blob: 7682dbacc136a5fe1af95ec259185b0b3bcf981a [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
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002275 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2276 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002277 if (!TextUtils.isEmpty(callingPackage)) {
2278 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2280 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002281 return "";
2282 }
2283 }
2284
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002285 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2286 // registered cell info, so return a NULL country instead.
2287 final long identity = Binder.clearCallingIdentity();
2288 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002289 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2290 // Get default phone in this case.
2291 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2292 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002293 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002294 // Todo: fix this when we can get the actual cellular network info when the device
2295 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002296 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002297 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2298 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002299 return "";
2300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002301 Phone phone = PhoneFactory.getPhone(phoneId);
2302 if (phone != null) {
2303 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002304 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305 if (sst != null) {
2306 LocaleTracker lt = sst.getLocaleTracker();
2307 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002308 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2309 return lt.getCurrentCountry();
2310 } else if (emergencyNumberTracker != null) {
2311 return emergencyNumberTracker.getEmergencyCountryIso();
2312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002313 }
2314 }
2315 }
2316 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002317 } finally {
2318 Binder.restoreCallingIdentity(identity);
2319 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002320 }
2321
2322 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002324 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002325 }
2326
Sanket Padawe356d7632015-06-22 14:03:32 -07002327 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002328 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 mApp.enforceCallingOrSelfPermission(
2330 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002331
2332 final long identity = Binder.clearCallingIdentity();
2333 try {
2334 final Phone phone = getPhone(subId);
2335 if (phone != null) {
2336 phone.enableLocationUpdates();
2337 }
2338 } finally {
2339 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 }
2342
2343 @Override
2344 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002345 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002346 }
2347
Sanket Padawe356d7632015-06-22 14:03:32 -07002348 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002349 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 mApp.enforceCallingOrSelfPermission(
2351 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002352
2353 final long identity = Binder.clearCallingIdentity();
2354 try {
2355 final Phone phone = getPhone(subId);
2356 if (phone != null) {
2357 phone.disableLocationUpdates();
2358 }
2359 } finally {
2360 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 }
2363
Nathan Harold31d7ff32018-10-15 20:20:30 -07002364 /**
2365 * Returns the target SDK version number for a given package name.
2366 *
Nathan Haroldec184742019-07-10 17:04:16 -07002367 * This call MUST be invoked before clearing the calling UID.
2368 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002369 * @return target SDK if the package is found or INT_MAX.
2370 */
2371 private int getTargetSdk(String packageName) {
2372 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002373 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002374 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002375 if (ai != null) return ai.targetSdkVersion;
2376 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002377 loge("Failed to get package info for pkg="
2378 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002379 }
2380 return Integer.MAX_VALUE;
2381 }
2382
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 @Override
2384 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002385 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2386 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002387 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002388 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2389 throw new SecurityException(
2390 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2391 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002392
Jordan Liu1617b712019-07-10 15:06:26 -07002393 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2395 return null;
2396 }
Svetoslav64fad262015-04-14 14:35:21 -07002397
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002398 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002400 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002401 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402
Nathan Haroldf180aac2018-06-01 18:43:55 -07002403 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2404 for (CellInfo ci : info) {
2405 if (ci instanceof CellInfoGsm) {
2406 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2407 } else if (ci instanceof CellInfoWcdma) {
2408 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002411 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 }
2413
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002414 private List<CellInfo> getCachedCellInfo() {
2415 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2416 for (Phone phone : PhoneFactory.getPhones()) {
2417 List<CellInfo> info = phone.getAllCellInfo();
2418 if (info != null) cellInfos.addAll(info);
2419 }
2420 return cellInfos;
2421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422
2423 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002424 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002425 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002426 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002427
2428 LocationAccessPolicy.LocationPermissionResult locationResult =
2429 LocationAccessPolicy.checkLocationPermission(mApp,
2430 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2431 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002432 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002433 .setCallingPid(Binder.getCallingPid())
2434 .setCallingUid(Binder.getCallingUid())
2435 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002436 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002437 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2438 .build());
2439 switch (locationResult) {
2440 case DENIED_HARD:
2441 throw new SecurityException("Not allowed to access cell info");
2442 case DENIED_SOFT:
2443 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 }
2445
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002446 final int targetSdk = getTargetSdk(callingPackage);
2447 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2448 return getCachedCellInfo();
2449 }
2450
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002451 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002452 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453 final long identity = Binder.clearCallingIdentity();
2454 try {
2455 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2456 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002457 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002458 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 if (info != null) cellInfos.addAll(info);
2460 }
2461 return cellInfos;
2462 } finally {
2463 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465 }
2466
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002467 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002468 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2469 String callingFeatureId) {
2470 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2471 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002472 }
2473
2474 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002475 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2476 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002477 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002478 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002479 }
2480
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002481 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2482 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002483 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002484 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002485
2486 LocationAccessPolicy.LocationPermissionResult locationResult =
2487 LocationAccessPolicy.checkLocationPermission(mApp,
2488 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2489 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002490 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002491 .setCallingPid(Binder.getCallingPid())
2492 .setCallingUid(Binder.getCallingUid())
2493 .setMethod("requestCellInfoUpdate")
2494 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2495 .build());
2496 switch (locationResult) {
2497 case DENIED_HARD:
2498 throw new SecurityException("Not allowed to access cell info");
2499 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002500 try {
2501 cb.onCellInfo(new ArrayList<CellInfo>());
2502 } catch (RemoteException re) {
2503 // Drop without consequences
2504 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002505 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002506 }
2507
Nathan Harolda939a962019-05-09 10:13:47 -07002508
2509 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002510 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2511
2512 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2513 }
2514
2515 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002517 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002518 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002522 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523 } finally {
2524 Binder.restoreCallingIdentity(identity);
2525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526 }
2527
Shishir Agrawala9f32182016-04-12 12:00:16 -07002528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002529 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002530 Phone phone = PhoneFactory.getPhone(slotIndex);
2531 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002532 return null;
2533 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002534 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002535 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002536 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002537 return null;
2538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002539
2540 final long identity = Binder.clearCallingIdentity();
2541 try {
2542 return phone.getImei();
2543 } finally {
2544 Binder.restoreCallingIdentity(identity);
2545 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002546 }
2547
2548 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002549 public String getTypeAllocationCodeForSlot(int slotIndex) {
2550 Phone phone = PhoneFactory.getPhone(slotIndex);
2551 String tac = null;
2552 if (phone != null) {
2553 String imei = phone.getImei();
2554 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2555 }
2556 return tac;
2557 }
2558
2559 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002560 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002561 Phone phone = PhoneFactory.getPhone(slotIndex);
2562 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002563 return null;
2564 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002565
Jeff Davidson913390f2018-02-23 17:11:49 -08002566 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002567 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002568 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002569 return null;
2570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571
2572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 return phone.getMeid();
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
2577 }
Jack Yu2af8d712017-03-15 17:14:14 -07002578 }
2579
2580 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002581 public String getManufacturerCodeForSlot(int slotIndex) {
2582 Phone phone = PhoneFactory.getPhone(slotIndex);
2583 String manufacturerCode = null;
2584 if (phone != null) {
2585 String meid = phone.getMeid();
2586 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2587 }
2588 return manufacturerCode;
2589 }
2590
2591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002592 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2593 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002594 Phone phone = PhoneFactory.getPhone(slotIndex);
2595 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002596 return null;
2597 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002598 int subId = phone.getSubId();
2599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002600 mApp, subId, callingPackage, callingFeatureId,
2601 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002602 return null;
2603 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604
2605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 return phone.getDeviceSvn();
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
2610 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002611 }
2612
fionaxu43304da2017-11-27 22:51:16 -08002613 @Override
2614 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 final Phone phone = getPhone(subId);
2618 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
2621 }
fionaxu43304da2017-11-27 22:51:16 -08002622 }
2623
2624 @Override
2625 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 final long identity = Binder.clearCallingIdentity();
2627 try {
2628 final Phone phone = getPhone(subId);
2629 return phone == null ? null : phone.getCarrierName();
2630 } finally {
2631 Binder.restoreCallingIdentity(identity);
2632 }
fionaxu43304da2017-11-27 22:51:16 -08002633 }
2634
calvinpanffe225e2018-11-01 19:43:06 +08002635 @Override
chen xu0026ca62019-03-06 15:28:50 -08002636 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 final Phone phone = getPhone(subId);
2640 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002641 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002642 } finally {
2643 Binder.restoreCallingIdentity(identity);
2644 }
2645 }
2646
2647 @Override
chen xu0026ca62019-03-06 15:28:50 -08002648 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002649 final long identity = Binder.clearCallingIdentity();
2650 try {
2651 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002652 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002653 } finally {
2654 Binder.restoreCallingIdentity(identity);
2655 }
2656 }
2657
chen xu651eec72018-11-11 19:03:44 -08002658 @Override
chen xu864e11c2018-12-06 22:10:03 -08002659 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2660 if (!isSubscriptionMccMnc) {
2661 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2662 }
chen xu651eec72018-11-11 19:03:44 -08002663 final Phone phone = PhoneFactory.getPhone(slotIndex);
2664 if (phone == null) {
2665 return TelephonyManager.UNKNOWN_CARRIER_ID;
2666 }
2667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
2672 }
2673 }
2674
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 //
2676 // Internal helper methods.
2677 //
2678
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002679 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2681 *
2682 * @throws SecurityException if the caller does not have the required permission
2683 */
2684 private void enforceModifyPermission() {
2685 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2686 }
2687
Shuo Qiancd19c462020-01-16 20:51:11 -08002688 /**
2689 * Make sure the caller is system.
2690 *
2691 * @throws SecurityException if the caller is not system.
2692 */
2693 private void enforceSystemCaller() {
2694 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2695 throw new SecurityException("Caller must be system");
2696 }
2697 }
2698
Shuo Qian3b6ee772019-11-13 17:43:31 -08002699 private void enforceActiveEmergencySessionPermission() {
2700 mApp.enforceCallingOrSelfPermission(
2701 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2702 }
2703
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 /**
2705 * Make sure the caller has the CALL_PHONE permission.
2706 *
2707 * @throws SecurityException if the caller does not have the required permission
2708 */
2709 private void enforceCallPermission() {
2710 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2711 }
2712
paulhu5a773602019-08-23 19:17:33 +08002713 private void enforceSettingsPermission() {
2714 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002715 }
2716
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 private String createTelUrl(String number) {
2718 if (TextUtils.isEmpty(number)) {
2719 return null;
2720 }
2721
Jake Hambye994d462014-02-03 13:10:13 -08002722 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 }
2724
Ihab Awadf9e92732013-12-05 18:02:52 -08002725 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2727 }
2728
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002729 private static void logv(String msg) {
2730 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2731 }
2732
Ihab Awadf9e92732013-12-05 18:02:52 -08002733 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2735 }
2736
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002737 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002739 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002740 }
2741
Sanket Padawe356d7632015-06-22 14:03:32 -07002742 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002743 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744 final long identity = Binder.clearCallingIdentity();
2745 try {
2746 final Phone phone = PhoneFactory.getPhone(slotIndex);
2747 if (phone == null) {
2748 return PhoneConstants.PHONE_TYPE_NONE;
2749 } else {
2750 return phone.getPhoneType();
2751 }
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002755 }
2756
2757 /**
2758 * Returns the CDMA ERI icon index to display
2759 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002761 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2762 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2763 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002764 }
2765
Sanket Padawe356d7632015-06-22 14:03:32 -07002766 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002767 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2768 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002770 mApp, subId, callingPackage, callingFeatureId,
2771 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002772 return -1;
2773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774
2775 final long identity = Binder.clearCallingIdentity();
2776 try {
2777 final Phone phone = getPhone(subId);
2778 if (phone != null) {
2779 return phone.getCdmaEriIconIndex();
2780 } else {
2781 return -1;
2782 }
2783 } finally {
2784 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002786 }
2787
2788 /**
2789 * Returns the CDMA ERI icon mode,
2790 * 0 - ON
2791 * 1 - FLASHING
2792 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002793 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002794 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2795 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2796 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002797 }
2798
Sanket Padawe356d7632015-06-22 14:03:32 -07002799 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002800 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2801 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002803 mApp, subId, callingPackage, callingFeatureId,
2804 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002805 return -1;
2806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807
2808 final long identity = Binder.clearCallingIdentity();
2809 try {
2810 final Phone phone = getPhone(subId);
2811 if (phone != null) {
2812 return phone.getCdmaEriIconMode();
2813 } else {
2814 return -1;
2815 }
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 }
2820
2821 /**
2822 * Returns the CDMA ERI text,
2823 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002824 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002825 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2826 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2827 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002828 }
2829
Sanket Padawe356d7632015-06-22 14:03:32 -07002830 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002831 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2832 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002834 mApp, subId, callingPackage, callingFeatureId,
2835 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002836 return null;
2837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838
2839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 final Phone phone = getPhone(subId);
2842 if (phone != null) {
2843 return phone.getCdmaEriText();
2844 } else {
2845 return null;
2846 }
2847 } finally {
2848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 }
2851
2852 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002853 * Returns the CDMA MDN.
2854 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002855 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002856 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2858 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859
2860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002863 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 return phone.getLine1Number();
2865 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002866 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 return null;
2868 }
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002871 }
2872 }
2873
2874 /**
2875 * Returns the CDMA MIN.
2876 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002877 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002878 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2880 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881
2882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 final Phone phone = getPhone(subId);
2885 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2886 return phone.getCdmaMin();
2887 } else {
2888 return null;
2889 }
2890 } finally {
2891 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002892 }
2893 }
2894
Hall Liud892bec2018-11-30 14:51:45 -08002895 @Override
2896 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2897 INumberVerificationCallback callback, String callingPackage) {
2898 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2899 != PERMISSION_GRANTED) {
2900 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2901 }
2902 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2903
2904 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2905 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2906 throw new SecurityException("Calling package must be configured in the device config");
2907 }
2908
2909 if (range == null) {
2910 throw new NullPointerException("Range must be non-null");
2911 }
2912
2913 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002914 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002915
2916 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2917 }
2918
Junda Liuca05d5d2014-08-14 22:36:34 -07002919 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 * Returns true if CDMA provisioning needs to run.
2921 */
2922 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923 final long identity = Binder.clearCallingIdentity();
2924 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002925 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926 } finally {
2927 Binder.restoreCallingIdentity(identity);
2928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
2930
2931 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002932 * Sets the voice mail number of a given subId.
2933 */
2934 @Override
2935 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002936 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2937 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938
2939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2942 new Pair<String, String>(alphaTag, number), new Integer(subId));
2943 return success;
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
2946 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002947 }
2948
Ta-wei Yen87c49842016-05-13 21:19:52 -07002949 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002950 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2951 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002952 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2953 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002954 if (!TextUtils.equals(callingPackage, systemDialer)) {
2955 throw new SecurityException("caller must be system dialer");
2956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957
2958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2961 if (phoneAccountHandle == null) {
2962 return null;
2963 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002964 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965 } finally {
2966 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002967 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002968 }
2969
2970 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002971 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2972 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002973 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002974 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002975 mApp, subId, callingPackage, callingFeatureId,
2976 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002977 return null;
2978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002980 final long identity = Binder.clearCallingIdentity();
2981 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002982 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002986 }
2987
2988 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002989 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2990 VisualVoicemailSmsFilterSettings settings) {
2991 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992
2993 final long identity = Binder.clearCallingIdentity();
2994 try {
2995 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002996 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 } finally {
2998 Binder.restoreCallingIdentity(identity);
2999 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003000 }
3001
3002 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003003 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3004 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005
3006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003009 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003010 } finally {
3011 Binder.restoreCallingIdentity(identity);
3012 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003013 }
3014
3015 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003016 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3017 String callingPackage, int subId) {
3018 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019
3020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003023 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003027 }
3028
3029 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003030 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003032
3033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003036 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003040 }
3041
3042 @Override
3043 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3044 String number, int port, String text, PendingIntent sentIntent) {
3045 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003046 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003047 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003048 SmsController smsController = PhoneFactory.getSmsController();
3049 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3050 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003051 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003052
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003053 /**
fionaxu0152e512016-11-14 13:36:14 -08003054 * Sets the voice activation state of a given subId.
3055 */
3056 @Override
3057 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3059 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 final Phone phone = getPhone(subId);
3064 if (phone != null) {
3065 phone.setVoiceActivationState(activationState);
3066 } else {
3067 loge("setVoiceActivationState fails with invalid subId: " + subId);
3068 }
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003071 }
3072 }
3073
3074 /**
3075 * Sets the data activation state of a given subId.
3076 */
3077 @Override
3078 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3080 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081
3082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 final Phone phone = getPhone(subId);
3085 if (phone != null) {
3086 phone.setDataActivationState(activationState);
3087 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003088 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089 }
3090 } finally {
3091 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003092 }
3093 }
3094
3095 /**
3096 * Returns the voice activation state of a given subId.
3097 */
3098 @Override
3099 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003100 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101
fionaxu0152e512016-11-14 13:36:14 -08003102 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 if (phone != null) {
3106 return phone.getVoiceActivationState();
3107 } else {
3108 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3109 }
3110 } finally {
3111 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003112 }
3113 }
3114
3115 /**
3116 * Returns the data activation state of a given subId.
3117 */
3118 @Override
3119 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003120 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003121
fionaxu0152e512016-11-14 13:36:14 -08003122 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 if (phone != null) {
3126 return phone.getDataActivationState();
3127 } else {
3128 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3129 }
3130 } finally {
3131 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003132 }
3133 }
3134
3135 /**
Wink Saville36469e72014-06-11 15:17:00 -07003136 * Returns the unread count of voicemails for a subId
3137 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003138 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003139 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3140 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003142 mApp, subId, callingPackage, callingFeatureId,
3143 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003144 return 0;
3145 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 final Phone phone = getPhone(subId);
3149 if (phone != null) {
3150 return phone.getVoiceMessageCount();
3151 } else {
3152 return 0;
3153 }
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 }
3158
3159 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003160 * returns true, if the device is in a state where both voice and data
3161 * are supported simultaneously. This can change based on location or network condition.
3162 */
3163 @Override
3164 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 final Phone phone = getPhone(subId);
3168 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003172 }
3173
3174 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003175 * Send the dialer code if called from the current default dialer or the caller has
3176 * carrier privilege.
3177 * @param inputCode The dialer code to send
3178 */
3179 @Override
3180 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003181 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003182 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003183 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3184 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003185 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003186 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003187 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003188 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189
3190 final long identity = Binder.clearCallingIdentity();
3191 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003192 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
fionaxu235cc5e2017-03-06 22:25:57 -08003196 }
3197
Pengquan Menga1bb6272018-09-06 09:59:22 -07003198 @Override
3199 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003200 TelephonyPermissions
3201 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3202 mApp, subId, "getNetworkSelectionMode");
3203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 if (!isActiveSubscription(subId)) {
3206 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3207 }
3208 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003211 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003212 }
3213
Brad Ebinger35c841c2018-10-01 10:40:55 -07003214 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003215 public boolean isInEmergencySmsMode() {
3216 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3217 final long identity = Binder.clearCallingIdentity();
3218 try {
3219 for (Phone phone : PhoneFactory.getPhones()) {
3220 if (phone.isInEmergencySmsMode()) {
3221 return true;
3222 }
3223 }
3224 } finally {
3225 Binder.restoreCallingIdentity(identity);
3226 }
3227 return false;
3228 }
3229
shilu366312e2019-12-17 09:28:10 -08003230 /**
3231 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3232 * @param subId The subscription to use to check the configuration.
3233 * @param c The callback that will be used to send the result.
3234 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003235 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003236 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3237 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003238 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3239 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003240
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003241 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3242 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3243 "IMS not available on device.");
3244 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003245 final long token = Binder.clearCallingIdentity();
3246 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003247 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003248 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003249 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003250 } catch (ImsException e) {
3251 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003252 } finally {
3253 Binder.restoreCallingIdentity(token);
3254 }
3255 }
3256
shilu366312e2019-12-17 09:28:10 -08003257 /**
3258 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3259 * @param subId The subscription to use to check the configuration.
3260 * @param c The callback that will be used to send the result.
3261 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003262 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003263 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003264 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3265 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003266 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3267 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3268 }
Meng Wangafbc5852019-09-19 17:37:13 -07003269 final long token = Binder.clearCallingIdentity();
3270 try {
3271 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3272 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3273 .removeRegistrationCallbackForSubscription(c, subId);
3274 } catch (ImsException e) {
3275 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3276 + "is inactive, ignoring unregister.");
3277 // If the subscription is no longer active, just return, since the callback
3278 // will already have been removed internally.
3279 } finally {
3280 Binder.restoreCallingIdentity(token);
3281 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003282 }
3283
Brad Ebingera34a6c22019-10-22 17:36:18 -07003284 /**
3285 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3286 */
3287 @Override
3288 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3289 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3290 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3291 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3292 "IMS not available on device.");
3293 }
3294 final long token = Binder.clearCallingIdentity();
3295 try {
3296 Phone phone = getPhone(subId);
3297 if (phone == null) {
3298 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3299 + subId + "'");
3300 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3301 }
3302 phone.getImsRegistrationState(regState -> {
3303 try {
3304 consumer.accept((regState == null)
3305 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3306 } catch (RemoteException e) {
3307 // Ignore if the remote process is no longer available to call back.
3308 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3309 }
3310 });
3311 } finally {
3312 Binder.restoreCallingIdentity(token);
3313 }
3314 }
3315
3316 /**
3317 * Get the transport type for the IMS service registration state.
3318 */
3319 @Override
3320 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003321 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3322 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003323 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3324 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3325 "IMS not available on device.");
3326 }
3327 final long token = Binder.clearCallingIdentity();
3328 try {
3329 Phone phone = getPhone(subId);
3330 if (phone == null) {
3331 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3332 + subId + "'");
3333 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3334 }
3335 phone.getImsRegistrationTech(regTech -> {
3336 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3337 int regTechConverted = (regTech == null)
3338 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3339 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3340 regTechConverted);
3341 try {
3342 consumer.accept(regTechConverted);
3343 } catch (RemoteException e) {
3344 // Ignore if the remote process is no longer available to call back.
3345 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3346 }
3347 });
3348 } finally {
3349 Binder.restoreCallingIdentity(token);
3350 }
3351 }
3352
shilu366312e2019-12-17 09:28:10 -08003353 /**
3354 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3355 * @param subId The subscription to use to check the configuration.
3356 * @param c The callback that will be used to send the result.
3357 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003358 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003359 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3360 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003361 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3362 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003363 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3364 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3365 "IMS not available on device.");
3366 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003367 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3368 final long token = Binder.clearCallingIdentity();
3369 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003370 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003371 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003372 } catch (ImsException e) {
3373 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003374 } finally {
3375 Binder.restoreCallingIdentity(token);
3376 }
3377 }
3378
shilu366312e2019-12-17 09:28:10 -08003379 /**
3380 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3381 * @param subId The subscription to use to check the configuration.
3382 * @param c The callback that will be used to send the result.
3383 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003384 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003385 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003386 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3387 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003388 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3389 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3390 }
Meng Wangafbc5852019-09-19 17:37:13 -07003391
3392 final long token = Binder.clearCallingIdentity();
3393 try {
3394 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3395 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003396 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003397 } catch (ImsException e) {
3398 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3399 + "is inactive, ignoring unregister.");
3400 // If the subscription is no longer active, just return, since the callback
3401 // will already have been removed internally.
3402 } finally {
3403 Binder.restoreCallingIdentity(token);
3404 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003405 }
3406
3407 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003408 public boolean isCapable(int subId, int capability, int regTech) {
3409 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003410 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3411 final long token = Binder.clearCallingIdentity();
3412 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003413 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003414 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003415 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003416 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3417 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003418 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003419 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3420 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003421 } finally {
3422 Binder.restoreCallingIdentity(token);
3423 }
3424 }
3425
3426 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003427 public boolean isAvailable(int subId, int capability, int regTech) {
3428 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003429 final long token = Binder.clearCallingIdentity();
3430 try {
3431 Phone phone = getPhone(subId);
3432 if (phone == null) return false;
3433 return phone.isImsCapabilityAvailable(capability, regTech);
3434 } finally {
3435 Binder.restoreCallingIdentity(token);
3436 }
3437 }
3438
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003439 /**
3440 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3441 * subscription.
3442 * @param subId The subscription to use to check the configuration.
3443 * @param callback The callback that will be used to send the result.
3444 * @param capability The MmTelFeature capability that will be used to send the result.
3445 * @param transportType The transport type of the MmTelFeature capability.
3446 */
3447 @Override
3448 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3449 int transportType) {
3450 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3451 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3452 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3453 "IMS not available on device.");
3454 }
3455 final long token = Binder.clearCallingIdentity();
3456 try {
3457 int slotId = getSlotIndex(subId);
3458 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3459 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3460 + subId + "'");
3461 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3462 }
3463 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3464 transportType, aBoolean -> {
3465 try {
3466 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3467 } catch (RemoteException e) {
3468 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3469 + "running. Ignore");
3470 }
3471 });
3472 } finally {
3473 Binder.restoreCallingIdentity(token);
3474 }
3475 }
3476
shilu366312e2019-12-17 09:28:10 -08003477 /**
3478 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3479 * @param subId The subscription to use to check the configuration.
3480 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003481 @Override
3482 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003483 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3484 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003485
Brad Ebinger35c841c2018-10-01 10:40:55 -07003486 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3487 final long token = Binder.clearCallingIdentity();
3488 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003489 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003490 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003491 } catch (ImsException e) {
3492 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003493 } finally {
3494 Binder.restoreCallingIdentity(token);
3495 }
3496 }
3497
3498 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003499 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003501 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003505 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003506 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003507 } catch (ImsException e) {
3508 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003509 } finally {
3510 Binder.restoreCallingIdentity(identity);
3511 }
3512 }
3513
shilu366312e2019-12-17 09:28:10 -08003514 /**
3515 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3516 * @param subId The subscription to use to check the configuration.
3517 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003518 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003519 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003520 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3521 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003522 final long identity = Binder.clearCallingIdentity();
3523 try {
3524 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003525 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3526 } catch (ImsException e) {
3527 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003528 } finally {
3529 Binder.restoreCallingIdentity(identity);
3530 }
3531 }
3532
3533 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003534 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003536 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003540 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003541 } catch (ImsException e) {
3542 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003543 } finally {
3544 Binder.restoreCallingIdentity(identity);
3545 }
3546 }
3547
shilu366312e2019-12-17 09:28:10 -08003548 /**
3549 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3550 * @param subId The subscription to use to check the configuration.
3551 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003552 @Override
3553 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003554 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3555 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003556 final long identity = Binder.clearCallingIdentity();
3557 try {
3558 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003559 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003560 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003561 } catch (ImsException e) {
3562 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003563 } finally {
3564 Binder.restoreCallingIdentity(identity);
3565 }
3566 }
3567
3568 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003569 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003571 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003575 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003576 } catch (ImsException e) {
3577 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003578 } finally {
3579 Binder.restoreCallingIdentity(identity);
3580 }
3581 }
3582
shilu366312e2019-12-17 09:28:10 -08003583 /**
3584 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3585 * @param subId The subscription to use to check the configuration.
3586 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003587 @Override
3588 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003589 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3590 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003591 final long identity = Binder.clearCallingIdentity();
3592 try {
3593 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003594 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003595 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003596 } catch (ImsException e) {
3597 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003598 } finally {
3599 Binder.restoreCallingIdentity(identity);
3600 }
3601 }
3602
3603 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003604 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003606 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003607 final long identity = Binder.clearCallingIdentity();
3608 try {
3609 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003610 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003611 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003612 } catch (ImsException e) {
3613 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003614 } finally {
3615 Binder.restoreCallingIdentity(identity);
3616 }
3617 }
3618
3619 @Override
3620 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3622 "setVoWiFiNonPersistent");
3623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003626 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003627 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003628 } catch (ImsException e) {
3629 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003630 } finally {
3631 Binder.restoreCallingIdentity(identity);
3632 }
3633 }
3634
shilu366312e2019-12-17 09:28:10 -08003635 /**
3636 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3637 * @param subId The subscription to use to check the configuration.
3638 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003639 @Override
3640 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003641 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3642 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003643 final long identity = Binder.clearCallingIdentity();
3644 try {
3645 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003646 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003647 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003648 } catch (ImsException e) {
3649 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
3653 }
3654
3655 @Override
3656 public void setVoWiFiModeSetting(int subId, int mode) {
3657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3658 "setVoWiFiModeSetting");
3659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003662 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003663 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003664 } catch (ImsException e) {
3665 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003666 } finally {
3667 Binder.restoreCallingIdentity(identity);
3668 }
3669 }
3670
3671 @Override
3672 public int getVoWiFiRoamingModeSetting(int subId) {
3673 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003677 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003678 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003679 } catch (ImsException e) {
3680 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003681 } finally {
3682 Binder.restoreCallingIdentity(identity);
3683 }
3684 }
3685
3686 @Override
3687 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3689 "setVoWiFiRoamingModeSetting");
3690 final long identity = Binder.clearCallingIdentity();
3691 try {
3692 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003693 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003694 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003695 } catch (ImsException e) {
3696 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003697 } finally {
3698 Binder.restoreCallingIdentity(identity);
3699 }
3700 }
3701
3702 @Override
3703 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3705 "setRttCapabilityEnabled");
3706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003709 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3710 } catch (ImsException e) {
3711 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
3715 }
3716
shilu366312e2019-12-17 09:28:10 -08003717 /**
3718 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3719 * @param subId The subscription to use to check the configuration.
3720 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003721 @Override
3722 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003723 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3724 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003728 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003729 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003730 } catch (ImsException e) {
3731 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003732 } finally {
3733 Binder.restoreCallingIdentity(identity);
3734 }
3735 }
3736
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003737 @Override
3738 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3739 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3740 final long identity = Binder.clearCallingIdentity();
3741 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003742 if (!isImsAvailableOnDevice()) {
3743 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3744 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003745 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003746 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003747 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003748 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003749 } catch (ImsException e) {
3750 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003751 } finally {
3752 Binder.restoreCallingIdentity(identity);
3753 }
3754 }
3755
3756 @Override
3757 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3758 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3759 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003760 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3761 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3762 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003763 try {
3764 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003765 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003766 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003767 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003768 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3769 + "is inactive, ignoring unregister.");
3770 // If the subscription is no longer active, just return, since the callback will already
3771 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003772 } finally {
3773 Binder.restoreCallingIdentity(identity);
3774 }
3775 }
3776
allenwtsu99c623b2020-01-03 18:24:23 +08003777
3778 private void checkModifyPhoneStatePermission(int subId, String message) {
3779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3780 message);
3781 }
3782
3783 private boolean isImsProvisioningRequired(int subId, int capability,
3784 boolean isMmtelCapability) {
3785 Phone phone = getPhone(subId);
3786 if (phone == null) {
3787 loge("phone instance null for subid " + subId);
3788 return false;
3789 }
3790 if (isMmtelCapability) {
3791 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3792 return false;
3793 }
3794 } else {
3795 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3796 return false;
3797 }
3798 }
3799 return true;
3800 }
3801
3802 @Override
3803 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3804 boolean isProvisioned) {
3805 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3806
3807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3810 if (!isImsProvisioningRequired(subId, capability, false)) {
3811 return;
3812 }
3813
3814 // this capability requires provisioning, route to the correct API.
3815 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3816 switch (capability) {
3817 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3818 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3819 ims.setEabProvisioned(isProvisioned);
3820 break;
3821 default: {
3822 throw new IllegalArgumentException("Tried to set provisioning for "
3823 + "rcs capability '" + capability + "', which does not require "
3824 + "provisioning.");
3825 }
3826 }
3827 } finally {
3828 Binder.restoreCallingIdentity(identity);
3829 }
3830
3831 }
3832
3833
3834 @Override
3835 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3836 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3837 final long identity = Binder.clearCallingIdentity();
3838 try {
3839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3840 if (!isImsProvisioningRequired(subId, capability, false)) {
3841 return true;
3842 }
3843
3844 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3845 switch (capability) {
3846 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3847 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3848 return ims.isEabProvisionedOnDevice();
3849
3850 default: {
3851 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3852 + "capability '" + capability + "', which does not require "
3853 + "provisioning.");
3854 }
3855 }
3856
3857 } finally {
3858 Binder.restoreCallingIdentity(identity);
3859 }
3860 }
3861
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003862 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003863 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3864 boolean isProvisioned) {
3865 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3866 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3867 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3868 }
allenwtsu99c623b2020-01-03 18:24:23 +08003869 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003870 final long identity = Binder.clearCallingIdentity();
3871 try {
3872 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003873 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003874 return;
3875 }
3876
3877 // this capability requires provisioning, route to the correct API.
3878 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3879 switch (capability) {
3880 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3881 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3882 ims.setVolteProvisioned(isProvisioned);
3883 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3884 ims.setWfcProvisioned(isProvisioned);
3885 }
3886 break;
3887 }
3888 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3889 // There is currently no difference in VT provisioning type.
3890 ims.setVtProvisioned(isProvisioned);
3891 break;
3892 }
3893 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3894 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3895 // change the capability of the feature instead if needed.
3896 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3897 == isProvisioned) {
3898 // No change in provisioning.
3899 return;
3900 }
3901 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3902 try {
3903 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003904 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003905 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3906 + ", Exception" + e.getMessage());
3907 }
3908 break;
3909 }
3910 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003911 throw new IllegalArgumentException("Tried to set provisioning for "
3912 + "MmTel capability '" + capability + "', which does not require "
3913 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003914 }
3915 }
3916
3917 } finally {
3918 Binder.restoreCallingIdentity(identity);
3919 }
3920 }
3921
3922 @Override
3923 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3924 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3925 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3926 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3927 }
3928 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3929 final long identity = Binder.clearCallingIdentity();
3930 try {
3931 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003932 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003933 return true;
3934 }
3935
3936 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3937 switch (capability) {
3938 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3939 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3940 return ims.isVolteProvisionedOnDevice();
3941 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3942 return ims.isWfcProvisionedOnDevice();
3943 }
3944 // This should never happen, since we are checking tech above to make sure it
3945 // is either LTE or IWLAN.
3946 throw new IllegalArgumentException("Invalid radio technology for voice "
3947 + "capability.");
3948 }
3949 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3950 // There is currently no difference in VT provisioning type.
3951 return ims.isVtProvisionedOnDevice();
3952 }
3953 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3954 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3955 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3956 }
3957 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003958 throw new IllegalArgumentException(
3959 "Tried to get provisioning for MmTel capability '" + capability
3960 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003961 }
3962 }
3963
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
3966 }
3967 }
3968
3969 @Override
3970 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3971 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3972 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3973 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3974 }
3975 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3976 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3977 return (provisionedBits & capability) > 0;
3978 }
3979
3980 @Override
3981 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3982 boolean isProvisioned) {
3983 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3984 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3985 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3986 }
3987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3988 "setProvisioningStatusForCapability");
3989 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3990 // If the current provisioning status for capability already matches isProvisioned,
3991 // do nothing.
3992 if (((provisionedBits & capability) > 0) == isProvisioned) {
3993 return;
3994 }
3995 if (isProvisioned) {
3996 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3997 } else {
3998 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3999 }
4000 }
4001
4002 /**
4003 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4004 * technology. The bitfield should mirror the bitfield defined by
4005 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4006 */
4007 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4008 String key = getMmTelProvisioningKey(subId, tech);
4009 // Default is no capabilities are provisioned.
4010 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4011 }
4012
4013 /**
4014 * Sets the MmTel capability provisioning bitfield (defined by
4015 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4016 * technology specified.
4017 *
4018 * Note: This is a synchronous command and should not be called on UI thread.
4019 */
4020 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4021 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4022 String key = getMmTelProvisioningKey(subId, tech);
4023 editor.putInt(key, newField);
4024 editor.commit();
4025 }
4026
4027 private static String getMmTelProvisioningKey(int subId, int tech) {
4028 // resulting key is provision_ims_mmtel_{subId}_{tech}
4029 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4030 }
4031
4032 /**
4033 * Query CarrierConfig to see if the specified capability requires provisioning for the
4034 * carrier associated with the subscription id.
4035 */
4036 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4037 int capability) {
4038 CarrierConfigManager configManager = new CarrierConfigManager(context);
4039 PersistableBundle c = configManager.getConfigForSubId(subId);
4040 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004041 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004042 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4043 false);
4044 boolean requireVoiceVtProvisioning = c.getBoolean(
4045 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4046
4047 // First check to make sure that the capability requires provisioning.
4048 switch (capability) {
4049 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4050 // intentional fallthrough
4051 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4052 if (requireVoiceVtProvisioning) {
4053 // Voice and Video requires provisioning
4054 return true;
4055 }
4056 break;
4057 }
4058 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4059 if (requireUtProvisioning) {
4060 // UT requires provisioning
4061 return true;
4062 }
4063 break;
4064 }
4065 }
4066 return false;
4067 }
4068
allenwtsu99c623b2020-01-03 18:24:23 +08004069 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4070 int capability) {
4071 CarrierConfigManager configManager = new CarrierConfigManager(context);
4072 PersistableBundle c = configManager.getConfigForSubId(subId);
4073
4074 boolean requireRcsProvisioning = c.getBoolean(
4075 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4076
4077 // First check to make sure that the capability requires provisioning.
4078 switch (capability) {
4079 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4080 // intentional fallthrough
4081 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4082 if (requireRcsProvisioning) {
4083 // OPTION or PRESENCE requires provisioning
4084 return true;
4085 }
4086 break;
4087 }
4088 }
4089 return false;
4090 }
4091
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004092 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004093 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004094 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4095 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4096 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004097 enforceReadPrivilegedPermission("getImsProvisioningInt");
4098 final long identity = Binder.clearCallingIdentity();
4099 try {
4100 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004101 int slotId = getSlotIndex(subId);
4102 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4103 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4104 + subId + "' for key:" + key);
4105 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4106 }
4107 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004108 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004109 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4110 + subId + "' for key:" + key);
4111 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004112 } finally {
4113 Binder.restoreCallingIdentity(identity);
4114 }
4115 }
4116
4117 @Override
4118 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004119 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4120 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4121 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004122 enforceReadPrivilegedPermission("getImsProvisioningString");
4123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004126 int slotId = getSlotIndex(subId);
4127 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4128 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4129 + subId + "' for key:" + key);
4130 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4131 }
4132 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004133 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004134 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4135 + subId + "' for key:" + key);
4136 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004137 } finally {
4138 Binder.restoreCallingIdentity(identity);
4139 }
4140 }
4141
4142 @Override
4143 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004144 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4145 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4146 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4148 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004152 int slotId = getSlotIndex(subId);
4153 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4154 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4155 + subId + "' for key:" + key);
4156 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4157 }
4158 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004159 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004160 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4161 + "' for key:" + key);
4162 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004163 } finally {
4164 Binder.restoreCallingIdentity(identity);
4165 }
4166 }
4167
4168 @Override
4169 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004170 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4171 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4172 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4174 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004175 final long identity = Binder.clearCallingIdentity();
4176 try {
4177 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004178 int slotId = getSlotIndex(subId);
4179 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4180 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4181 + subId + "' for key:" + key);
4182 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4183 }
4184 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004185 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004186 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4187 + "' for key:" + key);
4188 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004189 } finally {
4190 Binder.restoreCallingIdentity(identity);
4191 }
4192 }
4193
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004194 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 int slotId = SubscriptionManager.getSlotIndex(subId);
4196 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004197 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4198 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004199 }
4200 return slotId;
4201 }
4202
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004203 private int getSlotIndex(int subId) {
4204 int slotId = SubscriptionManager.getSlotIndex(subId);
4205 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4206 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4207 }
4208 return slotId;
4209 }
4210
Wink Saville36469e72014-06-11 15:17:00 -07004211 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004212 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004213 */
4214 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004215 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4216 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004217 final int targetSdk = getTargetSdk(callingPackage);
4218 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004219 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004220 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004221 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004222 mApp, subId, callingPackage, callingFeatureId,
4223 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004224 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4225 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004227 final long identity = Binder.clearCallingIdentity();
4228 try {
4229 final Phone phone = getPhone(subId);
4230 if (phone != null) {
4231 return phone.getServiceState().getDataNetworkType();
4232 } else {
4233 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4234 }
4235 } finally {
4236 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004238 }
4239
4240 /**
4241 * Returns the data network type
4242 */
4243 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004244 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4245 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4246 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004247 }
4248
4249 /**
4250 * Returns the data network type for a subId
4251 */
4252 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004253 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4254 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004256 mApp, subId, callingPackage, callingFeatureId,
4257 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004258 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4259 }
4260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261 final long identity = Binder.clearCallingIdentity();
4262 try {
4263 final Phone phone = getPhone(subId);
4264 if (phone != null) {
4265 return phone.getServiceState().getDataNetworkType();
4266 } else {
4267 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4268 }
4269 } finally {
4270 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004272 }
4273
4274 /**
Wink Saville36469e72014-06-11 15:17:00 -07004275 * Returns the Voice network type for a subId
4276 */
4277 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004278 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4279 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004281 mApp, subId, callingPackage, callingFeatureId,
4282 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004283 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4284 }
4285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286 final long identity = Binder.clearCallingIdentity();
4287 try {
4288 final Phone phone = getPhone(subId);
4289 if (phone != null) {
4290 return phone.getServiceState().getVoiceNetworkType();
4291 } else {
4292 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4293 }
4294 } finally {
4295 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004297 }
4298
4299 /**
4300 * @return true if a ICC card is present
4301 */
4302 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004303 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004304 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4305 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004306 }
4307
4308 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004309 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004310 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004311 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004312 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004313 final long identity = Binder.clearCallingIdentity();
4314 try {
4315 final Phone phone = PhoneFactory.getPhone(slotIndex);
4316 if (phone != null) {
4317 return phone.getIccCard().hasIccCard();
4318 } else {
4319 return false;
4320 }
4321 } finally {
4322 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004324 }
4325
4326 /**
4327 * Return if the current radio is LTE on CDMA. This
4328 * is a tri-state return value as for a period of time
4329 * the mode may be unknown.
4330 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004331 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004332 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004333 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004334 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004335 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004336 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4337 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4338 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004339 }
4340
Sanket Padawe356d7632015-06-22 14:03:32 -07004341 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004342 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4343 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004344 try {
4345 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4346 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004347 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4348 }
4349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350 final long identity = Binder.clearCallingIdentity();
4351 try {
4352 final Phone phone = getPhone(subId);
4353 if (phone == null) {
4354 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4355 } else {
4356 return phone.getLteOnCdmaMode();
4357 }
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004360 }
Wink Saville36469e72014-06-11 15:17:00 -07004361 }
4362
Wink Saville36469e72014-06-11 15:17:00 -07004363 /**
4364 * {@hide}
4365 * Returns Default subId, 0 in the case of single standby.
4366 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004367 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004368 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004369 }
4370
Shishir Agrawala9f32182016-04-12 12:00:16 -07004371 private int getSlotForDefaultSubscription() {
4372 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4373 }
4374
Wink Savilleb564aae2014-10-23 10:18:09 -07004375 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004376 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004377 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004378
Pengquan Menge92a50d2018-09-21 15:54:48 -07004379 private boolean isActiveSubscription(int subId) {
4380 return mSubscriptionController.isActiveSubId(subId);
4381 }
4382
Ihab Awadf2177b72013-11-25 13:33:23 -08004383 /**
4384 * @see android.telephony.TelephonyManager.WifiCallingChoices
4385 */
4386 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387 final long identity = Binder.clearCallingIdentity();
4388 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004389 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004390 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4391 getWhenToMakeWifiCallsDefaultPreference());
4392 } finally {
4393 Binder.restoreCallingIdentity(identity);
4394 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004395 }
4396
4397 /**
4398 * @see android.telephony.TelephonyManager.WifiCallingChoices
4399 */
4400 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 final long identity = Binder.clearCallingIdentity();
4402 try {
4403 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004404 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004409 }
4410
Sailesh Nepald1e68152013-12-12 19:08:02 -08004411 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004412 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004413 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004414 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004415
Jordan Liu4c733742019-02-28 12:03:40 -08004416 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4417 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4418 if (phoneId == -1) {
4419 throw new IllegalArgumentException("Given slot index: " + slotIndex
4420 + " does not correspond to an active phone");
4421 }
4422 return PhoneFactory.getPhone(phoneId);
4423 }
4424
Shishir Agrawal566b7612013-10-28 14:41:00 -07004425 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004426 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4427 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4429 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004430 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004431 if (DBG) {
4432 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4433 }
4434 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4435 p2);
4436 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004437
Jordan Liu4c733742019-02-28 12:03:40 -08004438
4439 @Override
4440 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4441 int slotIndex, String callingPackage, String aid, int p2) {
4442 enforceModifyPermission();
4443 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4444 if (DBG) {
4445 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4446 }
4447 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4448 callingPackage, aid, p2);
4449 }
4450
4451 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4452 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004453 final long identity = Binder.clearCallingIdentity();
4454 try {
4455 if (TextUtils.equals(ISDR_AID, aid)) {
4456 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004457 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4458 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004459 if (bestComponent == null
4460 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4461 loge("The calling package is not allowed to access ISD-R.");
4462 throw new SecurityException(
4463 "The calling package is not allowed to access ISD-R.");
4464 }
Derek Tan740e1672017-06-27 14:56:27 -07004465 }
Derek Tan740e1672017-06-27 14:56:27 -07004466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004467 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004468 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4469 null /* workSource */);
4470 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004471 return response;
4472 } finally {
4473 Binder.restoreCallingIdentity(identity);
4474 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004475 }
4476
4477 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004478 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004479 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4480 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004481 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4482 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4483 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004484
Jordan Liu4c733742019-02-28 12:03:40 -08004485 @Override
4486 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4487 enforceModifyPermission();
4488 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4489 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4490 channel);
4491 }
4492
4493 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004494 final long identity = Binder.clearCallingIdentity();
4495 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496 if (channel < 0) {
4497 return false;
4498 }
Jordan Liu4c733742019-02-28 12:03:40 -08004499 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4500 null /* workSource */);
4501 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004502 return success;
4503 } finally {
4504 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004505 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004506 }
4507
4508 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004509 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004510 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4512 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004513 if (DBG) {
4514 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4515 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4516 + p3 + " data=" + data);
4517 }
4518 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4519 command, p1, p2, p3, data);
4520 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004521
Jordan Liu4c733742019-02-28 12:03:40 -08004522 @Override
4523 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4524 int command, int p1, int p2, int p3, String data) {
4525 enforceModifyPermission();
4526 if (DBG) {
4527 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4528 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4529 + p3 + " data=" + data);
4530 }
4531 return iccTransmitApduLogicalChannelWithPermission(
4532 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4533 data);
4534 }
4535
4536 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4537 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004538 final long identity = Binder.clearCallingIdentity();
4539 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004540 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004541 return "";
4542 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004544 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004545 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4546 null /* workSource */);
4547 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004549 // Append the returned status code to the end of the response payload.
4550 String s = Integer.toHexString(
4551 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4552 if (response.payload != null) {
4553 s = IccUtils.bytesToHexString(response.payload) + s;
4554 }
4555 return s;
4556 } finally {
4557 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004558 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004559 }
Jake Hambye994d462014-02-03 13:10:13 -08004560
Evan Charltonc66da362014-05-16 14:06:40 -07004561 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004562 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4563 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4565 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004566 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004567 if (DBG) {
4568 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4569 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4570 }
4571 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4572 cla, command, p1, p2, p3, data);
4573 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004574
Jordan Liu4c733742019-02-28 12:03:40 -08004575 @Override
4576 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4577 int command, int p1, int p2, int p3, String data) {
4578 enforceModifyPermission();
4579 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4580 if (DBG) {
4581 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4582 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4583 + " data=" + data);
4584 }
4585
4586 return iccTransmitApduBasicChannelWithPermission(
4587 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4588 p2, p3, data);
4589 }
4590
4591 // open APDU basic channel assuming the caller has sufficient permissions
4592 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4593 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004594 final long identity = Binder.clearCallingIdentity();
4595 try {
4596 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4597 && TextUtils.equals(ISDR_AID, data)) {
4598 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004599 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4600 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601 if (bestComponent == null
4602 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4603 loge("The calling package is not allowed to select ISD-R.");
4604 throw new SecurityException(
4605 "The calling package is not allowed to select ISD-R.");
4606 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004607 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004609 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004610 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4611 null /* workSource */);
4612 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004614 // Append the returned status code to the end of the response payload.
4615 String s = Integer.toHexString(
4616 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4617 if (response.payload != null) {
4618 s = IccUtils.bytesToHexString(response.payload) + s;
4619 }
4620 return s;
4621 } finally {
4622 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004623 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004624 }
4625
4626 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004627 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004628 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4630 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004631
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632 final long identity = Binder.clearCallingIdentity();
4633 try {
4634 if (DBG) {
4635 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4636 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4637 }
4638
4639 IccIoResult response =
4640 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4641 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4642 subId);
4643
4644 if (DBG) {
4645 log("Exchange SIM_IO [R]" + response);
4646 }
4647
4648 byte[] result = null;
4649 int length = 2;
4650 if (response.payload != null) {
4651 length = 2 + response.payload.length;
4652 result = new byte[length];
4653 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4654 } else {
4655 result = new byte[length];
4656 }
4657
4658 result[length - 1] = (byte) response.sw2;
4659 result[length - 2] = (byte) response.sw1;
4660 return result;
4661 } finally {
4662 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004663 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004664 }
4665
Nathan Haroldb3014052017-01-25 15:57:32 -08004666 /**
4667 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4668 * on a particular subscription
4669 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004670 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4671 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004672 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004673 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004674 return null;
4675 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004676
4677 final long identity = Binder.clearCallingIdentity();
4678 try {
4679 if (appType != TelephonyManager.APPTYPE_USIM
4680 && appType != TelephonyManager.APPTYPE_SIM) {
4681 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4682 return null;
4683 }
4684 Object response = sendRequest(
4685 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4686 if (response instanceof String[]) {
4687 return (String[]) response;
4688 }
yincheng zhao2737e882019-09-06 17:06:54 -07004689 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004690 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004691 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004692 } finally {
4693 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004694 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004695 }
4696
yincheng zhao2737e882019-09-06 17:06:54 -07004697 /**
4698 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4699 * subscription.
4700 *
4701 * @param subId the id of the subscription.
4702 * @param appType the uicc app type, must be USIM or SIM.
4703 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4704 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004705 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004706 * @return number of fplmns that is successfully written to the SIM.
4707 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004708 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4709 String callingFeatureId) {
4710 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4711 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004712 if (DBG) logv("no permissions for setForbiddenplmns");
4713 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4714 }
4715 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4716 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4717 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4718 }
4719 if (fplmns == null) {
4720 throw new IllegalArgumentException("Fplmn List provided is null");
4721 }
4722 for (String fplmn : fplmns) {
4723 if (!CellIdentity.isValidPlmn(fplmn)) {
4724 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4725 }
4726 }
4727 final long identity = Binder.clearCallingIdentity();
4728 try {
4729 Object response = sendRequest(
4730 CMD_SET_FORBIDDEN_PLMNS,
4731 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4732 subId);
4733 return (int) response;
4734 } finally {
4735 Binder.restoreCallingIdentity(identity);
4736 }
4737 }
4738
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004739 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004740 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4742 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 final long identity = Binder.clearCallingIdentity();
4745 try {
4746 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4747 if (response.payload == null) {
4748 return "";
4749 }
Evan Charltonc66da362014-05-16 14:06:40 -07004750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004751 // Append the returned status code to the end of the response payload.
4752 String s = Integer.toHexString(
4753 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4754 s = IccUtils.bytesToHexString(response.payload) + s;
4755 return s;
4756 } finally {
4757 Binder.restoreCallingIdentity(identity);
4758 }
Evan Charltonc66da362014-05-16 14:06:40 -07004759 }
4760
Jake Hambye994d462014-02-03 13:10:13 -08004761 /**
4762 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4763 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4764 *
4765 * @param itemID the ID of the item to read
4766 * @return the NV item as a String, or null on error.
4767 */
4768 @Override
4769 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004770 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4772 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773
4774 final long identity = Binder.clearCallingIdentity();
4775 try {
4776 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004777 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004778 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4779 return value;
4780 } finally {
4781 Binder.restoreCallingIdentity(identity);
4782 }
Jake Hambye994d462014-02-03 13:10:13 -08004783 }
4784
4785 /**
4786 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4787 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4788 *
4789 * @param itemID the ID of the item to read
4790 * @param itemValue the value to write, as a String
4791 * @return true on success; false on any failure
4792 */
4793 @Override
4794 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004795 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4797 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798
4799 final long identity = Binder.clearCallingIdentity();
4800 try {
4801 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4802 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004803 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004804 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4805 return success;
4806 } finally {
4807 Binder.restoreCallingIdentity(identity);
4808 }
Jake Hambye994d462014-02-03 13:10:13 -08004809 }
4810
4811 /**
4812 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4813 * Used for device configuration by some CDMA operators.
4814 *
4815 * @param preferredRoamingList byte array containing the new PRL
4816 * @return true on success; false on any failure
4817 */
4818 @Override
4819 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4821 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004822
4823 final long identity = Binder.clearCallingIdentity();
4824 try {
4825 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4826 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4827 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4828 return success;
4829 } finally {
4830 Binder.restoreCallingIdentity(identity);
4831 }
Jake Hambye994d462014-02-03 13:10:13 -08004832 }
4833
4834 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004835 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004836 * Used for device configuration by some CDMA operators.
4837 *
chen xu6dac5ab2018-10-26 17:39:23 -07004838 * @param slotIndex - device slot.
4839 *
Jake Hambye994d462014-02-03 13:10:13 -08004840 * @return true on success; false on any failure
4841 */
4842 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004843 public boolean resetModemConfig(int slotIndex) {
4844 Phone phone = PhoneFactory.getPhone(slotIndex);
4845 if (phone != null) {
4846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4847 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004848
chen xu6dac5ab2018-10-26 17:39:23 -07004849 final long identity = Binder.clearCallingIdentity();
4850 try {
4851 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4852 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4853 return success;
4854 } finally {
4855 Binder.restoreCallingIdentity(identity);
4856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004857 }
chen xu6dac5ab2018-10-26 17:39:23 -07004858 return false;
4859 }
4860
4861 /**
4862 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4863 *
4864 * @param slotIndex - device slot.
4865 *
4866 * @return true on success; false on any failure
4867 */
4868 @Override
4869 public boolean rebootModem(int slotIndex) {
4870 Phone phone = PhoneFactory.getPhone(slotIndex);
4871 if (phone != null) {
4872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4873 mApp, phone.getSubId(), "rebootModem");
4874
4875 final long identity = Binder.clearCallingIdentity();
4876 try {
4877 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4878 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4879 return success;
4880 } finally {
4881 Binder.restoreCallingIdentity(identity);
4882 }
4883 }
4884 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004885 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004886
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004887 public String[] getPcscfAddress(String apnType, String callingPackage,
4888 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004889 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4891 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004892 return new String[0];
4893 }
4894
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895 final long identity = Binder.clearCallingIdentity();
4896 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004897 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004898 } finally {
4899 Binder.restoreCallingIdentity(identity);
4900 }
Wink Saville36469e72014-06-11 15:17:00 -07004901 }
4902
Brad Ebinger51f743a2017-01-23 13:50:20 -08004903 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004904 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4905 * {@link #disableIms(int)}.
4906 * @param slotIndex device slot.
4907 */
4908 public void resetIms(int slotIndex) {
4909 enforceModifyPermission();
4910
4911 final long identity = Binder.clearCallingIdentity();
4912 try {
4913 if (mImsResolver == null) {
4914 // may happen if the does not support IMS.
4915 return;
4916 }
4917 mImsResolver.disableIms(slotIndex);
4918 mImsResolver.enableIms(slotIndex);
4919 } finally {
4920 Binder.restoreCallingIdentity(identity);
4921 }
4922 }
4923
4924 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004925 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4926 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004927 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004928 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004929 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004930
4931 final long identity = Binder.clearCallingIdentity();
4932 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004933 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004934 // may happen if the device does not support IMS.
4935 return;
4936 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004937 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004938 } finally {
4939 Binder.restoreCallingIdentity(identity);
4940 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004941 }
4942
4943 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004944 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4945 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004946 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004947 public void disableIms(int slotId) {
4948 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949
4950 final long identity = Binder.clearCallingIdentity();
4951 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004952 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004953 // may happen if the device does not support IMS.
4954 return;
4955 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004956 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004957 } finally {
4958 Binder.restoreCallingIdentity(identity);
4959 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004960 }
4961
4962 /**
4963 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4964 * feature or {@link null} if the service is not available. If the feature is available, the
4965 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4966 */
4967 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004968 IImsServiceFeatureCallback callback) {
4969 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970
4971 final long identity = Binder.clearCallingIdentity();
4972 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004973 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004974 // may happen if the device does not support IMS.
4975 return null;
4976 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004977 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004978 } finally {
4979 Binder.restoreCallingIdentity(identity);
4980 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004981 }
4982
4983 /**
4984 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4985 * feature during emergency calling or {@link null} if the service is not available. If the
4986 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4987 * listener for feature updates.
4988 */
4989 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4990 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991
4992 final long identity = Binder.clearCallingIdentity();
4993 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004994 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004995 // may happen if the device does not support IMS.
4996 return null;
4997 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004998 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 } finally {
5000 Binder.restoreCallingIdentity(identity);
5001 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005002 }
5003
Brad Ebinger5f64b052017-12-14 14:26:15 -08005004 /**
5005 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005006 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005007 */
5008 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5009 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010
5011 final long identity = Binder.clearCallingIdentity();
5012 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005013 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005014 // may happen if the device does not support IMS.
5015 return null;
5016 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005017 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018 } finally {
5019 Binder.restoreCallingIdentity(identity);
5020 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005021 }
5022
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005023 /**
5024 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005025 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005026 */
5027 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5028 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005029
5030 final long identity = Binder.clearCallingIdentity();
5031 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005032 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005033 // may happen if the device does not support IMS.
5034 return null;
5035 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005036 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005037 } finally {
5038 Binder.restoreCallingIdentity(identity);
5039 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005040 }
5041
Brad Ebinger884c07b2018-02-15 16:17:40 -08005042 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005043 * Sets the ImsService Package Name that Telephony will bind to.
5044 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005045 * @param slotIndex the slot ID that the ImsService should bind for.
5046 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005047 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005048 * @param featureTypes An integer array of feature types associated with a packageName.
5049 * @param packageName The name of the package that the current configuration will be replaced
5050 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005051 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005052 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005053 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5054 int[] featureTypes, String packageName) {
5055 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5056 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5058 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005059 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005060
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005061 final long identity = Binder.clearCallingIdentity();
5062 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005063 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005064 // may happen if the device does not support IMS.
5065 return false;
5066 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005067 Map<Integer, String> featureConfig = new HashMap<>();
5068 for (int featureType : featureTypes) {
5069 featureConfig.put(featureType, packageName);
5070 }
5071 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5072 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073 } finally {
5074 Binder.restoreCallingIdentity(identity);
5075 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005076 }
5077
5078 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005079 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005080 *
5081 * @param slotId The slot that the ImsService is associated with.
5082 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5083 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005084 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005085 * @return the package name of the ImsService configuration.
5086 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005087 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5088 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005089 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005090 TelephonyPermissions
5091 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5092 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5093 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 final long identity = Binder.clearCallingIdentity();
5096 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005097 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005098 // may happen if the device does not support IMS.
5099 return "";
5100 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005101 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005102 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5103 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 } finally {
5105 Binder.restoreCallingIdentity(identity);
5106 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005107 }
5108
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005109 /**
5110 * Get the MmTelFeature state associated with the requested subscription id.
5111 * @param subId The subscription that the MmTelFeature is associated with.
5112 * @param callback A callback with an integer containing the
5113 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5114 */
5115 @Override
5116 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5117 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5118 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5119 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5120 "IMS not available on device.");
5121 }
5122 final long token = Binder.clearCallingIdentity();
5123 try {
5124 int slotId = getSlotIndex(subId);
5125 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5126 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5127 + subId + "'");
5128 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5129 }
5130 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5131 try {
5132 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5133 } catch (RemoteException e) {
5134 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5135 + "Ignore");
5136 }
5137 });
5138 } finally {
5139 Binder.restoreCallingIdentity(token);
5140 }
5141 }
5142
Wink Saville36469e72014-06-11 15:17:00 -07005143 public void setImsRegistrationState(boolean registered) {
5144 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145
5146 final long identity = Binder.clearCallingIdentity();
5147 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005148 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149 } finally {
5150 Binder.restoreCallingIdentity(identity);
5151 }
Wink Saville36469e72014-06-11 15:17:00 -07005152 }
5153
5154 /**
Stuart Scott54788802015-03-30 13:18:01 -07005155 * Set the network selection mode to automatic.
5156 *
5157 */
5158 @Override
5159 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5161 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162
5163 final long identity = Binder.clearCallingIdentity();
5164 try {
shilufc958392020-01-20 11:36:01 -08005165 if (!isActiveSubscription(subId)) {
5166 return;
5167 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5169 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5170 } finally {
5171 Binder.restoreCallingIdentity(identity);
5172 }
Stuart Scott54788802015-03-30 13:18:01 -07005173 }
5174
Pengquan Mengea84e042018-09-20 14:57:26 -07005175 /**
5176 * Ask the radio to connect to the input network and change selection mode to manual.
5177 *
5178 * @param subId the id of the subscription.
5179 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5180 * the operator to attach to.
5181 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5182 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5183 * normal network selection next time.
5184 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005185 */
5186 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005187 public boolean setNetworkSelectionModeManual(
5188 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5190 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005191
5192 if (!isActiveSubscription(subId)) {
5193 return false;
5194 }
5195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196 final long identity = Binder.clearCallingIdentity();
5197 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005198 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005200 if (DBG) {
5201 log("setNetworkSelectionModeManual: subId: " + subId
5202 + " operator: " + operatorInfo);
5203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005208 }
shilu84f6e8b2019-12-19 13:58:01 -08005209 /**
5210 * Get the manual network selection
5211 *
5212 * @param subId the id of the subscription.
5213 *
5214 * @return the previously saved user selected PLMN
5215 */
5216 @Override
5217 public String getManualNetworkSelectionPlmn(int subId) {
5218 TelephonyPermissions
5219 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5220 mApp, subId, "getManualNetworkSelectionPlmn");
5221
5222 final long identity = Binder.clearCallingIdentity();
5223 try {
5224 if (!isActiveSubscription(subId)) {
5225 return "";
5226 }
5227
5228 final Phone phone = getPhone(subId);
5229 if (phone == null) {
5230 return "";
5231 }
5232 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5233 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5234 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
5238 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005239
5240 /**
5241 * Scans for available networks.
5242 */
5243 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005244 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5245 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5247 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005248 LocationAccessPolicy.LocationPermissionResult locationResult =
5249 LocationAccessPolicy.checkLocationPermission(mApp,
5250 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5251 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005252 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005253 .setCallingPid(Binder.getCallingPid())
5254 .setCallingUid(Binder.getCallingUid())
5255 .setMethod("getCellNetworkScanResults")
5256 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5257 .build());
5258 switch (locationResult) {
5259 case DENIED_HARD:
5260 throw new SecurityException("Not allowed to access scan results -- location");
5261 case DENIED_SOFT:
5262 return null;
5263 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264
Pengquan Menga1bb6272018-09-06 09:59:22 -07005265 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005266 try {
5267 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005268 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 } finally {
5271 Binder.restoreCallingIdentity(identity);
5272 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005273 }
5274
5275 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005276 * Get the call forwarding info, given the call forwarding reason.
5277 */
5278 @Override
5279 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5280 enforceReadPrivilegedPermission("getCallForwarding");
5281 long identity = Binder.clearCallingIdentity();
5282 try {
5283 if (DBG) {
5284 log("getCallForwarding: subId " + subId
5285 + " callForwardingReason" + callForwardingReason);
5286 }
5287 return (CallForwardingInfo) sendRequest(
5288 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5289 } finally {
5290 Binder.restoreCallingIdentity(identity);
5291 }
5292 }
5293
5294 /**
5295 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5296 * reason, the number to forward, and the timeout before the forwarding is attempted.
5297 */
5298 @Override
5299 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5300 enforceModifyPermission();
5301 long identity = Binder.clearCallingIdentity();
5302 try {
5303 if (DBG) {
5304 log("setCallForwarding: subId " + subId
5305 + " callForwardingInfo" + callForwardingInfo);
5306 }
5307 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5308 } finally {
5309 Binder.restoreCallingIdentity(identity);
5310 }
5311 }
5312
5313 /**
5314 * Get the call forwarding info, given the call forwarding reason.
5315 */
5316 @Override
5317 public int getCallWaitingStatus(int subId) {
5318 enforceReadPrivilegedPermission("getCallForwarding");
5319 long identity = Binder.clearCallingIdentity();
5320 try {
5321 if (DBG) log("getCallWaitingStatus: subId " + subId);
5322 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5323 } finally {
5324 Binder.restoreCallingIdentity(identity);
5325 }
5326 }
5327
5328 /**
5329 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5330 * reason, the number to forward, and the timeout before the forwarding is attempted.
5331 */
5332 @Override
5333 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5334 enforceModifyPermission();
5335 long identity = Binder.clearCallingIdentity();
5336 try {
5337 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5338 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
5342 }
5343
5344 /**
yinxub1bed742017-04-17 11:45:04 -07005345 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005346 *
yinxub1bed742017-04-17 11:45:04 -07005347 * @param subId id of the subscription
5348 * @param request contains the radio access networks with bands/channels to scan
5349 * @param messenger callback messenger for scan results or errors
5350 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005351 * @return the id of the requested scan which can be used to stop the scan.
5352 */
5353 @Override
5354 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005355 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5357 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005358 LocationAccessPolicy.LocationPermissionResult locationResult =
5359 LocationAccessPolicy.checkLocationPermission(mApp,
5360 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5361 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005362 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005363 .setCallingPid(Binder.getCallingPid())
5364 .setCallingUid(Binder.getCallingUid())
5365 .setMethod("requestNetworkScan")
5366 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5367 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005368 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005369 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005370 if (e != null) {
5371 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5372 throw e;
5373 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005374 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005375 return TelephonyScanManager.INVALID_SCAN_ID;
5376 }
5377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 }
Hall Liu912dfd32019-04-25 14:02:26 -07005379 int callingUid = Binder.getCallingUid();
5380 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005381 final long identity = Binder.clearCallingIdentity();
5382 try {
5383 return mNetworkScanRequestTracker.startNetworkScan(
5384 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005385 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005386 } finally {
5387 Binder.restoreCallingIdentity(identity);
5388 }
yinxu504e1392017-04-12 16:03:22 -07005389 }
5390
Hall Liub2ac8ef2019-02-28 15:56:23 -08005391 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005392 NetworkScanRequest request, int subId) {
5393 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5394 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5395 boolean hasNetworkScanPermission =
5396 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5397 == PERMISSION_GRANTED;
5398
5399 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5400 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5401 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005402 }
5403
5404 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5405 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005406 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5407 return new SecurityException("Specific channels must not be"
5408 + " scanned without location access.");
5409 }
5410 }
5411 }
5412
Hall Liub2ac8ef2019-02-28 15:56:23 -08005413 return null;
5414 }
5415
yinxu504e1392017-04-12 16:03:22 -07005416 /**
5417 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005418 *
5419 * @param subId id of the subscription
5420 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005421 */
5422 @Override
5423 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5425 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426
Hall Liu912dfd32019-04-25 14:02:26 -07005427 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428 final long identity = Binder.clearCallingIdentity();
5429 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005430 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 } finally {
5432 Binder.restoreCallingIdentity(identity);
5433 }
yinxu504e1392017-04-12 16:03:22 -07005434 }
5435
5436 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005437 * Get the calculated preferred network type.
5438 * Used for debugging incorrect network type.
5439 *
5440 * @return the preferred network type, defined in RILConstants.java.
5441 */
5442 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005443 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005444 final Phone defaultPhone = getDefaultPhone();
5445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005446 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005447 return RILConstants.PREFERRED_NETWORK_MODE;
5448 }
5449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 final long identity = Binder.clearCallingIdentity();
5451 try {
5452 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005453 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454 } finally {
5455 Binder.restoreCallingIdentity(identity);
5456 }
Junda Liu84d15a22014-07-02 11:21:04 -07005457 }
5458
5459 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005460 * Get the preferred network type.
5461 * Used for device configuration by some CDMA operators.
5462 *
5463 * @return the preferred network type, defined in RILConstants.java.
5464 */
5465 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005466 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005467 TelephonyPermissions
5468 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5469 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470
5471 final long identity = Binder.clearCallingIdentity();
5472 try {
5473 if (DBG) log("getPreferredNetworkType");
5474 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5475 int networkType = (result != null ? result[0] : -1);
5476 if (DBG) log("getPreferredNetworkType: " + networkType);
5477 return networkType;
5478 } finally {
5479 Binder.restoreCallingIdentity(identity);
5480 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005481 }
5482
5483 /**
5484 * Set the preferred network type.
5485 * Used for device configuration by some CDMA operators.
5486 *
5487 * @param networkType the preferred network type, defined in RILConstants.java.
5488 * @return true on success; false on any failure.
5489 */
5490 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005491 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5493 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494
5495 final long identity = Binder.clearCallingIdentity();
5496 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005497 Settings.Global.putInt(mApp.getContentResolver(),
5498 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5499 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 } finally {
5501 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005502 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005503 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005504
5505 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005506 * Get the allowed network types that store in the telephony provider.
5507 *
5508 * @param subId the id of the subscription.
5509 * @return allowedNetworkTypes the allowed network types.
5510 */
5511 @Override
5512 public long getAllowedNetworkTypes(int subId) {
5513 TelephonyPermissions
5514 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5515 mApp, subId, "getAllowedNetworkTypes");
5516
5517 final long identity = Binder.clearCallingIdentity();
5518 try {
5519 return SubscriptionManager.getLongSubscriptionProperty(
5520 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5521 } finally {
5522 Binder.restoreCallingIdentity(identity);
5523 }
5524 }
5525
5526 /**
5527 * Set the allowed network types.
5528 *
5529 * @param subId the id of the subscription.
5530 * @param allowedNetworkTypes the allowed network types.
5531 * @return true on success; false on any failure.
5532 */
5533 @Override
5534 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5536 mApp, subId, "setAllowedNetworkTypes");
5537 final long identity = Binder.clearCallingIdentity();
5538 try {
5539 SubscriptionManager.setSubscriptionProperty(subId,
5540 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5541 String.valueOf(allowedNetworkTypes));
5542 return setPreferredNetworkTypesInternal(subId);
5543 } finally {
5544 Binder.restoreCallingIdentity(identity);
5545 }
5546 }
5547
5548 private boolean setPreferredNetworkTypesInternal(int subId) {
5549 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5550 Settings.Global.getInt(mApp.getContentResolver(),
5551 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5552 RILConstants.PREFERRED_NETWORK_MODE));
5553 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5554 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5555 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5556 (int) (networkTypeBitMask & allowedNetworkTypes));
5557
5558 if (DBG) {
5559 log("setPreferredNetworkTypesInternal: subId " + subId
5560 + " networkTypes " + networkTypeBitMask
5561 + " allowedNetworkTypes " + allowedNetworkTypes
5562 + " networkMode " + networkMode);
5563 }
5564
5565 Boolean success = (Boolean) sendRequest(
5566 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5567 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5568 return success;
5569 }
5570
5571 /**
Miaoa84611c2019-03-15 09:21:10 +08005572 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005573 *
Miaoa84611c2019-03-15 09:21:10 +08005574 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005575 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005576 * @hide
5577 */
5578 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005579 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005580 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005582 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 try {
Miaoa84611c2019-03-15 09:21:10 +08005584 if (phone != null) {
5585 return phone.hasMatchedTetherApnSetting();
5586 } else {
5587 return false;
5588 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 } finally {
5590 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005591 }
Junda Liu475951f2014-11-07 16:45:03 -08005592 }
5593
5594 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005595 * Set mobile data enabled
5596 * Used by the user through settings etc to turn on/off mobile data
5597 *
5598 * @param enable {@code true} turn turn data on, else {@code false}
5599 */
5600 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005601 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5603 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604
5605 final long identity = Binder.clearCallingIdentity();
5606 try {
5607 int phoneId = mSubscriptionController.getPhoneId(subId);
5608 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5609 Phone phone = PhoneFactory.getPhone(phoneId);
5610 if (phone != null) {
5611 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005612 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005613 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005614 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 }
5616 } finally {
5617 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005618 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005619 }
5620
5621 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005622 * Enable or disable always reporting signal strength changes from radio.
5623 *
5624 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5625 */
5626 @Override
5627 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5628 enforceModifyPermission();
5629 enforceSystemCaller();
5630
5631 final long identity = Binder.clearCallingIdentity();
5632 final Phone phone = getPhone(subId);
5633 try {
5634 if (phone != null) {
5635 if (DBG) {
5636 log("setAlwaysReportSignalStrength: subId=" + subId
5637 + " isEnable=" + isEnable);
5638 }
5639 phone.setAlwaysReportSignalStrength(isEnable);
5640 } else {
5641 loge("setAlwaysReportSignalStrength: no phone found for subId="
5642 + subId);
5643 }
5644 } finally {
5645 Binder.restoreCallingIdentity(identity);
5646 }
5647 }
5648
5649 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005650 * Get the user enabled state of Mobile Data.
5651 *
5652 * TODO: remove and use isUserDataEnabled.
5653 * This can't be removed now because some vendor codes
5654 * calls through ITelephony directly while they should
5655 * use TelephonyManager.
5656 *
5657 * @return true on enabled
5658 */
5659 @Override
5660 public boolean getDataEnabled(int subId) {
5661 return isUserDataEnabled(subId);
5662 }
5663
5664 /**
5665 * Get whether mobile data is enabled per user setting.
5666 *
5667 * There are other factors deciding whether mobile data is actually enabled, but they are
5668 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005669 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005670 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005671 *
5672 * @return {@code true} if data is enabled else {@code false}
5673 */
5674 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005675 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005676 try {
5677 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5678 null);
5679 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5681 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683
5684 final long identity = Binder.clearCallingIdentity();
5685 try {
5686 int phoneId = mSubscriptionController.getPhoneId(subId);
5687 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5688 Phone phone = PhoneFactory.getPhone(phoneId);
5689 if (phone != null) {
5690 boolean retVal = phone.isUserDataEnabled();
5691 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5692 return retVal;
5693 } else {
5694 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5695 return false;
5696 }
5697 } finally {
5698 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005699 }
5700 }
5701
5702 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005703 * Checks if the device is capable of mobile data by considering whether whether the
5704 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5705 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005706 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005707 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005708 */
5709 @Override
5710 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005711 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712
5713 final long identity = Binder.clearCallingIdentity();
5714 try {
5715 int phoneId = mSubscriptionController.getPhoneId(subId);
5716 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5717 Phone phone = PhoneFactory.getPhone(phoneId);
5718 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005719 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5721 return retVal;
5722 } else {
5723 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5724 return false;
5725 }
5726 } finally {
5727 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005728 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005729 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005730
Malcolm Chen71c9a8c2020-02-24 15:12:43 -08005731 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005732 Phone phone) {
5733 //load access rules from carrier configs, and check those as well: b/139133814
5734 SubscriptionController subController = SubscriptionController.getInstance();
5735 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5736 || subController == null) return privilegeFromSim;
5737
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005738 PackageManager pkgMgr = phone.getContext().getPackageManager();
5739 String[] packages = pkgMgr.getPackagesForUid(uid);
5740
5741 final long identity = Binder.clearCallingIdentity();
5742 try {
5743 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5744 SubscriptionManager subManager = (SubscriptionManager)
5745 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5746 for (String pkg : packages) {
5747 if (subManager.canManageSubscription(subInfo, pkg)) {
5748 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5749 }
5750 }
5751 return privilegeFromSim;
5752 } finally {
5753 Binder.restoreCallingIdentity(identity);
5754 }
5755 }
5756
5757 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5758 String pkgName) {
5759 //load access rules from carrier configs, and check those as well: b/139133814
5760 SubscriptionController subController = SubscriptionController.getInstance();
5761 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5762 || subController == null) return privilegeFromSim;
5763
5764 final long identity = Binder.clearCallingIdentity();
5765 try {
5766 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5767 SubscriptionManager subManager = (SubscriptionManager)
5768 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5769 return subManager.canManageSubscription(subInfo, pkgName)
5770 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5771 } finally {
5772 Binder.restoreCallingIdentity(identity);
5773 }
5774 }
5775
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005776 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005777 public int getCarrierPrivilegeStatus(int subId) {
5778 final Phone phone = getPhone(subId);
5779 if (phone == null) {
5780 loge("getCarrierPrivilegeStatus: Invalid subId");
5781 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5782 }
5783 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005784 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005785 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005786 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5787 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005788
5789 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5790 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chen71c9a8c2020-02-24 15:12:43 -08005791 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005792 }
Junda Liu29340342014-07-10 15:23:27 -07005793
5794 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005795 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005796 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005797 final Phone phone = getPhone(subId);
5798 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005799 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005800 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5801 }
5802 UiccProfile profile =
5803 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5804 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005805 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005806 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5807 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005808 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005809 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chen71c9a8c2020-02-24 15:12:43 -08005810 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005811 }
5812
5813 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005814 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5815 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005816 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005817 }
5818
5819 int phoneId = SubscriptionManager.getPhoneId(subId);
5820 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005821 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005822 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005823 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5824 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005825 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5826 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5827 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005828 }
5829
5830 @Override
5831 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005832 if (TextUtils.isEmpty(pkgName))
5833 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005834 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5835 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5836 UiccCard card = UiccController.getInstance().getUiccCard(i);
5837 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005838 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005839 continue;
5840 }
5841
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005842 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5843 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5844 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005845 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5846 break;
5847 }
5848 }
5849
5850 return result;
Junda Liu29340342014-07-10 15:23:27 -07005851 }
Derek Tan89e89d42014-07-08 17:00:10 -07005852
5853 @Override
Junda Liue64de782015-04-16 17:19:16 -07005854 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5855 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5856 loge("phoneId " + phoneId + " is not valid.");
5857 return null;
5858 }
5859 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005860 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005861 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005862 return null ;
5863 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005864 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005865 }
5866
Amith Yamasani6e118872016-02-19 12:53:51 -08005867 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005868 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005869 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005870 List<String> privilegedPackages = new ArrayList<>();
5871 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005872 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5873 // has UICC in that slot.
5874 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005875 if (card.hasCarrierPrivilegeRules()) {
5876 if (packages == null) {
5877 // Only check packages in user 0 for now
5878 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005879 PackageManager.MATCH_DISABLED_COMPONENTS
5880 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005881 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005882 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005883 }
5884 for (int p = packages.size() - 1; p >= 0; p--) {
5885 PackageInfo pkgInfo = packages.get(p);
5886 if (pkgInfo != null && pkgInfo.packageName != null
5887 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005888 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005889 privilegedPackages.add(pkgInfo.packageName);
5890 }
5891 }
5892 }
5893 }
5894 return privilegedPackages;
5895 }
5896
chen xuf7e9fe82019-05-09 19:31:02 -07005897 @Override
5898 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005899 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5900
5901 final long identity = Binder.clearCallingIdentity();
5902
chen xuf7e9fe82019-05-09 19:31:02 -07005903 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005904 try {
5905 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5906 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5907 }
5908 } finally {
5909 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005910 }
5911 return privilegedPackages;
5912 }
5913
Wink Savilleb564aae2014-10-23 10:18:09 -07005914 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005915 final Phone phone = getPhone(subId);
5916 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005917 if (card == null) {
5918 loge("getIccId: No UICC");
5919 return null;
5920 }
5921 String iccId = card.getIccId();
5922 if (TextUtils.isEmpty(iccId)) {
5923 loge("getIccId: ICC ID is null or empty.");
5924 return null;
5925 }
5926 return iccId;
5927 }
5928
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005929 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005930 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5931 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005932 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005933 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 final long identity = Binder.clearCallingIdentity();
5936 try {
5937 final String iccId = getIccId(subId);
5938 final Phone phone = getPhone(subId);
5939 if (phone == null) {
5940 return false;
5941 }
5942 final String subscriberId = phone.getSubscriberId();
5943
5944 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08005945 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946 + subscriberId + " to " + number);
5947 }
5948
5949 if (TextUtils.isEmpty(iccId)) {
5950 return false;
5951 }
5952
5953 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5954
5955 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5956 if (alphaTag == null) {
5957 editor.remove(alphaTagPrefKey);
5958 } else {
5959 editor.putString(alphaTagPrefKey, alphaTag);
5960 }
5961
5962 // Record both the line number and IMSI for this ICCID, since we need to
5963 // track all merged IMSIs based on line number
5964 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5965 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5966 if (number == null) {
5967 editor.remove(numberPrefKey);
5968 editor.remove(subscriberPrefKey);
5969 } else {
5970 editor.putString(numberPrefKey, number);
5971 editor.putString(subscriberPrefKey, subscriberId);
5972 }
5973
5974 editor.commit();
5975 return true;
5976 } finally {
5977 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005978 }
Derek Tan7226c842014-07-02 17:42:23 -07005979 }
5980
5981 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005982 public String getLine1NumberForDisplay(int subId, String callingPackage,
5983 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005984 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005986 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005987 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005988 return null;
5989 }
Derek Tan97ebb422014-09-05 16:55:38 -07005990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 final long identity = Binder.clearCallingIdentity();
5992 try {
5993 String iccId = getIccId(subId);
5994 if (iccId != null) {
5995 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5996 if (DBG_MERGE) {
5997 log("getLine1NumberForDisplay returning "
5998 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5999 }
6000 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006002 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6003 return null;
6004 } finally {
6005 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006006 }
Derek Tan7226c842014-07-02 17:42:23 -07006007 }
6008
6009 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006010 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6011 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006013 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006014 return null;
6015 }
Derek Tan97ebb422014-09-05 16:55:38 -07006016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 final long identity = Binder.clearCallingIdentity();
6018 try {
6019 String iccId = getIccId(subId);
6020 if (iccId != null) {
6021 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6022 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6023 }
6024 return null;
6025 } finally {
6026 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006027 }
Derek Tan7226c842014-07-02 17:42:23 -07006028 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006029
6030 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006031 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6032 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006033 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6034 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006036 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006037 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006038 return null;
6039 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006040
Jordan Liub49b04b2019-05-06 14:45:15 -07006041 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6042 // the process, where TelephonyManager was instantiated.
6043 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006044 final long identity = Binder.clearCallingIdentity();
6045 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006046 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006047 final TelephonyManager tele = TelephonyManager.from(context);
6048 final SubscriptionManager sub = SubscriptionManager.from(context);
6049
6050 // Figure out what subscribers are currently active
6051 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052
Jordan Liub49b04b2019-05-06 14:45:15 -07006053 // Only consider subs which match the current subId
6054 // This logic can be simplified. See b/131189269 for progress.
6055 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006056 activeSubscriberIds.add(tele.getSubscriberId(subId));
6057 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006058
6059 // First pass, find a number override for an active subscriber
6060 String mergeNumber = null;
6061 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6062 for (String key : prefs.keySet()) {
6063 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6064 final String subscriberId = (String) prefs.get(key);
6065 if (activeSubscriberIds.contains(subscriberId)) {
6066 final String iccId = key.substring(
6067 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6068 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6069 mergeNumber = (String) prefs.get(numberKey);
6070 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006071 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 + " for active subscriber " + subscriberId);
6073 }
6074 if (!TextUtils.isEmpty(mergeNumber)) {
6075 break;
6076 }
6077 }
6078 }
6079 }
6080
6081 // Shortcut when no active merged subscribers
6082 if (TextUtils.isEmpty(mergeNumber)) {
6083 return null;
6084 }
6085
6086 // Second pass, find all subscribers under that line override
6087 final ArraySet<String> result = new ArraySet<>();
6088 for (String key : prefs.keySet()) {
6089 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6090 final String number = (String) prefs.get(key);
6091 if (mergeNumber.equals(number)) {
6092 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6093 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6094 final String subscriberId = (String) prefs.get(subscriberKey);
6095 if (!TextUtils.isEmpty(subscriberId)) {
6096 result.add(subscriberId);
6097 }
6098 }
6099 }
6100 }
6101
6102 final String[] resultArray = result.toArray(new String[result.size()]);
6103 Arrays.sort(resultArray);
6104 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006105 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6107 }
6108 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006109 } finally {
6110 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006111 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006112 }
6113
6114 @Override
zoey chen38003472019-12-13 17:16:31 +08006115 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6116 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006117
6118 final long identity = Binder.clearCallingIdentity();
6119 try {
6120 final TelephonyManager telephonyManager = mApp.getSystemService(
6121 TelephonyManager.class);
6122 String subscriberId = telephonyManager.getSubscriberId(subId);
6123 if (subscriberId == null) {
6124 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006125 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006126 + subId);
6127 }
6128 return null;
6129 }
6130
6131 final SubscriptionInfo info = SubscriptionController.getInstance()
6132 .getSubscriptionInfo(subId);
6133 final ParcelUuid groupUuid = info.getGroupUuid();
6134 // If it doesn't belong to any group, return just subscriberId of itself.
6135 if (groupUuid == null) {
6136 return new String[]{subscriberId};
6137 }
6138
6139 // Get all subscriberIds from the group.
6140 final List<String> mergedSubscriberIds = new ArrayList<>();
6141 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006142 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6143 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006144 for (SubscriptionInfo subInfo : groupInfos) {
6145 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6146 if (subscriberId != null) {
6147 mergedSubscriberIds.add(subscriberId);
6148 }
6149 }
6150
6151 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6152 } finally {
6153 Binder.restoreCallingIdentity(identity);
6154
6155 }
6156 }
6157
6158 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006159 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006160 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006161 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162
6163 final long identity = Binder.clearCallingIdentity();
6164 try {
6165 final Phone phone = getPhone(subId);
6166 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006170 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006171
6172 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006173 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006174 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6175 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006176 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6177 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006178
6179 final long identity = Binder.clearCallingIdentity();
6180 try {
6181 final Phone phone = getPhone(subId);
6182 if (phone == null) {
6183 return false;
6184 }
6185 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6186 cdmaNonRoamingList);
6187 } finally {
6188 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006189 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006190 }
6191
6192 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006193 @Deprecated
6194 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6195 enforceModifyPermission();
6196
6197 int returnValue = 0;
6198 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006199 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006200 if(result.exception == null) {
6201 if (result.result != null) {
6202 byte[] responseData = (byte[])(result.result);
6203 if(responseData.length > oemResp.length) {
6204 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6205 responseData.length + "bytes. Buffer Size is " +
6206 oemResp.length + "bytes.");
6207 }
6208 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6209 returnValue = responseData.length;
6210 }
6211 } else {
6212 CommandException ex = (CommandException) result.exception;
6213 returnValue = ex.getCommandError().ordinal();
6214 if(returnValue > 0) returnValue *= -1;
6215 }
6216 } catch (RuntimeException e) {
6217 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6218 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6219 if(returnValue > 0) returnValue *= -1;
6220 }
6221
6222 return returnValue;
6223 }
6224
6225 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006226 public void setRadioCapability(RadioAccessFamily[] rafs) {
6227 try {
6228 ProxyController.getInstance().setRadioCapability(rafs);
6229 } catch (RuntimeException e) {
6230 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6231 }
6232 }
6233
6234 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006235 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006236 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006237 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006238 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006239 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006240 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 final long identity = Binder.clearCallingIdentity();
6242 try {
chen xub97461a2018-10-26 14:17:57 -07006243 TelephonyPermissions
6244 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6245 mApp, phone.getSubId(), "getRadioAccessFamily");
6246 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006247 } finally {
6248 Binder.restoreCallingIdentity(identity);
6249 }
chen xub97461a2018-10-26 14:17:57 -07006250 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006251 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006252
6253 @Override
6254 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006255 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006256 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257
6258 final long identity = Binder.clearCallingIdentity();
6259 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006260 ImsManager.getInstance(defaultPhone.getContext(),
6261 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262 } finally {
6263 Binder.restoreCallingIdentity(identity);
6264 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006265 }
6266
6267 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006268 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006269 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6271 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006272 return false;
6273 }
Svet Ganovb320e182015-04-16 12:30:10 -07006274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275 final long identity = Binder.clearCallingIdentity();
6276 try {
6277 // Check the user preference and the system-level IMS setting. Even if the user has
6278 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6279 // In the long run, we may instead need to check if there exists a connection service
6280 // which can support video calling.
6281 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006282 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283 return imsManager.isVtEnabledByPlatform()
6284 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6285 && imsManager.isVtEnabledByUser();
6286 } finally {
6287 Binder.restoreCallingIdentity(identity);
6288 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006289 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006290
Andrew Leea1239f22015-03-02 17:44:07 -08006291 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006292 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6293 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006295 mApp, subId, callingPackage, callingFeatureId,
6296 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297 return false;
6298 }
6299
6300 final long identity = Binder.clearCallingIdentity();
6301 try {
6302 CarrierConfigManager configManager =
6303 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006304 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6306 } finally {
6307 Binder.restoreCallingIdentity(identity);
6308 }
Andrew Leea1239f22015-03-02 17:44:07 -08006309 }
6310
6311 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006312 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006314 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 return false;
6316 }
6317
6318 final long identity = Binder.clearCallingIdentity();
6319 try {
6320 CarrierConfigManager configManager =
6321 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006322 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006323 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6324 } finally {
6325 Binder.restoreCallingIdentity(identity);
6326 }
Andrew Leea1239f22015-03-02 17:44:07 -08006327 }
6328
Andrew Lee9431b832015-03-09 18:46:45 -07006329 @Override
6330 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006331 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006332 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006333 }
6334
6335 @Override
6336 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 final long identity = Binder.clearCallingIdentity();
6338 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006339 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006340 } finally {
6341 Binder.restoreCallingIdentity(identity);
6342 }
Andrew Lee9431b832015-03-09 18:46:45 -07006343 }
6344
Hall Liuf6668912018-10-31 17:05:23 -07006345 /**
6346 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6347 * support for the feature and device firmware support.
6348 *
6349 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6350 */
6351 @Override
6352 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006354 final Phone phone = getPhone(subscriptionId);
6355 if (phone == null) {
6356 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6357 return false;
6358 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006359 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006360 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006361 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6362 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006363 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 return isCarrierSupported && isDeviceSupported;
6365 } finally {
6366 Binder.restoreCallingIdentity(identity);
6367 }
Hall Liu98187582018-01-22 19:15:32 -08006368 }
6369
Hall Liuf6668912018-10-31 17:05:23 -07006370 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006371 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6372 * RTT setting, will return true if the device and carrier both support RTT.
6373 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006374 */
6375 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376 final long identity = Binder.clearCallingIdentity();
6377 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006378 boolean isRttSupported = isRttSupported(subscriptionId);
6379 boolean isUserRttSettingOn = Settings.Secure.getInt(
6380 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6381 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6382 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6383 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384 } finally {
6385 Binder.restoreCallingIdentity(identity);
6386 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006387 }
6388
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006389 @Deprecated
6390 @Override
6391 public String getDeviceId(String callingPackage) {
6392 return getDeviceIdWithFeature(callingPackage, null);
6393 }
6394
Sanket Padawe7310cc72015-01-14 09:53:20 -08006395 /**
6396 * Returns the unique device ID of phone, for example, the IMEI for
6397 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6398 *
6399 * <p>Requires Permission:
6400 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6401 */
6402 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006403 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006404 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006405 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006406 return null;
6407 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006408 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006409 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006410 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006411 return null;
6412 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413
6414 final long identity = Binder.clearCallingIdentity();
6415 try {
6416 return phone.getDeviceId();
6417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006420 }
6421
Ping Sunc67b7c22016-03-02 19:16:45 +08006422 /**
6423 * {@hide}
6424 * Returns the IMS Registration Status on a particular subid
6425 *
6426 * @param subId
6427 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006428 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006429 Phone phone = getPhone(subId);
6430 if (phone != null) {
6431 return phone.isImsRegistered();
6432 } else {
6433 return false;
6434 }
6435 }
6436
Santos Cordon7a1885b2015-02-03 11:15:19 -08006437 @Override
6438 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439 final long identity = Binder.clearCallingIdentity();
6440 try {
6441 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6442 } finally {
6443 Binder.restoreCallingIdentity(identity);
6444 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006445 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006446
Tyler Gunnf70ed162019-04-03 15:28:53 -07006447 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006448 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006449 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006450 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006451 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006452 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6453 }
6454 final long identity = Binder.clearCallingIdentity();
6455 try {
6456 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6457 } finally {
6458 Binder.restoreCallingIdentity(identity);
6459 }
6460 }
6461
6462 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006463 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6464 final long identity = Binder.clearCallingIdentity();
6465 try {
6466 Phone phone = getPhone(subscriptionId);
6467 if (phone == null) {
6468 return null;
6469 }
6470 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6471 } finally {
6472 Binder.restoreCallingIdentity(identity);
6473 }
6474 }
6475
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006476 /**
6477 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006478 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006479 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 final long identity = Binder.clearCallingIdentity();
6481 try {
6482 Phone phone = getPhone(subId);
6483 if (phone != null) {
6484 return phone.isWifiCallingEnabled();
6485 } else {
6486 return false;
6487 }
6488 } finally {
6489 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006490 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006491 }
6492
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006493 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006494 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006495 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006496 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006497 final long identity = Binder.clearCallingIdentity();
6498 try {
6499 Phone phone = getPhone(subId);
6500 if (phone != null) {
6501 return phone.isVideoEnabled();
6502 } else {
6503 return false;
6504 }
6505 } finally {
6506 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006507 }
6508 }
6509
6510 /**
6511 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6512 * defined in {@link ImsRegistrationImplBase}.
6513 */
6514 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006515 final long identity = Binder.clearCallingIdentity();
6516 try {
6517 Phone phone = getPhone(subId);
6518 if (phone != null) {
6519 return phone.getImsRegistrationTech();
6520 } else {
6521 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6522 }
6523 } finally {
6524 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006525 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006526 }
6527
Stuart Scott8eef64f2015-04-08 15:13:54 -07006528 @Override
6529 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006530 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006531 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6532 return;
6533 }
6534
Svet Ganovcc087f82015-05-12 20:35:54 -07006535 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006536
Svet Ganovcc087f82015-05-12 20:35:54 -07006537 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006538 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6539 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006540 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006541 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006542 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006543 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6544 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006545 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006546 // There has been issues when Sms raw table somehow stores orphan
6547 // fragments. They lead to garbled message when new fragments come
6548 // in and combined with those stale ones. In case this happens again,
6549 // user can reset all network settings which will clean up this table.
6550 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006551 // Clean up IMS settings as well here.
6552 int slotId = getSlotIndex(subId);
6553 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6554 ImsManager.getInstance(mApp, slotId).factoryReset();
6555 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006556
6557 // Erase modem config if erase modem on network setting is enabled.
6558 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6559 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6560 if (configValue != null && Boolean.parseBoolean(configValue)) {
6561 sendEraseModemConfig(getDefaultPhone());
6562 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006563 } finally {
6564 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006565 }
6566 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006567
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006568 private void cleanUpSmsRawTable(Context context) {
6569 ContentResolver resolver = context.getContentResolver();
6570 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6571 resolver.delete(uri, null, null);
6572 }
6573
Narayan Kamath1c496c22015-04-16 14:40:19 +01006574 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006575 public String getSimLocaleForSubscriber(int subId) {
6576 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6577 final Phone phone = getPhone(subId);
6578 if (phone == null) {
6579 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006580 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 final long identity = Binder.clearCallingIdentity();
6583 try {
chen xu5d3637b2019-01-21 23:31:38 -08006584 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006585 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006586 if (info == null) {
6587 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6588 return null;
6589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 // Try and fetch the locale from the carrier properties or from the SIM language
6591 // preferences (EF-PL and EF-LI)...
6592 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006593 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006594 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6595 if (localeFromDefaultSim != null) {
6596 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6597 if (DBG) log("Using locale from subId: " + subId + " locale: "
6598 + localeFromDefaultSim);
6599 return localeFromDefaultSim.toLanguageTag();
6600 } else {
6601 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 }
6603 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605 // The SIM language preferences only store a language (e.g. fr = French), not an
6606 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6607 // the SIM and carrier preferences does not include a country we add the country
6608 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006609 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006610 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006611 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612 return mccLocale.toLanguageTag();
6613 }
6614
6615 if (DBG) log("No locale found - returning null");
6616 return null;
6617 } finally {
6618 Binder.restoreCallingIdentity(identity);
6619 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006620 }
6621
6622 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006623 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6624 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006625 }
6626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006627 /**
6628 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6629 */
6630 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006631 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6632 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006633 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006634
Chenjie Yu1ba97252018-01-11 18:16:20 -08006635 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006636 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006637
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006638 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006639 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6640 * representing the state of the modem.
6641 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006642 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6643 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006644 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006645 */
6646 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006647 public void requestModemActivityInfo(ResultReceiver result) {
6648 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006649 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650
6651 final long identity = Binder.clearCallingIdentity();
6652 try {
6653 ModemActivityInfo ret = null;
6654 synchronized (mLastModemActivityInfo) {
6655 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6656 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006657 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006658 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006660 int[] txTimeMs = info.getTransmitTimeMillis();
6661 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006662 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006663 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006664 }
6665 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006666 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6667 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668 mLastModemActivityInfo.setIdleTimeMillis(
6669 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006670 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6671 mLastModemActivityInfo.setReceiveTimeMillis(
6672 info.getReceiveTimeMillis() + mLastModemActivityInfo
6673 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006674 }
Chen Xud78231e2019-09-10 18:49:52 -07006675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006676 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6677 mLastModemActivityInfo.getSleepTimeMillis(),
6678 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006679 mLastModemActivityInfo.getTransmitTimeMillis(),
6680 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006681 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006682 Bundle bundle = new Bundle();
6683 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6684 result.send(0, bundle);
6685 } finally {
6686 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006687 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006688 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006689
Siddharth Rayb8114062018-06-17 15:02:38 -07006690 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6691 // less than total activity duration.
6692 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6693 if (info == null) {
6694 return false;
6695 }
6696 int activityDurationMs =
6697 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6698 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006699 int[] txTimeMs = info.getTransmitTimeMillis();
6700 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6701 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006702 }
6703 return (info.isValid()
6704 && (info.getSleepTimeMillis() <= activityDurationMs)
6705 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006706 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006707 && (totalTxTimeMs <= activityDurationMs));
6708 }
6709
Jack Yu85bd38a2015-11-09 11:34:32 -08006710 /**
6711 * {@hide}
6712 * Returns the service state information on specified subscription.
6713 */
6714 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006715 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6716 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006717 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006718 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006719 return null;
6720 }
6721
Hall Liuf19c44f2018-11-27 14:38:17 -08006722 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6723 LocationAccessPolicy.checkLocationPermission(mApp,
6724 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6725 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006726 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006727 .setCallingPid(Binder.getCallingPid())
6728 .setCallingUid(Binder.getCallingUid())
6729 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006730 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006731 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6732 .build());
6733
6734 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6735 LocationAccessPolicy.checkLocationPermission(mApp,
6736 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6737 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006738 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006739 .setCallingPid(Binder.getCallingPid())
6740 .setCallingUid(Binder.getCallingUid())
6741 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006742 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006743 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6744 .build());
6745 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6746 boolean hasFinePermission =
6747 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6748 boolean hasCoarsePermission =
6749 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751 final long identity = Binder.clearCallingIdentity();
6752 try {
6753 final Phone phone = getPhone(subId);
6754 if (phone == null) {
6755 return null;
6756 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006757
Hall Liuf19c44f2018-11-27 14:38:17 -08006758 ServiceState ss = phone.getServiceState();
6759
6760 // Scrub out the location info in ServiceState depending on what level of access
6761 // the caller has.
6762 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006763 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6764 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006765 } finally {
6766 Binder.restoreCallingIdentity(identity);
6767 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006768 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006769
6770 /**
6771 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6772 *
6773 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6774 * voicemail ringtone.
6775 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6776 * PhoneAccount.
6777 */
6778 @Override
6779 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780 final long identity = Binder.clearCallingIdentity();
6781 try {
6782 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6783 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006784 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006785 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6788 } finally {
6789 Binder.restoreCallingIdentity(identity);
6790 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006791 }
6792
6793 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006794 * Sets the per-account voicemail ringtone.
6795 *
6796 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6797 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6798 *
6799 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6800 * voicemail ringtone.
6801 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6802 * PhoneAccount.
6803 */
6804 @Override
6805 public void setVoicemailRingtoneUri(String callingPackage,
6806 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006807 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006808 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006809 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6810 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6812 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6813 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006814 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006815
6816 final long identity = Binder.clearCallingIdentity();
6817 try {
6818 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6819 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006820 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821 }
6822 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6823 } finally {
6824 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006825 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006826 }
6827
6828 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006829 * Returns whether vibration is set for voicemail notification in Phone settings.
6830 *
6831 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6832 * voicemail vibration setting.
6833 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6834 */
6835 @Override
6836 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006837 final long identity = Binder.clearCallingIdentity();
6838 try {
6839 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6840 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006841 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006842 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006844 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6845 } finally {
6846 Binder.restoreCallingIdentity(identity);
6847 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006848 }
6849
Youhan Wange64578a2016-05-02 15:32:42 -07006850 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006851 * Sets the per-account voicemail vibration.
6852 *
6853 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6854 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6855 *
6856 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6857 * voicemail vibration setting.
6858 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6859 * specific PhoneAccount.
6860 */
6861 @Override
6862 public void setVoicemailVibrationEnabled(String callingPackage,
6863 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006864 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006865 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006866 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6867 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6869 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6870 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006871 }
6872
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873 final long identity = Binder.clearCallingIdentity();
6874 try {
6875 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6876 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006877 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006878 }
6879 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6880 } finally {
6881 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006882 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006883 }
6884
6885 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006886 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6887 *
6888 * @throws SecurityException if the caller does not have the required permission
6889 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006890 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006891 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006892 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006893 }
6894
6895 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006896 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6897 * permission.
6898 *
6899 * @throws SecurityException if the caller does not have the required permission
6900 */
6901 private void enforceSendSmsPermission() {
6902 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6903 }
6904
6905 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006906 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006907 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006908 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006909 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006910 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911 final long identity = Binder.clearCallingIdentity();
6912 try {
6913 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006914 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006915 if (componentName == null) {
6916 throw new SecurityException(
6917 "Caller not current active visual voicemail package[null]");
6918 }
6919 String vvmPackage = componentName.getPackageName();
6920 if (!callingPackage.equals(vvmPackage)) {
6921 throw new SecurityException("Caller not current active visual voicemail package["
6922 + vvmPackage + "]");
6923 }
6924 } finally {
6925 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006926 }
6927 }
6928
6929 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006930 * Return the application ID for the app type.
6931 *
6932 * @param subId the subscription ID that this request applies to.
6933 * @param appType the uicc app type.
6934 * @return Application ID for specificied app type, or null if no uicc.
6935 */
6936 @Override
6937 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006938 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006939 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006940
6941 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006942 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006943 if (phone == null) {
6944 return null;
6945 }
6946 String aid = null;
6947 try {
6948 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6949 .getApplicationByType(appType).getAid();
6950 } catch (Exception e) {
6951 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6952 }
6953 return aid;
6954 } finally {
6955 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006956 }
Youhan Wange64578a2016-05-02 15:32:42 -07006957 }
6958
Youhan Wang4001d252016-05-11 10:29:41 -07006959 /**
6960 * Return the Electronic Serial Number.
6961 *
6962 * @param subId the subscription ID that this request applies to.
6963 * @return ESN or null if error.
6964 */
6965 @Override
6966 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006967 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006968 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006969
6970 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006971 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006972 if (phone == null) {
6973 return null;
6974 }
6975 String esn = null;
6976 try {
6977 esn = phone.getEsn();
6978 } catch (Exception e) {
6979 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6980 }
6981 return esn;
6982 } finally {
6983 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006984 }
Youhan Wang4001d252016-05-11 10:29:41 -07006985 }
6986
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006987 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006988 * Return the Preferred Roaming List Version.
6989 *
6990 * @param subId the subscription ID that this request applies to.
6991 * @return PRLVersion or null if error.
6992 */
6993 @Override
6994 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006995 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006996 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006997
6998 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006999 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007000 if (phone == null) {
7001 return null;
7002 }
7003 String cdmaPrlVersion = null;
7004 try {
7005 cdmaPrlVersion = phone.getCdmaPrlVersion();
7006 } catch (Exception e) {
7007 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7008 }
7009 return cdmaPrlVersion;
7010 } finally {
7011 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007012 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007013 }
7014
7015 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007016 * Get snapshot of Telephony histograms
7017 * @return List of Telephony histograms
7018 * @hide
7019 */
7020 @Override
7021 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7023 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024
7025 final long identity = Binder.clearCallingIdentity();
7026 try {
7027 return RIL.getTelephonyRILTimingHistograms();
7028 } finally {
7029 Binder.restoreCallingIdentity(identity);
7030 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007031 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007032
7033 /**
7034 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007035 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7036 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007037 * Require system privileges. In the future we may add this to carrier APIs.
7038 *
Michele Berionne482f8202018-11-27 18:57:59 -08007039 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007040 */
7041 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007042 @TelephonyManager.SetCarrierRestrictionResult
7043 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007044 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007045 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007046
Michele Berionne482f8202018-11-27 18:57:59 -08007047 if (carrierRestrictionRules == null) {
7048 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007049 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 final long identity = Binder.clearCallingIdentity();
7052 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007053 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007054 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055 } finally {
7056 Binder.restoreCallingIdentity(identity);
7057 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007058 }
7059
7060 /**
7061 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007062 * Get the allowed carrier list and the excluded carrier list, including the priority between
7063 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007064 * Require system privileges. In the future we may add this to carrier APIs.
7065 *
Michele Berionne482f8202018-11-27 18:57:59 -08007066 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007067 */
7068 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007069 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007070 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007071 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072
7073 final long identity = Binder.clearCallingIdentity();
7074 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007075 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7076 if (response instanceof CarrierRestrictionRules) {
7077 return (CarrierRestrictionRules) response;
7078 }
7079 // Response is an Exception of some kind,
7080 // which is signalled to the user as a NULL retval
7081 return null;
7082 } catch (Exception e) {
7083 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7084 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007085 } finally {
7086 Binder.restoreCallingIdentity(identity);
7087 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007088 }
7089
fionaxu59545b42016-05-25 15:53:37 -07007090 /**
7091 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7092 * @param subId the subscription ID that this action applies to.
7093 * @param enabled control enable or disable metered apns.
7094 * {@hide}
7095 */
7096 @Override
7097 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7098 enforceModifyPermission();
7099 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100
7101 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007102 if (phone == null) {
7103 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7104 return;
7105 }
7106 try {
7107 phone.carrierActionSetMeteredApnsEnabled(enabled);
7108 } catch (Exception e) {
7109 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110 } finally {
7111 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007112 }
7113 }
7114
7115 /**
7116 * Action set from carrier signalling broadcast receivers to enable/disable radio
7117 * @param subId the subscription ID that this action applies to.
7118 * @param enabled control enable or disable radio.
7119 * {@hide}
7120 */
7121 @Override
7122 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7123 enforceModifyPermission();
7124 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007125
7126 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007127 if (phone == null) {
7128 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7129 return;
7130 }
7131 try {
7132 phone.carrierActionSetRadioEnabled(enabled);
7133 } catch (Exception e) {
7134 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007135 } finally {
7136 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007137 }
7138 }
7139
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007140 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007141 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7142 * network status based on which carrier apps could apply actions accordingly,
7143 * enable/disable default url handler for example.
7144 *
7145 * @param subId the subscription ID that this action applies to.
7146 * @param report control start/stop reporting the default network status.
7147 * {@hide}
7148 */
7149 @Override
7150 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7151 enforceModifyPermission();
7152 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007153
7154 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007155 if (phone == null) {
7156 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7157 return;
7158 }
7159 try {
7160 phone.carrierActionReportDefaultNetworkStatus(report);
7161 } catch (Exception e) {
7162 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163 } finally {
7164 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007165 }
7166 }
7167
7168 /**
fionaxud9622282017-07-17 17:51:30 -07007169 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7170 * @param subId the subscription ID that this action applies to.
7171 * {@hide}
7172 */
7173 @Override
7174 public void carrierActionResetAll(int subId) {
7175 enforceModifyPermission();
7176 final Phone phone = getPhone(subId);
7177 if (phone == null) {
7178 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7179 return;
7180 }
7181 try {
7182 phone.carrierActionResetAll();
7183 } catch (Exception e) {
7184 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7185 }
7186 }
7187
7188 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007189 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7190 * bug report is being generated.
7191 */
7192 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007193 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007194 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7195 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007196 writer.println("Permission Denial: can't dump Phone from pid="
7197 + Binder.getCallingPid()
7198 + ", uid=" + Binder.getCallingUid()
7199 + "without permission "
7200 + android.Manifest.permission.DUMP);
7201 return;
7202 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007203 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007204 }
Jack Yueb89b242016-06-22 13:27:47 -07007205
Brad Ebingerdac2f002018-04-03 15:17:52 -07007206 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007207 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7208 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7209 @NonNull String[] args) {
7210 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7211 this, in.getFileDescriptor(), out.getFileDescriptor(),
7212 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007213 }
7214
Jack Yueb89b242016-06-22 13:27:47 -07007215 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007216 * Policy control of data connection. Usually used when data limit is passed.
7217 * @param enabled True if enabling the data, otherwise disabling.
7218 * @param subId Subscription index
7219 * {@hide}
7220 */
7221 @Override
7222 public void setPolicyDataEnabled(boolean enabled, int subId) {
7223 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224
7225 final long identity = Binder.clearCallingIdentity();
7226 try {
7227 Phone phone = getPhone(subId);
7228 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007229 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230 }
7231 } finally {
7232 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007233 }
7234 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007235
7236 /**
7237 * Get Client request stats
7238 * @return List of Client Request Stats
7239 * @hide
7240 */
7241 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007242 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7243 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007244 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007245 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007246 return null;
7247 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007248 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250 final long identity = Binder.clearCallingIdentity();
7251 try {
7252 if (phone != null) {
7253 return phone.getClientRequestStats();
7254 }
7255
7256 return null;
7257 } finally {
7258 Binder.restoreCallingIdentity(identity);
7259 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007260 }
7261
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007262 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007263 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007264 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007265 }
Jack Yueb4124c2017-02-16 15:32:43 -08007266
7267 /**
Grace Chen70990072017-03-24 17:21:30 -07007268 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007269 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007270 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007271 * @param state State of SIM (power down, power up, pass through)
7272 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7273 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7274 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007275 *
7276 **/
7277 @Override
Grace Chen70990072017-03-24 17:21:30 -07007278 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007279 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007280 Phone phone = PhoneFactory.getPhone(slotIndex);
7281
vagdeviaf9a5b92018-08-15 16:01:53 -07007282 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007284 final long identity = Binder.clearCallingIdentity();
7285 try {
7286 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007287 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007288 }
7289 } finally {
7290 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007291 }
7292 }
Shuo Qiandd210312017-04-12 22:11:33 +00007293
Tyler Gunn65d45c22017-06-05 11:22:26 -07007294 private boolean isUssdApiAllowed(int subId) {
7295 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007296 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007297 if (configManager == null) {
7298 return false;
7299 }
7300 PersistableBundle pb = configManager.getConfigForSubId(subId);
7301 if (pb == null) {
7302 return false;
7303 }
7304 return pb.getBoolean(
7305 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7306 }
7307
Shuo Qiandd210312017-04-12 22:11:33 +00007308 /**
7309 * Check if phone is in emergency callback mode
7310 * @return true if phone is in emergency callback mode
7311 * @param subId sub id
7312 */
goneil9c5f4872017-12-05 14:07:56 -08007313 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007314 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007315 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007316 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007317
7318 final long identity = Binder.clearCallingIdentity();
7319 try {
7320 if (phone != null) {
7321 return phone.isInEcm();
7322 } else {
7323 return false;
7324 }
7325 } finally {
7326 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007327 }
7328 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007329
7330 /**
7331 * Get the current signal strength information for the given subscription.
7332 * Because this information is not updated when the device is in a low power state
7333 * it should not be relied-upon to be current.
7334 * @param subId Subscription index
7335 * @return the most recent cached signal strength info from the modem
7336 */
7337 @Override
7338 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007339 final long identity = Binder.clearCallingIdentity();
7340 try {
7341 Phone p = getPhone(subId);
7342 if (p == null) {
7343 return null;
7344 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007346 return p.getSignalStrength();
7347 } finally {
7348 Binder.restoreCallingIdentity(identity);
7349 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007350 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007351
Pengquan Meng77b7f132018-08-22 14:49:57 -07007352 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007353 * Get the current modem radio state for the given slot.
7354 * @param slotIndex slot index.
7355 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007356 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007357 * @return the current radio power state from the modem
7358 */
7359 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007360 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007361 Phone phone = PhoneFactory.getPhone(slotIndex);
7362 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007363 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7364 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007365 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7366 }
7367
7368 final long identity = Binder.clearCallingIdentity();
7369 try {
7370 return phone.getRadioPowerState();
7371 } finally {
7372 Binder.restoreCallingIdentity(identity);
7373 }
7374 }
7375 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7376 }
7377
7378 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007379 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7380 *
7381 * <p>Requires one of the following permissions:
7382 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7383 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7384 * privileges.
7385 *
7386 * @param subId subscription id
7387 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7388 * {@code false}.
7389 */
7390 @Override
7391 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007392 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7393 null /* message */);
7394
Pengquan Menga1bb6272018-09-06 09:59:22 -07007395 boolean isEnabled = false;
7396 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007397 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007398 Phone phone = getPhone(subId);
7399 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007400 } catch (Exception e) {
7401 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7402 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007403 } finally {
7404 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007405 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007406 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007407 }
7408
7409
7410 /**
7411 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7412 *
7413 * <p> Requires permission:
7414 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7415 * privileges.
7416 *
7417 * @param subId subscription id
7418 * @param isEnabled {@code true} means enable, {@code false} means disable.
7419 */
7420 @Override
7421 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7423 mApp, subId, "setDataRoamingEnabled");
7424
Pengquan Menga1bb6272018-09-06 09:59:22 -07007425 final long identity = Binder.clearCallingIdentity();
7426 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007427 Phone phone = getPhone(subId);
7428 if (phone != null) {
7429 phone.setDataRoamingEnabled(isEnabled);
7430 }
7431 } finally {
7432 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007433 }
7434 }
7435
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007436 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007437 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007438 TelephonyPermissions
7439 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007440 mApp, subId, "isManualNetworkSelectionAllowed");
7441
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007442 boolean isAllowed = true;
7443 final long identity = Binder.clearCallingIdentity();
7444 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007445 Phone phone = getPhone(subId);
7446 if (phone != null) {
7447 isAllowed = phone.isCspPlmnEnabled();
7448 }
7449 } finally {
7450 Binder.restoreCallingIdentity(identity);
7451 }
7452 return isAllowed;
7453 }
7454
7455 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007456 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007457 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007458 try {
7459 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007460 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007461 } catch (SecurityException e) {
7462 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7463 // has carrier privileges on an active UICC
7464 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7465 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007466 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007467 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007468 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007469
7470 final long identity = Binder.clearCallingIdentity();
7471 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007472 UiccController uiccController = UiccController.getInstance();
7473 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007474 if (hasReadPermission) {
7475 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007476 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007477
7478 // Remove private info if the caller doesn't have access
7479 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7480 for (UiccCardInfo cardInfo : cardInfos) {
7481 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7482 // is available
7483 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7484 if (card == null || card.getUiccProfile() == null) {
7485 // assume no access if the card or profile is unavailable
7486 filteredInfos.add(cardInfo.getUnprivileged());
7487 continue;
7488 }
7489 UiccProfile profile = card.getUiccProfile();
7490 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7491 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7492 filteredInfos.add(cardInfo);
7493 } else {
7494 filteredInfos.add(cardInfo.getUnprivileged());
7495 }
7496 }
7497 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007498 } finally {
7499 Binder.restoreCallingIdentity(identity);
7500 }
7501 }
7502
7503 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007504 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007505 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507 final long identity = Binder.clearCallingIdentity();
7508 try {
7509 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7510 if (slots == null) {
7511 Rlog.i(LOG_TAG, "slots is null.");
7512 return null;
7513 }
7514
7515 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7516 for (int i = 0; i < slots.length; i++) {
7517 UiccSlot slot = slots[i];
7518 if (slot == null) {
7519 continue;
7520 }
7521
Jordan Liu7be7e652019-05-06 18:55:02 +00007522 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 UiccCard card = slot.getUiccCard();
7524 if (card != null) {
7525 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007526 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007527 cardId = slot.getEid();
7528 if (TextUtils.isEmpty(cardId)) {
7529 cardId = slot.getIccId();
7530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 }
7532
Jordan Liu857451f2019-05-09 16:35:35 -07007533 if (cardId != null) {
7534 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7535 // if cardId is an EID, it's all digits so this is fine
7536 cardId = IccUtils.stripTrailingFs(cardId);
7537 }
7538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 int cardState = 0;
7540 switch (slot.getCardState()) {
7541 case CARDSTATE_ABSENT:
7542 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7543 break;
7544 case CARDSTATE_PRESENT:
7545 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7546 break;
7547 case CARDSTATE_ERROR:
7548 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7549 break;
7550 case CARDSTATE_RESTRICTED:
7551 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7552 break;
7553 default:
7554 break;
7555
7556 }
7557
7558 infos[i] = new UiccSlotInfo(
7559 slot.isActive(),
7560 slot.isEuicc(),
7561 cardId,
7562 cardState,
7563 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007564 slot.isExtendedApduSupported(),
7565 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 }
7567 return infos;
7568 } finally {
7569 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007570 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007571 }
7572
7573 @Override
7574 public boolean switchSlots(int[] physicalSlots) {
7575 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007576
7577 final long identity = Binder.clearCallingIdentity();
7578 try {
7579 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7580 } finally {
7581 Binder.restoreCallingIdentity(identity);
7582 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007583 }
Jack Yu4c988042018-02-27 15:30:01 -08007584
7585 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007586 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007587 final long identity = Binder.clearCallingIdentity();
7588 try {
7589 return UiccController.getInstance().getCardIdForDefaultEuicc();
7590 } finally {
7591 Binder.restoreCallingIdentity(identity);
7592 }
7593 }
7594
Pengquan Meng85728fb2018-03-12 16:31:21 -07007595 /**
goneil47ffb6e2018-04-06 15:40:58 -07007596 * A test API to reload the UICC profile.
7597 *
7598 * <p>Requires that the calling app has permission
7599 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7600 * @hide
7601 */
7602 @Override
7603 public void refreshUiccProfile(int subId) {
7604 enforceModifyPermission();
7605
7606 final long identity = Binder.clearCallingIdentity();
7607 try {
7608 Phone phone = getPhone(subId);
7609 if (phone == null) {
7610 return;
7611 }
7612 UiccCard uiccCard = phone.getUiccCard();
7613 if (uiccCard == null) {
7614 return;
7615 }
7616 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7617 if (uiccProfile == null) {
7618 return;
7619 }
7620 uiccProfile.refresh();
7621 } finally {
7622 Binder.restoreCallingIdentity(identity);
7623 }
7624 }
7625
7626 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007627 * Returns false if the mobile data is disabled by default, otherwise return true.
7628 */
7629 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007630 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007631 }
7632
7633 /**
7634 * Returns true if the data roaming is enabled by default, i.e the system property
7635 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7636 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7637 */
7638 private boolean getDefaultDataRoamingEnabled(int subId) {
7639 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007640 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007641 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007642 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7643 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7644 return isDataRoamingEnabled;
7645 }
7646
7647 /**
7648 * Returns the default network type for the given {@code subId}, if the default network type is
7649 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7650 */
7651 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007652 List<Integer> list = TelephonyProperties.default_network();
7653 int phoneId = mSubscriptionController.getPhoneId(subId);
7654 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7655 return list.get(phoneId);
7656 }
7657 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007658 }
fionaxua13278b2018-03-21 00:08:13 -07007659
7660 @Override
7661 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007662 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007663 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007664
7665 final long identity = Binder.clearCallingIdentity();
7666 try {
7667 final Phone phone = getPhone(subId);
7668 if (phone == null) {
7669 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7670 return;
7671 }
chen xueaba88a2019-03-15 13:15:10 -07007672 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7673 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674 } finally {
7675 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007676 }
fionaxua13278b2018-03-21 00:08:13 -07007677 }
7678
7679 @Override
7680 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007681 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007682
7683 final long identity = Binder.clearCallingIdentity();
7684 try {
7685 final Phone phone = getPhone(subId);
7686 if (phone == null) {
7687 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7688 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7689 }
7690 return phone.getCarrierIdListVersion();
7691 } finally {
7692 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007693 }
fionaxua13278b2018-03-21 00:08:13 -07007694 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007695
7696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007697 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7698 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007700 mApp, subId, callingPackage, callingFeatureId,
7701 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007702 return -1;
7703 }
7704
7705 final long identity = Binder.clearCallingIdentity();
7706 try {
7707 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7708 } finally {
7709 Binder.restoreCallingIdentity(identity);
7710 }
7711 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007712
7713 @Override
7714 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007715 TelephonyPermissions
7716 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007717 mApp, subId, "getCdmaRoamingMode");
7718
7719 final long identity = Binder.clearCallingIdentity();
7720 try {
7721 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7722 } finally {
7723 Binder.restoreCallingIdentity(identity);
7724 }
7725 }
7726
7727 @Override
7728 public boolean setCdmaRoamingMode(int subId, int mode) {
7729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7730 mApp, subId, "setCdmaRoamingMode");
7731
7732 final long identity = Binder.clearCallingIdentity();
7733 try {
7734 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7735 } finally {
7736 Binder.restoreCallingIdentity(identity);
7737 }
7738 }
7739
7740 @Override
7741 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7743 mApp, subId, "setCdmaSubscriptionMode");
7744
7745 final long identity = Binder.clearCallingIdentity();
7746 try {
7747 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7748 } finally {
7749 Binder.restoreCallingIdentity(identity);
7750 }
7751 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007752
sqianc5eccab2018-10-19 18:46:41 -07007753 @Override
sqian8c685422019-02-22 15:55:18 -08007754 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007755 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007757 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7758 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007759 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7760 }
7761 final long identity = Binder.clearCallingIdentity();
7762 try {
sqian854d44b2018-12-12 16:48:18 -08007763 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7764 for (Phone phone: PhoneFactory.getPhones()) {
7765 if (phone.getEmergencyNumberTracker() != null
7766 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7767 emergencyNumberListInternal.put(
7768 phone.getSubId(),
7769 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7770 }
sqian11b7a0e2018-12-05 18:48:28 -08007771 }
sqian854d44b2018-12-12 16:48:18 -08007772 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007773 } finally {
7774 Binder.restoreCallingIdentity(identity);
7775 }
sqianc5eccab2018-10-19 18:46:41 -07007776 }
7777
7778 @Override
sqian8c685422019-02-22 15:55:18 -08007779 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007780 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007781 if (!exactMatch) {
7782 TelephonyPermissions
7783 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007784 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007785 }
7786 final long identity = Binder.clearCallingIdentity();
7787 try {
sqian854d44b2018-12-12 16:48:18 -08007788 for (Phone phone: PhoneFactory.getPhones()) {
7789 if (phone.getEmergencyNumberTracker() != null
7790 && phone.getEmergencyNumberTracker() != null) {
7791 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7792 number, exactMatch)) {
7793 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007794 }
7795 }
sqian11b7a0e2018-12-05 18:48:28 -08007796 }
7797 return false;
7798 } finally {
7799 Binder.restoreCallingIdentity(identity);
7800 }
7801 }
7802
sqianf4ca7ed2019-01-15 18:32:07 -08007803 /**
7804 * Update emergency number list for test mode.
7805 */
7806 @Override
7807 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7808 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7809 "updateEmergencyNumberListTestMode");
7810
7811 final long identity = Binder.clearCallingIdentity();
7812 try {
7813 for (Phone phone: PhoneFactory.getPhones()) {
7814 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7815 if (tracker != null) {
7816 tracker.executeEmergencyNumberTestModeCommand(action, num);
7817 }
7818 }
7819 } finally {
7820 Binder.restoreCallingIdentity(identity);
7821 }
7822 }
7823
7824 /**
7825 * Get the full emergency number list for test mode.
7826 */
7827 @Override
7828 public List<String> getEmergencyNumberListTestMode() {
7829 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7830 "getEmergencyNumberListTestMode");
7831
7832 final long identity = Binder.clearCallingIdentity();
7833 try {
7834 Set<String> emergencyNumbers = new HashSet<>();
7835 for (Phone phone: PhoneFactory.getPhones()) {
7836 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7837 if (tracker != null) {
7838 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7839 emergencyNumbers.add(num.getNumber());
7840 }
7841 }
7842 }
7843 return new ArrayList<>(emergencyNumbers);
7844 } finally {
7845 Binder.restoreCallingIdentity(identity);
7846 }
7847 }
7848
chen xud6b45bd2018-10-30 22:27:10 -07007849 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007850 public int getEmergencyNumberDbVersion(int subId) {
7851 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7852
7853 final long identity = Binder.clearCallingIdentity();
7854 try {
7855 final Phone phone = getPhone(subId);
7856 if (phone == null) {
7857 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7858 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7859 }
7860 return phone.getEmergencyNumberDbVersion();
7861 } finally {
7862 Binder.restoreCallingIdentity(identity);
7863 }
7864 }
7865
7866 @Override
7867 public void notifyOtaEmergencyNumberDbInstalled() {
7868 enforceModifyPermission();
7869
7870 final long identity = Binder.clearCallingIdentity();
7871 try {
7872 for (Phone phone: PhoneFactory.getPhones()) {
7873 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7874 if (tracker != null) {
7875 tracker.updateOtaEmergencyNumberDatabase();
7876 }
7877 }
7878 } finally {
7879 Binder.restoreCallingIdentity(identity);
7880 }
7881 }
7882
7883 @Override
7884 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7885 enforceActiveEmergencySessionPermission();
7886
7887 final long identity = Binder.clearCallingIdentity();
7888 try {
7889 for (Phone phone: PhoneFactory.getPhones()) {
7890 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7891 if (tracker != null) {
7892 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7893 }
7894 }
7895 } finally {
7896 Binder.restoreCallingIdentity(identity);
7897 }
7898 }
7899
7900 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007901 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7902 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7903 Phone phone = getPhone(subId);
7904 if (phone == null) {
7905 return null;
7906 }
7907 final long identity = Binder.clearCallingIdentity();
7908 try {
7909 UiccProfile profile = UiccController.getInstance()
7910 .getUiccProfileForPhone(phone.getPhoneId());
7911 if (profile != null) {
7912 return profile.getCertsFromCarrierPrivilegeAccessRules();
7913 }
7914 } finally {
7915 Binder.restoreCallingIdentity(identity);
7916 }
7917 return null;
7918 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007919
7920 /**
7921 * Enable or disable a modem stack.
7922 */
7923 @Override
7924 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7925 enforceModifyPermission();
7926
7927 final long identity = Binder.clearCallingIdentity();
7928 try {
7929 Phone phone = PhoneFactory.getPhone(slotIndex);
7930 if (phone == null) {
7931 return false;
7932 } else {
7933 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7934 }
7935 } finally {
7936 Binder.restoreCallingIdentity(identity);
7937 }
7938 }
Michelecea4cf22018-12-21 15:00:11 -08007939
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007940 /**
7941 * Whether a modem stack is enabled or not.
7942 */
7943 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007944 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7945 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007946 Phone phone = PhoneFactory.getPhone(slotIndex);
7947 if (phone == null) return false;
7948
7949 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007950 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7951 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007952 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7953 }
7954
7955 final long identity = Binder.clearCallingIdentity();
7956 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007957 try {
7958 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7959 } catch (NoSuchElementException ex) {
7960 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7961 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007962 } finally {
7963 Binder.restoreCallingIdentity(identity);
7964 }
7965 }
7966
Michelecea4cf22018-12-21 15:00:11 -08007967 @Override
Michele0ea7d782019-03-19 14:58:42 -07007968 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007969 enforceModifyPermission();
7970
7971 final long identity = Binder.clearCallingIdentity();
7972 try {
7973 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007974 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007975 .commit();
7976 } finally {
7977 Binder.restoreCallingIdentity(identity);
7978 }
7979 }
7980
7981 @Override
Michele0ea7d782019-03-19 14:58:42 -07007982 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007983 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007984 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007985 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7986 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007987 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007988 }
Michelecea4cf22018-12-21 15:00:11 -08007989
7990 final long identity = Binder.clearCallingIdentity();
7991 try {
Michele0ea7d782019-03-19 14:58:42 -07007992 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007993 } finally {
7994 Binder.restoreCallingIdentity(identity);
7995 }
7996 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007997
Michele0ea7d782019-03-19 14:58:42 -07007998 @TelephonyManager.IsMultiSimSupportedResult
7999 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008000 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8001 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8002 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008003 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8004 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008005 }
8006 // Check if the hardware supports multisim functionality. If usage of multisim is not
8007 // supported by the modem, indicate that it is restricted.
8008 PhoneCapability staticCapability =
8009 mPhoneConfigurationManager.getStaticPhoneCapability();
8010 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008011 loge("isMultiSimSupportedInternal: no static configuration available");
8012 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008013 }
Sarah Chin7caee492020-02-18 20:49:02 +00008014 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008015 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8016 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008017 }
8018 // Check if support of multiple SIMs is restricted by carrier
8019 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008020 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008021 }
8022
Michele0ea7d782019-03-19 14:58:42 -07008023 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008024 }
8025
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008026 /**
8027 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008028 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8029 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8030 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008031 * @param numOfSims number of active sims we want to switch to
8032 */
8033 @Override
8034 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008035 if (numOfSims == 1) {
8036 enforceModifyPermission();
8037 } else {
8038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8039 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8040 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008041 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008042
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008043 try {
Michele30b57b22019-03-01 12:01:14 -08008044 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008045 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008046 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8047 return;
8048 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008049 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8050 } finally {
8051 Binder.restoreCallingIdentity(identity);
8052 }
8053 }
8054
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008055 @Override
8056 public boolean isApplicationOnUicc(int subId, int appType) {
8057 enforceReadPrivilegedPermission("isApplicationOnUicc");
8058 Phone phone = getPhone(subId);
8059 if (phone == null) {
8060 return false;
8061 }
8062 final long identity = Binder.clearCallingIdentity();
8063 try {
8064 UiccCard uiccCard = phone.getUiccCard();
8065 if (uiccCard == null) {
8066 return false;
8067 }
8068 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8069 if (uiccProfile == null) {
8070 return false;
8071 }
8072 if (TelephonyManager.APPTYPE_SIM <= appType
8073 && appType <= TelephonyManager.APPTYPE_ISIM) {
8074 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8075 }
8076 return false;
8077 } finally {
8078 Binder.restoreCallingIdentity(identity);
8079 }
8080 }
8081
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008082 /**
chen xub4baa772019-04-03 10:23:41 -07008083 * Get whether making changes to modem configurations will trigger reboot.
8084 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008085 */
8086 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008087 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8088 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008089 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008090 mApp, subId, callingPackage, callingFeatureId,
8091 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008092 return false;
8093 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008094 final long identity = Binder.clearCallingIdentity();
8095 try {
8096 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8097 } finally {
8098 Binder.restoreCallingIdentity(identity);
8099 }
8100 }
8101
Nathan Harold29f5f052019-02-15 13:41:57 -08008102 private void updateModemStateMetrics() {
8103 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8104 // TODO: check the state for each modem if the api is ready.
8105 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8106 }
8107
Pengquan Meng3889a572019-01-23 11:16:29 -08008108 @Override
8109 public int[] getSlotsMapping() {
8110 enforceReadPrivilegedPermission("getSlotsMapping");
8111
8112 final long identity = Binder.clearCallingIdentity();
8113 try {
8114 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8115 // All logical slots should have a mapping to a physical slot.
8116 int[] logicalSlotsMapping = new int[phoneCount];
8117 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8118 for (int i = 0; i < slotInfos.length; i++) {
8119 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8120 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8121 }
8122 }
8123 return logicalSlotsMapping;
8124 } finally {
8125 Binder.restoreCallingIdentity(identity);
8126 }
8127 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008128
8129 /**
8130 * Get the IRadio HAL Version
8131 */
8132 @Override
8133 public int getRadioHalVersion() {
8134 Phone phone = getDefaultPhone();
8135 if (phone == null) return -1;
8136 HalVersion hv = phone.getHalVersion();
8137 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8138 return hv.major * 100 + hv.minor;
8139 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008140
8141 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008142 * Get the current calling package name.
8143 * @return the current calling package name
8144 */
8145 @Override
8146 public String getCurrentPackageName() {
8147 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8148 }
8149
8150 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008151 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8152 * corresponding network requests on a subId.
8153 *
8154 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008155 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008156 * 2) APN is un-metered for this subscription, or
8157 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008158 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008159 *
8160 * @return whether data is allowed for a apn type.
8161 *
8162 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008163 */
8164 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008165 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008166 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8167 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008168
8169 // Now that all security checks passes, perform the operation as ourselves.
8170 final long identity = Binder.clearCallingIdentity();
8171 try {
8172 Phone phone = getPhone(subId);
8173 if (phone == null) return false;
8174
Jack Yu41407ee2019-05-13 16:54:09 -07008175 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008176 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8177 } finally {
8178 Binder.restoreCallingIdentity(identity);
8179 }
8180 }
8181
8182 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008183 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008184 enforceReadPrivilegedPermission("isApnMetered");
8185
8186 // Now that all security checks passes, perform the operation as ourselves.
8187 final long identity = Binder.clearCallingIdentity();
8188 try {
8189 Phone phone = getPhone(subId);
8190 if (phone == null) return true; // By default return true.
8191
Jack Yu41407ee2019-05-13 16:54:09 -07008192 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008193 } finally {
8194 Binder.restoreCallingIdentity(identity);
8195 }
8196 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008197
8198 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008199 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8200 int subscriptionId, IBooleanConsumer resultCallback) {
8201 enforceModifyPermission();
8202 long token = Binder.clearCallingIdentity();
8203 try {
8204 Phone phone = getPhone(subscriptionId);
8205 if (phone == null) {
8206 try {
8207 if (resultCallback != null) {
8208 resultCallback.accept(false);
8209 }
8210 } catch (RemoteException e) {
8211 // ignore
8212 }
8213 return;
8214 }
8215 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8216 Pair.create(specifiers, (x) -> {
8217 try {
8218 if (resultCallback != null) {
8219 resultCallback.accept(x);
8220 }
8221 } catch (RemoteException e) {
8222 // ignore
8223 }
8224 });
8225 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8226 } finally {
8227 Binder.restoreCallingIdentity(token);
8228 }
8229 }
8230
8231 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008232 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8233 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8234 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8235 if (iccRecords == null) {
8236 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8237 return false;
8238 }
8239 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8240 }
8241
8242 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008243 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008244 if (callingPackage == null) {
8245 callingPackage = getCurrentPackageName();
8246 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008247 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8248 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8249 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8250 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8251 }
8252 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8253 Intent intent = new Intent();
8254 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8255 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8256 // Bring up choose default SMS subscription dialog right now
8257 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8258 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8259 mApp.startActivity(intent);
8260 }
chen xud5ca2d52019-05-28 15:20:57 -07008261
8262 @Override
8263 public String getMmsUAProfUrl(int subId) {
8264 //TODO investigate if this API should require proper permission check in R b/133791609
8265 final long identity = Binder.clearCallingIdentity();
8266 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008267 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8268 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008269 } finally {
8270 Binder.restoreCallingIdentity(identity);
8271 }
8272 }
8273
8274 @Override
8275 public String getMmsUserAgent(int subId) {
8276 //TODO investigate if this API should require proper permission check in R b/133791609
8277 final long identity = Binder.clearCallingIdentity();
8278 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008279 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8280 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008281 } finally {
8282 Binder.restoreCallingIdentity(identity);
8283 }
8284 }
Jack Yub07d4972019-05-28 16:12:25 -07008285
8286 @Override
8287 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8288 enforceModifyPermission();
8289
8290 // Now that all security checks passes, perform the operation as ourselves.
8291 final long identity = Binder.clearCallingIdentity();
8292 try {
8293 Phone phone = getPhone(subId);
8294 if (phone == null) return false;
8295
8296 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8297 } finally {
8298 Binder.restoreCallingIdentity(identity);
8299 }
8300 }
8301
8302 @Override
8303 public boolean isDataAllowedInVoiceCall(int subId) {
8304 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8305
8306 // Now that all security checks passes, perform the operation as ourselves.
8307 final long identity = Binder.clearCallingIdentity();
8308 try {
8309 Phone phone = getPhone(subId);
8310 if (phone == null) return false;
8311
8312 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8313 } finally {
8314 Binder.restoreCallingIdentity(identity);
8315 }
8316 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008317
changbettyd5c246e2019-12-24 15:40:37 +08008318 @Override
8319 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8320 enforceModifyPermission();
8321
8322 // Now that all security checks passes, perform the operation as ourselves.
8323 final long identity = Binder.clearCallingIdentity();
8324 try {
8325 Phone phone = getPhone(subId);
8326 if (phone == null) return false;
8327
8328 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8329 } finally {
8330 Binder.restoreCallingIdentity(identity);
8331 }
8332 }
8333
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008334 /**
8335 * Updates whether conference event pacakge handling is enabled.
8336 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8337 * otherwise.
8338 */
8339 @Override
8340 public void setCepEnabled(boolean isCepEnabled) {
8341 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8342
8343 final long identity = Binder.clearCallingIdentity();
8344 try {
8345 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8346 for (Phone phone : PhoneFactory.getPhones()) {
8347 Phone defaultPhone = phone.getImsPhone();
8348 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8349 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8350 ImsPhoneCallTracker imsPhoneCallTracker =
8351 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8352 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8353 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8354 + imsPhone.getMsisdn());
8355 }
8356 }
8357 } finally {
8358 Binder.restoreCallingIdentity(identity);
8359 }
8360 }
allenwtsu46dcc572020-01-08 18:24:03 +08008361
8362 /**
8363 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8364 *
8365 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8366 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8367 * before being read.
8368 */
8369 @Override
8370 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8371 isCompressed) {
8372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8373 mApp, subId, "notifyRcsAutoConfigurationReceived");
8374 try {
8375 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8376 if (configBinder == null) {
8377 Rlog.e(LOG_TAG, "null result for getImsConfig");
8378 } else {
8379 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8380 }
8381 } catch (RemoteException e) {
8382 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8383 }
8384 }
zoey chene02881a2019-12-30 16:11:23 +08008385
8386 @Override
8387 public boolean isIccLockEnabled(int subId) {
8388 enforceReadPrivilegedPermission("isIccLockEnabled");
8389
8390 // Now that all security checks passes, perform the operation as ourselves.
8391 final long identity = Binder.clearCallingIdentity();
8392 try {
8393 Phone phone = getPhone(subId);
8394 if (phone != null && phone.getIccCard() != null) {
8395 return phone.getIccCard().getIccLockEnabled();
8396 } else {
8397 return false;
8398 }
8399 } finally {
8400 Binder.restoreCallingIdentity(identity);
8401 }
8402 }
8403
8404 /**
8405 * Set the ICC pin lock enabled or disabled.
8406 *
8407 * @return an integer representing the status of IccLock enabled or disabled in the following
8408 * three cases:
8409 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8410 * successfully.
8411 * - Positive number and zero for remaining password attempts.
8412 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8413 *
8414 */
8415 @Override
8416 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8417 enforceModifyPermission();
8418
8419 Phone phone = getPhone(subId);
8420 if (phone == null) {
8421 return 0;
8422 }
8423 // Now that all security checks passes, perform the operation as ourselves.
8424 final long identity = Binder.clearCallingIdentity();
8425 try {
8426 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8427 new Pair<Boolean, String>(enabled, password), phone, null);
8428 return attemptsRemaining;
8429
8430 } catch (Exception e) {
8431 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8432 } finally {
8433 Binder.restoreCallingIdentity(identity);
8434 }
8435 return 0;
8436 }
8437
8438 /**
8439 * Change the ICC password used in ICC pin lock.
8440 *
8441 * @return an integer representing the status of IccLock changed in the following three cases:
8442 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8443 * - Positive number and zero for remaining password attempts.
8444 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8445 *
8446 */
8447 @Override
8448 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8449 enforceModifyPermission();
8450
8451 Phone phone = getPhone(subId);
8452 if (phone == null) {
8453 return 0;
8454 }
8455 // Now that all security checks passes, perform the operation as ourselves.
8456 final long identity = Binder.clearCallingIdentity();
8457 try {
8458 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8459 new Pair<String, String>(oldPassword, newPassword), phone, null);
8460 return attemptsRemaining;
8461
8462 } catch (Exception e) {
8463 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8464 } finally {
8465 Binder.restoreCallingIdentity(identity);
8466 }
8467 return 0;
8468 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008469
8470 /**
8471 * Request for receiving user activity notification
8472 */
8473 @Override
8474 public void requestUserActivityNotification() {
8475 if (!mNotifyUserActivity.get()
8476 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8477 mNotifyUserActivity.set(true);
8478 }
8479 }
8480
8481 /**
8482 * Called when userActivity is signalled in the power manager.
8483 * This is safe to call from any thread, with any window manager locks held or not.
8484 */
8485 @Override
8486 public void userActivity() {
8487 // ***************************************
8488 // * Inherited from PhoneWindowManager *
8489 // ***************************************
8490 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8491 // WITH ITS LOCKS HELD.
8492 //
8493 // This code must be VERY careful about the locks
8494 // it acquires.
8495 // In fact, the current code acquires way too many,
8496 // and probably has lurking deadlocks.
8497
8498 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8499 throw new SecurityException("Only the OS may call notifyUserActivity()");
8500 }
8501
8502 if (mNotifyUserActivity.getAndSet(false)) {
8503 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8504 USER_ACTIVITY_NOTIFICATION_DELAY);
8505 }
8506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008507}