blob: 8d360f639484ef77dec1f318c0818cfd40160daf [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -080067import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800123import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800130import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800132import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800133import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700134import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800135import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800137import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700138import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700139import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700140import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700142import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800143import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700144import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700145import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700146import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700147import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700148import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700149import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700150import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700151import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800152import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800153import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800154import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700155import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800156import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700157import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800158import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700159import com.android.internal.telephony.imsphone.ImsPhone;
160import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800161import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700162import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800164import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700167import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800168import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800170import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000171import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800172import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700173import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800174import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700175import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700176import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800177import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700178import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700179import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800180import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800181
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700182import java.io.FileDescriptor;
183import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800185import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800186import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800188import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100189import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800190import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700191import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800192import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800193import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800194import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195
196/**
197 * Implementation of the ITelephony interface.
198 */
Santos Cordon117fee72014-05-16 17:56:12 -0700199public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200 private static final String LOG_TAG = "PhoneInterfaceManager";
201 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
202 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800203 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204
205 // Message codes used with mMainThreadHandler
206 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700207 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
208 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700209 private static final int CMD_OPEN_CHANNEL = 9;
210 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
211 private static final int CMD_CLOSE_CHANNEL = 11;
212 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800213 private static final int CMD_NV_READ_ITEM = 13;
214 private static final int EVENT_NV_READ_ITEM_DONE = 14;
215 private static final int CMD_NV_WRITE_ITEM = 15;
216 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
217 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
218 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700219 private static final int CMD_RESET_MODEM_CONFIG = 19;
220 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800221 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
222 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
223 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
224 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800225 private static final int CMD_SEND_ENVELOPE = 25;
226 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000227 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
228 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700229 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
230 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
231 private static final int CMD_EXCHANGE_SIM_IO = 31;
232 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800233 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
234 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700235 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
236 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700237 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
238 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700239 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
240 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
241 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
242 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700243 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
244 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
245 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
246 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700247 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800248 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
249 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000250 private static final int CMD_SWITCH_SLOTS = 50;
251 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700252 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
253 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
254 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
255 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
256 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
257 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
258 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
259 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700260 private static final int CMD_GET_ALL_CELL_INFO = 60;
261 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
262 private static final int CMD_GET_CELL_LOCATION = 62;
263 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700264 private static final int CMD_MODEM_REBOOT = 64;
265 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700266 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
267 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800268 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
269 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700270 private static final int CMD_GET_MODEM_STATUS = 70;
271 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700272 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
273 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700274 private static final int CMD_ERASE_MODEM_CONFIG = 74;
275 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800276 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
277 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
278 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
279 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800280 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
281 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800282 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800283 private static final int CMD_GET_CALL_FORWARDING = 83;
284 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
285 private static final int CMD_SET_CALL_FORWARDING = 85;
286 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
287 private static final int CMD_GET_CALL_WAITING = 87;
288 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
289 private static final int CMD_SET_CALL_WAITING = 89;
290 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800292 // Parameters of select command.
293 private static final int SELECT_COMMAND = 0xA4;
294 private static final int SELECT_P1 = 0x04;
295 private static final int SELECT_P2 = 0;
296 private static final int SELECT_P3 = 0x10;
297
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298 /** The singleton instance. */
299 private static PhoneInterfaceManager sInstance;
300
Wink Saville3ab207e2014-11-20 13:07:20 -0800301 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800302 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800303 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700304 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800305 private AppOpsManager mAppOps;
306 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800307 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800308 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700309 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310
Peter Wangdafb9ac2020-01-15 14:13:38 -0800311 /** User Activity */
312 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800313 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
314
Derek Tan97ebb422014-09-05 16:55:38 -0700315 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
316 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800317 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800318 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700319
Michelecea4cf22018-12-21 15:00:11 -0800320 // String to store multi SIM allowed
321 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
322
Derek Tan740e1672017-06-27 14:56:27 -0700323 // The AID of ISD-R.
324 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
325
yinxub1bed742017-04-17 11:45:04 -0700326 private NetworkScanRequestTracker mNetworkScanRequestTracker;
327
David Kelly5e06a7f2018-03-12 14:10:59 +0000328 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
329 private static final int MANUFACTURER_CODE_LENGTH = 8;
330
Derek Tan89e89d42014-07-08 17:00:10 -0700331 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700332 * Experiment flag to enable erase modem config on reset network, default value is false
333 */
334 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
335 "reset_network_erase_modem_config_enabled";
336
337 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700338 * A request object to use for transmitting data to an ICC.
339 */
340 private static final class IccAPDUArgument {
341 public int channel, cla, command, p1, p2, p3;
342 public String data;
343
344 public IccAPDUArgument(int channel, int cla, int command,
345 int p1, int p2, int p3, String data) {
346 this.channel = channel;
347 this.cla = cla;
348 this.command = command;
349 this.p1 = p1;
350 this.p2 = p2;
351 this.p3 = p3;
352 this.data = data;
353 }
354 }
355
356 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700357 * A request object to use for transmitting data to an ICC.
358 */
359 private static final class ManualNetworkSelectionArgument {
360 public OperatorInfo operatorInfo;
361 public boolean persistSelection;
362
363 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
364 this.operatorInfo = operatorInfo;
365 this.persistSelection = persistSelection;
366 }
367 }
368
369 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
371 * request after sending. The main thread will notify the request when it is complete.
372 */
373 private static final class MainThreadRequest {
374 /** The argument to use for the request */
375 public Object argument;
376 /** The result of the request that is run on the main thread */
377 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800378 // The subscriber id that this request applies to. Defaults to
379 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
380 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381
Nathan Harold92bed182018-10-12 18:16:49 -0700382 // In cases where subId is unavailable, the caller needs to specify the phone.
383 public Phone phone;
384
vagdeviaf9a5b92018-08-15 16:01:53 -0700385 public WorkSource workSource;
386
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 public MainThreadRequest(Object argument) {
388 this.argument = argument;
389 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800390
Nathan Harold92bed182018-10-12 18:16:49 -0700391 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
392 this.argument = argument;
393 if (phone != null) {
394 this.phone = phone;
395 }
396 this.workSource = workSource;
397 }
398
vagdeviaf9a5b92018-08-15 16:01:53 -0700399 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800400 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800401 if (subId != null) {
402 this.subId = subId;
403 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700404 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 }
407
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800408 private static final class IncomingThirdPartyCallArgs {
409 public final ComponentName component;
410 public final String callId;
411 public final String callerDisplayName;
412
413 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
414 String callerDisplayName) {
415 this.component = component;
416 this.callId = callId;
417 this.callerDisplayName = callerDisplayName;
418 }
419 }
420
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421 /**
422 * A handler that processes messages on the main thread in the phone process. Since many
423 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
424 * inbound binder threads to the main thread in the phone process. The Binder thread
425 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
426 * on, which will be notified when the operation completes and will contain the result of the
427 * request.
428 *
429 * <p>If a MainThreadRequest object is provided in the msg.obj field,
430 * note that request.result must be set to something non-null for the calling thread to
431 * unblock.
432 */
433 private final class MainThreadHandler extends Handler {
434 @Override
435 public void handleMessage(Message msg) {
436 MainThreadRequest request;
437 Message onCompleted;
438 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800439 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800441 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442
443 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700444 case CMD_HANDLE_USSD_REQUEST: {
445 request = (MainThreadRequest) msg.obj;
446 final Phone phone = getPhoneFromRequest(request);
447 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
448 String ussdRequest = ussdObject.first;
449 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700450
Pengquan Menga1bb6272018-09-06 09:59:22 -0700451 if (!isUssdApiAllowed(request.subId)) {
452 // Carrier does not support use of this API, return failure.
453 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
454 UssdResponse response = new UssdResponse(ussdRequest, null);
455 Bundle returnData = new Bundle();
456 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
457 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700458
Pengquan Menga1bb6272018-09-06 09:59:22 -0700459 request.result = true;
460 notifyRequester(request);
461 return;
462 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700463
Pengquan Menga1bb6272018-09-06 09:59:22 -0700464 try {
465 request.result = phone != null
466 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
467 } catch (CallStateException cse) {
468 request.result = false;
469 }
470 // Wake up the requesting thread
471 notifyRequester(request);
472 break;
pkanwar32d516d2016-10-14 19:37:38 -0700473 }
474
Yorke Lee716f67e2015-06-17 15:39:16 -0700475 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700476 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700477 final Phone phone = getPhoneFromRequest(request);
478 request.result = phone != null ?
479 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
480 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700482 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700487 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700490 if (uiccCard == null) {
491 loge("iccTransmitApduLogicalChannel: No UICC");
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700494 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
496 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700497 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 iccArgument.channel, iccArgument.cla, iccArgument.command,
499 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700500 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700501 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700502 break;
503
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700504 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 ar = (AsyncResult) msg.obj;
506 request = (MainThreadRequest) ar.userObj;
507 if (ar.exception == null && ar.result != null) {
508 request.result = ar.result;
509 } else {
510 request.result = new IccIoResult(0x6F, 0, (byte[])null);
511 if (ar.result == null) {
512 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800513 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700514 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800515 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700516 } else {
517 loge("iccTransmitApduLogicalChannel: Unknown exception");
518 }
519 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700520 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700521 break;
522
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
524 request = (MainThreadRequest) msg.obj;
525 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800526 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 if (uiccCard == null) {
528 loge("iccTransmitApduBasicChannel: No UICC");
529 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 } else {
532 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
533 request);
534 uiccCard.iccTransmitApduBasicChannel(
535 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
536 iccArgument.p3, iccArgument.data, onCompleted);
537 }
538 break;
539
540 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
541 ar = (AsyncResult) msg.obj;
542 request = (MainThreadRequest) ar.userObj;
543 if (ar.exception == null && ar.result != null) {
544 request.result = ar.result;
545 } else {
546 request.result = new IccIoResult(0x6F, 0, (byte[])null);
547 if (ar.result == null) {
548 loge("iccTransmitApduBasicChannel: Empty response");
549 } else if (ar.exception instanceof CommandException) {
550 loge("iccTransmitApduBasicChannel: CommandException: " +
551 ar.exception);
552 } else {
553 loge("iccTransmitApduBasicChannel: Unknown exception");
554 }
555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 break;
558
559 case CMD_EXCHANGE_SIM_IO:
560 request = (MainThreadRequest) msg.obj;
561 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800562 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 if (uiccCard == null) {
564 loge("iccExchangeSimIO: No UICC");
565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 } else {
568 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
569 request);
570 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
571 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
572 iccArgument.data, onCompleted);
573 }
574 break;
575
576 case EVENT_EXCHANGE_SIM_IO_DONE:
577 ar = (AsyncResult) msg.obj;
578 request = (MainThreadRequest) ar.userObj;
579 if (ar.exception == null && ar.result != null) {
580 request.result = ar.result;
581 } else {
582 request.result = new IccIoResult(0x6f, 0, (byte[])null);
583 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 break;
586
Derek Tan4d5e5c12014-02-04 11:54:58 -0800587 case CMD_SEND_ENVELOPE:
588 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800589 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 if (uiccCard == null) {
591 loge("sendEnvelopeWithStatus: No UICC");
592 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 } else {
595 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
596 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
597 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800598 break;
599
600 case EVENT_SEND_ENVELOPE_DONE:
601 ar = (AsyncResult) msg.obj;
602 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700603 if (ar.exception == null && ar.result != null) {
604 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800605 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700606 request.result = new IccIoResult(0x6F, 0, (byte[])null);
607 if (ar.result == null) {
608 loge("sendEnvelopeWithStatus: Empty response");
609 } else if (ar.exception instanceof CommandException) {
610 loge("sendEnvelopeWithStatus: CommandException: " +
611 ar.exception);
612 } else {
613 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
614 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800615 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800617 break;
618
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 case CMD_OPEN_CHANNEL:
620 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800621 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800622 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700623 if (uiccCard == null) {
624 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800625 request.result = new IccOpenLogicalChannelResponse(-1,
626 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700628 } else {
629 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800630 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
631 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700632 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 break;
634
635 case EVENT_OPEN_CHANNEL_DONE:
636 ar = (AsyncResult) msg.obj;
637 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 int[] result = (int[]) ar.result;
641 int channelId = result[0];
642 byte[] selectResponse = null;
643 if (result.length > 1) {
644 selectResponse = new byte[result.length - 1];
645 for (int i = 1; i < result.length; ++i) {
646 selectResponse[i - 1] = (byte) result[i];
647 }
648 }
649 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700650 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 if (ar.result == null) {
653 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 if (ar.exception != null) {
656 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
657 }
658
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700659 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700660 if (ar.exception instanceof CommandException) {
661 CommandException.Error error =
662 ((CommandException) (ar.exception)).getCommandError();
663 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700664 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700665 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700666 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 }
668 }
669 openChannelResp = new IccOpenLogicalChannelResponse(
670 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700672 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700673 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 break;
675
676 case CMD_CLOSE_CHANNEL:
677 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800678 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700679 if (uiccCard == null) {
680 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900681 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700682 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700683 } else {
684 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
685 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
686 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 break;
688
689 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800690 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
691 break;
692
693 case CMD_NV_READ_ITEM:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800696 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
697 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
700 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 ar = (AsyncResult) msg.obj;
702 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800703 if (ar.exception == null && ar.result != null) {
704 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800706 request.result = "";
707 if (ar.result == null) {
708 loge("nvReadItem: Empty response");
709 } else if (ar.exception instanceof CommandException) {
710 loge("nvReadItem: CommandException: " +
711 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800713 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 }
715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 break;
718
Jake Hambye994d462014-02-03 13:10:13 -0800719 case CMD_NV_WRITE_ITEM:
720 request = (MainThreadRequest) msg.obj;
721 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
722 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800723 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700724 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800725 break;
726
727 case EVENT_NV_WRITE_ITEM_DONE:
728 handleNullReturnEvent(msg, "nvWriteItem");
729 break;
730
731 case CMD_NV_WRITE_CDMA_PRL:
732 request = (MainThreadRequest) msg.obj;
733 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800734 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800735 break;
736
737 case EVENT_NV_WRITE_CDMA_PRL_DONE:
738 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
739 break;
740
chen xu6dac5ab2018-10-26 17:39:23 -0700741 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800742 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700743 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800744 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800745 break;
746
chen xu6dac5ab2018-10-26 17:39:23 -0700747 case EVENT_RESET_MODEM_CONFIG_DONE:
748 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800749 break;
750
Jake Hamby7c27be32014-03-03 13:25:59 -0800751 case CMD_GET_PREFERRED_NETWORK_TYPE:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700754 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800755 break;
756
757 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
758 ar = (AsyncResult) msg.obj;
759 request = (MainThreadRequest) ar.userObj;
760 if (ar.exception == null && ar.result != null) {
761 request.result = ar.result; // Integer
762 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800763 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800764 if (ar.result == null) {
765 loge("getPreferredNetworkType: Empty response");
766 } else if (ar.exception instanceof CommandException) {
767 loge("getPreferredNetworkType: CommandException: " +
768 ar.exception);
769 } else {
770 loge("getPreferredNetworkType: Unknown exception");
771 }
772 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800774 break;
775
776 case CMD_SET_PREFERRED_NETWORK_TYPE:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
779 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700780 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800781 break;
782
783 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
784 handleNullReturnEvent(msg, "setPreferredNetworkType");
785 break;
786
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000787 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
788 request = (MainThreadRequest)msg.obj;
789 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800790 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000791 break;
792
793 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
794 ar = (AsyncResult)msg.obj;
795 request = (MainThreadRequest)ar.userObj;
796 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700797 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000798 break;
799
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800800 case CMD_SET_VOICEMAIL_NUMBER:
801 request = (MainThreadRequest) msg.obj;
802 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
803 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800804 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
805 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800806 break;
807
808 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
809 handleNullReturnEvent(msg, "setVoicemailNumber");
810 break;
811
Stuart Scott54788802015-03-30 13:18:01 -0700812 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
813 request = (MainThreadRequest) msg.obj;
814 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
815 request);
816 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
817 break;
818
819 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
820 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
821 break;
822
Shishir Agrawal302c8692015-06-19 13:49:39 -0700823 case CMD_PERFORM_NETWORK_SCAN:
824 request = (MainThreadRequest) msg.obj;
825 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
826 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
827 break;
828
Shuo Qian4a594052020-01-23 11:59:30 -0800829 case CMD_GET_CALL_FORWARDING:
830 request = (MainThreadRequest) msg.obj;
831 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
832 int callForwardingReason = (Integer) request.argument;
833 getPhoneFromRequest(request).getCallForwardingOption(
834 callForwardingReason, onCompleted);
835 break;
836
837 case EVENT_GET_CALL_FORWARDING_DONE:
838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 CallForwardingInfo callForwardingInfo = null;
841 if (ar.exception == null && ar.result != null) {
842 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
843 for (CallForwardInfo callForwardInfo : callForwardInfos) {
844 // Service Class is a bit mask per 3gpp 27.007. Search for
845 // any service for voice call.
846 if ((callForwardInfo.serviceClass
847 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
848 callForwardingInfo = new CallForwardingInfo(
849 callForwardInfo.serviceClass, callForwardInfo.reason,
850 callForwardInfo.number,
851 callForwardInfo.timeSeconds);
852 break;
853 }
854 }
855 // Didn't find a call forward info for voice call.
856 if (callForwardingInfo == null) {
857 callForwardingInfo = new CallForwardingInfo(
858 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
859 0 /* reason */, null /* number */, 0 /* timeout */);
860 }
861 } else {
862 if (ar.result == null) {
863 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
864 }
865 if (ar.exception != null) {
866 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
867 }
868 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
869 if (ar.exception instanceof CommandException) {
870 CommandException.Error error =
871 ((CommandException) (ar.exception)).getCommandError();
872 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
873 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
874 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
875 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
876 }
877 }
878 callForwardingInfo = new CallForwardingInfo(
879 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
880 }
881 request.result = callForwardingInfo;
882 notifyRequester(request);
883 break;
884
885 case CMD_SET_CALL_FORWARDING:
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
888 CallForwardingInfo callForwardingInfoToSet =
889 (CallForwardingInfo) request.argument;
890 getPhoneFromRequest(request).setCallForwardingOption(
891 callForwardingInfoToSet.getStatus(),
892 callForwardingInfoToSet.getReason(),
893 callForwardingInfoToSet.getNumber(),
894 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
895 break;
896
897 case EVENT_SET_CALL_FORWARDING_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null) {
901 request.result = true;
902 } else {
903 request.result = false;
904 loge("setCallForwarding exception: " + ar.exception);
905 }
906 notifyRequester(request);
907 break;
908
909 case CMD_GET_CALL_WAITING:
910 request = (MainThreadRequest) msg.obj;
911 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
912 getPhoneFromRequest(request).getCallWaiting(onCompleted);
913 break;
914
915 case EVENT_GET_CALL_WAITING_DONE:
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
919 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800920 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800921 // Service Class is a bit mask per 3gpp 27.007.
922 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800923 if (callForwardResults.length > 1
924 && ((callForwardResults[1]
925 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
926 callForwardingStatus = callForwardResults[0] == 0
Shuo Qian4a594052020-01-23 11:59:30 -0800927 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
928 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
929 } else {
930 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
931 }
932 } else {
933 if (ar.result == null) {
934 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
935 }
936 if (ar.exception != null) {
937 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
938 }
939 if (ar.exception instanceof CommandException) {
940 CommandException.Error error =
941 ((CommandException) (ar.exception)).getCommandError();
942 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
943 callForwardingStatus =
944 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
945 }
946 }
947 }
948 request.result = callForwardingStatus;
949 notifyRequester(request);
950 break;
951
952 case CMD_SET_CALL_WAITING:
953 request = (MainThreadRequest) msg.obj;
954 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
955 boolean isEnable = (Boolean) request.argument;
956 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
957 break;
958
959 case EVENT_SET_CALL_WAITING_DONE:
960 ar = (AsyncResult) msg.obj;
961 request = (MainThreadRequest) ar.userObj;
962 if (ar.exception == null) {
963 request.result = true;
964 } else {
965 request.result = false;
966 loge("setCallWaiting exception: " + ar.exception);
967 }
968 notifyRequester(request);
969 break;
970
Shishir Agrawal302c8692015-06-19 13:49:39 -0700971 case EVENT_PERFORM_NETWORK_SCAN_DONE:
972 ar = (AsyncResult) msg.obj;
973 request = (MainThreadRequest) ar.userObj;
974 CellNetworkScanResult cellScanResult;
975 if (ar.exception == null && ar.result != null) {
976 cellScanResult = new CellNetworkScanResult(
977 CellNetworkScanResult.STATUS_SUCCESS,
978 (List<OperatorInfo>) ar.result);
979 } else {
980 if (ar.result == null) {
981 loge("getCellNetworkScanResults: Empty response");
982 }
983 if (ar.exception != null) {
984 loge("getCellNetworkScanResults: Exception: " + ar.exception);
985 }
986 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
987 if (ar.exception instanceof CommandException) {
988 CommandException.Error error =
989 ((CommandException) (ar.exception)).getCommandError();
990 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
991 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
992 } else if (error == CommandException.Error.GENERIC_FAILURE) {
993 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
994 }
995 }
996 cellScanResult = new CellNetworkScanResult(errorCode, null);
997 }
998 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700999 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001000 break;
1001
1002 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1003 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001004 ManualNetworkSelectionArgument selArg =
1005 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001006 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1007 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001008 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1009 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001010 break;
1011
1012 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 if (ar.exception == null) {
1016 request.result = true;
1017 } else {
1018 request.result = false;
1019 loge("setNetworkSelectionModeManual " + ar.exception);
1020 }
1021 notifyRequester(request);
1022 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001023 break;
1024
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001025 case CMD_GET_MODEM_ACTIVITY_INFO:
1026 request = (MainThreadRequest) msg.obj;
1027 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001028 if (defaultPhone != null) {
1029 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001030 } else {
1031 ResultReceiver result = (ResultReceiver) request.argument;
1032 Bundle bundle = new Bundle();
1033 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1034 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1035 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001036 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001037 break;
1038
1039 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001042 ResultReceiver result = (ResultReceiver) request.argument;
1043
1044 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001045 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001046 // Update the last modem activity info and the result of the request.
1047 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1048 if (isModemActivityInfoValid(info)) {
1049 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1050 int[] txTimeMs = info.getTransmitTimeMillis();
1051 int[] lastModemTxTimeMs = mLastModemActivityInfo
1052 .getTransmitTimeMillis();
1053 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1054 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1055 }
1056 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1057 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1058 + mLastModemActivityInfo.getSleepTimeMillis());
1059 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1060 + mLastModemActivityInfo.getIdleTimeMillis());
1061 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1062 mLastModemActivityInfo.setReceiveTimeMillis(
1063 info.getReceiveTimeMillis()
1064 + mLastModemActivityInfo.getReceiveTimeMillis());
1065 }
1066 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1067 mLastModemActivityInfo.getSleepTimeMillis(),
1068 mLastModemActivityInfo.getIdleTimeMillis(),
1069 mLastModemActivityInfo.getTransmitTimeMillis(),
1070 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001071 } else {
1072 if (ar.result == null) {
1073 loge("queryModemActivityInfo: Empty response");
1074 } else if (ar.exception instanceof CommandException) {
1075 loge("queryModemActivityInfo: CommandException: " +
1076 ar.exception);
1077 } else {
1078 loge("queryModemActivityInfo: Unknown exception");
1079 }
1080 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001081 Bundle bundle = new Bundle();
1082 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1083 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001084 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001085 break;
1086
Meng Wang1a7c35a2016-05-05 20:56:15 -07001087 case CMD_SET_ALLOWED_CARRIERS:
1088 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001089 CarrierRestrictionRules argument =
1090 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001091 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001092 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001093 break;
1094
1095 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1096 ar = (AsyncResult) msg.obj;
1097 request = (MainThreadRequest) ar.userObj;
1098 if (ar.exception == null && ar.result != null) {
1099 request.result = ar.result;
1100 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001101 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1102 if (ar.exception instanceof CommandException) {
1103 loge("setAllowedCarriers: CommandException: " + ar.exception);
1104 CommandException.Error error =
1105 ((CommandException) (ar.exception)).getCommandError();
1106 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1107 request.result =
1108 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1109 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001110 } else {
1111 loge("setAllowedCarriers: Unknown exception");
1112 }
1113 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001114 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001115 break;
1116
1117 case CMD_GET_ALLOWED_CARRIERS:
1118 request = (MainThreadRequest) msg.obj;
1119 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001120 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001121 break;
1122
1123 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1124 ar = (AsyncResult) msg.obj;
1125 request = (MainThreadRequest) ar.userObj;
1126 if (ar.exception == null && ar.result != null) {
1127 request.result = ar.result;
1128 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001129 request.result = new IllegalStateException(
1130 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001131 if (ar.result == null) {
1132 loge("getAllowedCarriers: Empty response");
1133 } else if (ar.exception instanceof CommandException) {
1134 loge("getAllowedCarriers: CommandException: " +
1135 ar.exception);
1136 } else {
1137 loge("getAllowedCarriers: Unknown exception");
1138 }
1139 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001140 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001141 break;
1142
Nathan Haroldb3014052017-01-25 15:57:32 -08001143 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1144 ar = (AsyncResult) msg.obj;
1145 request = (MainThreadRequest) ar.userObj;
1146 if (ar.exception == null && ar.result != null) {
1147 request.result = ar.result;
1148 } else {
1149 request.result = new IllegalArgumentException(
1150 "Failed to retrieve Forbidden Plmns");
1151 if (ar.result == null) {
1152 loge("getForbiddenPlmns: Empty response");
1153 } else {
1154 loge("getForbiddenPlmns: Unknown exception");
1155 }
1156 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001157 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001158 break;
1159
1160 case CMD_GET_FORBIDDEN_PLMNS:
1161 request = (MainThreadRequest) msg.obj;
1162 uiccCard = getUiccCardFromRequest(request);
1163 if (uiccCard == null) {
1164 loge("getForbiddenPlmns() UiccCard is null");
1165 request.result = new IllegalArgumentException(
1166 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001167 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001168 break;
1169 }
1170 Integer appType = (Integer) request.argument;
1171 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1172 if (uiccApp == null) {
1173 loge("getForbiddenPlmns() no app with specified type -- "
1174 + appType);
1175 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001176 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001177 break;
1178 } else {
1179 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1180 + " specified type -- " + appType);
1181 }
1182 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1183 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1184 onCompleted);
1185 break;
1186
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001187 case CMD_SWITCH_SLOTS:
1188 request = (MainThreadRequest) msg.obj;
1189 int[] physicalSlots = (int[]) request.argument;
1190 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1191 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1192 break;
1193
1194 case EVENT_SWITCH_SLOTS_DONE:
1195 ar = (AsyncResult) msg.obj;
1196 request = (MainThreadRequest) ar.userObj;
1197 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001198 notifyRequester(request);
1199 break;
1200 case CMD_GET_NETWORK_SELECTION_MODE:
1201 request = (MainThreadRequest) msg.obj;
1202 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1203 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1204 break;
1205
1206 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1207 ar = (AsyncResult) msg.obj;
1208 request = (MainThreadRequest) ar.userObj;
1209 if (ar.exception != null) {
1210 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1211 } else {
1212 int mode = ((int[]) ar.result)[0];
1213 if (mode == 0) {
1214 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1215 } else {
1216 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1217 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001218 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001219 notifyRequester(request);
1220 break;
1221 case CMD_GET_CDMA_ROAMING_MODE:
1222 request = (MainThreadRequest) msg.obj;
1223 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1224 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1225 break;
1226 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1227 ar = (AsyncResult) msg.obj;
1228 request = (MainThreadRequest) ar.userObj;
1229 if (ar.exception != null) {
1230 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1231 } else {
1232 request.result = ((int[]) ar.result)[0];
1233 }
1234 notifyRequester(request);
1235 break;
1236 case CMD_SET_CDMA_ROAMING_MODE:
1237 request = (MainThreadRequest) msg.obj;
1238 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1239 int mode = (int) request.argument;
1240 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1241 break;
1242 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1243 ar = (AsyncResult) msg.obj;
1244 request = (MainThreadRequest) ar.userObj;
1245 request.result = ar.exception == null;
1246 notifyRequester(request);
1247 break;
1248 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1249 request = (MainThreadRequest) msg.obj;
1250 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1251 int subscriptionMode = (int) request.argument;
1252 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1253 break;
1254 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1255 ar = (AsyncResult) msg.obj;
1256 request = (MainThreadRequest) ar.userObj;
1257 request.result = ar.exception == null;
1258 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001259 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001260 case CMD_GET_ALL_CELL_INFO:
1261 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001262 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001263 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001264 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001265 case EVENT_GET_ALL_CELL_INFO_DONE:
1266 ar = (AsyncResult) msg.obj;
1267 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001268 // If a timeout occurs, the response will be null
1269 request.result = (ar.exception == null && ar.result != null)
1270 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001271 synchronized (request) {
1272 request.notifyAll();
1273 }
1274 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001275 case CMD_REQUEST_CELL_INFO_UPDATE:
1276 request = (MainThreadRequest) msg.obj;
1277 request.phone.requestCellInfoUpdate(request.workSource,
1278 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1279 break;
1280 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1281 ar = (AsyncResult) msg.obj;
1282 request = (MainThreadRequest) ar.userObj;
1283 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1284 try {
1285 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001286 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001287 cb.onError(
1288 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1289 ar.exception.getClass().getName(),
1290 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001291 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001292 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001293 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001294 } else {
1295 // use the result as returned
1296 cb.onCellInfo((List<CellInfo>) ar.result);
1297 }
1298 } catch (RemoteException re) {
1299 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1300 }
1301 break;
1302 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001303 request = (MainThreadRequest) msg.obj;
1304 WorkSource ws = (WorkSource) request.argument;
1305 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001306 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001307 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001308 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001309 ar = (AsyncResult) msg.obj;
1310 request = (MainThreadRequest) ar.userObj;
1311 if (ar.exception == null) {
1312 request.result = ar.result;
1313 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001314 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001315 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001316 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001317 }
1318
1319 synchronized (request) {
1320 request.notifyAll();
1321 }
1322 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001323 case CMD_MODEM_REBOOT:
1324 request = (MainThreadRequest) msg.obj;
1325 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001326 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001327 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001328 case EVENT_CMD_MODEM_REBOOT_DONE:
1329 handleNullReturnEvent(msg, "rebootModem");
1330 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001331 case CMD_REQUEST_ENABLE_MODEM:
1332 request = (MainThreadRequest) msg.obj;
1333 boolean enable = (boolean) request.argument;
1334 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001335 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001336 PhoneConfigurationManager.getInstance()
1337 .enablePhone(request.phone, enable, onCompleted);
1338 break;
1339 case EVENT_ENABLE_MODEM_DONE:
1340 ar = (AsyncResult) msg.obj;
1341 request = (MainThreadRequest) ar.userObj;
1342 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001343 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001344 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001345 if ((boolean) request.result) {
1346 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1347 updateModemStateMetrics();
1348 } else {
1349 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1350 + ar.exception);
1351 }
1352 notifyRequester(request);
1353 break;
1354 case CMD_GET_MODEM_STATUS:
1355 request = (MainThreadRequest) msg.obj;
1356 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1357 PhoneConfigurationManager.getInstance()
1358 .getPhoneStatusFromModem(request.phone, onCompleted);
1359 break;
1360 case EVENT_GET_MODEM_STATUS_DONE:
1361 ar = (AsyncResult) msg.obj;
1362 request = (MainThreadRequest) ar.userObj;
1363 int id = request.phone.getPhoneId();
1364 if (ar.exception == null && ar.result != null) {
1365 request.result = ar.result;
1366 //update the cache as modem status has changed
1367 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1368 (boolean) request.result);
1369 } else {
1370 // Return true if modem status cannot be retrieved. For most cases,
1371 // modem status is on. And for older version modems, GET_MODEM_STATUS
1372 // and disable modem are not supported. Modem is always on.
1373 // TODO: this should be fixed in R to support a third
1374 // status UNKNOWN b/131631629
1375 request.result = true;
1376 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1377 + ar.exception);
1378 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001379 notifyRequester(request);
1380 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001381 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1382 request = (MainThreadRequest) msg.obj;
1383 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1384 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1385 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1386 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1387 break;
1388 }
1389 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1390 ar = (AsyncResult) msg.obj;
1391 request = (MainThreadRequest) ar.userObj;
1392 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1393 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1394 args.second.accept(ar.exception == null);
1395 notifyRequester(request);
1396 break;
1397 }
yincheng zhao2737e882019-09-06 17:06:54 -07001398 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1399 ar = (AsyncResult) msg.obj;
1400 request = (MainThreadRequest) ar.userObj;
1401 if (ar.exception == null && ar.result != null) {
1402 request.result = ar.result;
1403 } else {
1404 request.result = -1;
1405 loge("Failed to set Forbidden Plmns");
1406 if (ar.result == null) {
1407 loge("setForbidenPlmns: Empty response");
1408 } else if (ar.exception != null) {
1409 loge("setForbiddenPlmns: Exception: " + ar.exception);
1410 request.result = -1;
1411 } else {
1412 loge("setForbiddenPlmns: Unknown exception");
1413 }
1414 }
1415 notifyRequester(request);
1416 break;
1417 case CMD_SET_FORBIDDEN_PLMNS:
1418 request = (MainThreadRequest) msg.obj;
1419 uiccCard = getUiccCardFromRequest(request);
1420 if (uiccCard == null) {
1421 loge("setForbiddenPlmns: UiccCard is null");
1422 request.result = -1;
1423 notifyRequester(request);
1424 break;
1425 }
1426 Pair<Integer, List<String>> setFplmnsArgs =
1427 (Pair<Integer, List<String>>) request.argument;
1428 appType = setFplmnsArgs.first;
1429 List<String> fplmns = setFplmnsArgs.second;
1430 uiccApp = uiccCard.getApplicationByType(appType);
1431 if (uiccApp == null) {
1432 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1433 request.result = -1;
1434 loge("Failed to get UICC App");
1435 notifyRequester(request);
1436 } else {
1437 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1438 ((SIMRecords) uiccApp.getIccRecords())
1439 .setForbiddenPlmns(onCompleted, fplmns);
1440 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001441 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001442 case CMD_ERASE_MODEM_CONFIG:
1443 request = (MainThreadRequest) msg.obj;
1444 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1445 defaultPhone.eraseModemConfig(onCompleted);
1446 break;
1447 case EVENT_ERASE_MODEM_CONFIG_DONE:
1448 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001449 break;
zoey chene02881a2019-12-30 16:11:23 +08001450
1451 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1452 request = (MainThreadRequest) msg.obj;
1453 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1454 Pair<String, String> changed = (Pair<String, String>) request.argument;
1455 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1456 changed.first, changed.second, onCompleted);
1457 break;
1458 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1459 ar = (AsyncResult) msg.obj;
1460 request = (MainThreadRequest) ar.userObj;
1461 if (ar.exception == null) {
1462 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1463 } else {
1464 request.result = msg.arg1;
1465 }
1466 notifyRequester(request);
1467 break;
1468
1469 case CMD_SET_ICC_LOCK_ENABLED:
1470 request = (MainThreadRequest) msg.obj;
1471 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1472 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1473 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1474 enabled.first, enabled.second, onCompleted);
1475 break;
1476 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1477 ar = (AsyncResult) msg.obj;
1478 request = (MainThreadRequest) ar.userObj;
1479 if (ar.exception == null) {
1480 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1481 } else {
1482 request.result = msg.arg1;
1483 }
1484 notifyRequester(request);
1485 break;
1486
Peter Wangdafb9ac2020-01-15 14:13:38 -08001487 case MSG_NOTIFY_USER_ACTIVITY:
1488 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001489 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001490 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1491 getDefaultPhone().getContext().sendBroadcastAsUser(
1492 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1493 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001494 default:
1495 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1496 break;
1497 }
1498 }
Jake Hambye994d462014-02-03 13:10:13 -08001499
Pengquan Menga1bb6272018-09-06 09:59:22 -07001500 private void notifyRequester(MainThreadRequest request) {
1501 synchronized (request) {
1502 request.notifyAll();
1503 }
1504 }
1505
Jake Hambye994d462014-02-03 13:10:13 -08001506 private void handleNullReturnEvent(Message msg, String command) {
1507 AsyncResult ar = (AsyncResult) msg.obj;
1508 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1509 if (ar.exception == null) {
1510 request.result = true;
1511 } else {
1512 request.result = false;
1513 if (ar.exception instanceof CommandException) {
1514 loge(command + ": CommandException: " + ar.exception);
1515 } else {
1516 loge(command + ": Unknown exception");
1517 }
1518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001519 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001521 }
1522
1523 /**
1524 * Posts the specified command to be executed on the main thread,
1525 * waits for the request to complete, and returns the result.
1526 * @see #sendRequestAsync
1527 */
1528 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001529 return sendRequest(
1530 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001531 }
1532
1533 /**
1534 * Posts the specified command to be executed on the main thread,
1535 * waits for the request to complete, and returns the result.
1536 * @see #sendRequestAsync
1537 */
1538 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1539 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001540 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001541 }
1542
1543 /**
1544 * Posts the specified command to be executed on the main thread,
1545 * waits for the request to complete, and returns the result.
1546 * @see #sendRequestAsync
1547 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001548 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001549 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001550 }
1551
1552 /**
1553 * Posts the specified command to be executed on the main thread,
1554 * waits for the request to complete, and returns the result.
1555 * @see #sendRequestAsync
1556 */
Nathan Harold92bed182018-10-12 18:16:49 -07001557 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1558 return sendRequest(command, argument, subId, null, workSource);
1559 }
1560
1561 /**
1562 * Posts the specified command to be executed on the main thread,
1563 * waits for the request to complete, and returns the result.
1564 * @see #sendRequestAsync
1565 */
1566 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1567 return sendRequest(
1568 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1569 }
1570
1571 /**
1572 * Posts the specified command to be executed on the main thread,
1573 * waits for the request to complete, and returns the result.
1574 * @see #sendRequestAsync
1575 */
1576 private Object sendRequest(
1577 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001578 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1579 throw new RuntimeException("This method will deadlock if called from the main thread.");
1580 }
1581
Nathan Harold92bed182018-10-12 18:16:49 -07001582 MainThreadRequest request = null;
1583 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1584 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1585 } else if (phone != null) {
1586 request = new MainThreadRequest(argument, phone, workSource);
1587 } else {
1588 request = new MainThreadRequest(argument, subId, workSource);
1589 }
1590
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 Message msg = mMainThreadHandler.obtainMessage(command, request);
1592 msg.sendToTarget();
1593
1594 // Wait for the request to complete
1595 synchronized (request) {
1596 while (request.result == null) {
1597 try {
1598 request.wait();
1599 } catch (InterruptedException e) {
1600 // Do nothing, go back and wait until the request is complete
1601 }
1602 }
1603 }
1604 return request.result;
1605 }
1606
1607 /**
1608 * Asynchronous ("fire and forget") version of sendRequest():
1609 * Posts the specified command to be executed on the main thread, and
1610 * returns immediately.
1611 * @see #sendRequest
1612 */
1613 private void sendRequestAsync(int command) {
1614 mMainThreadHandler.sendEmptyMessage(command);
1615 }
1616
1617 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001618 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001619 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001620 */
1621 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001622 sendRequestAsync(command, argument, null, null);
1623 }
1624
1625 /**
1626 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1627 * @see {@link #sendRequest(int,Object)}
1628 */
1629 private void sendRequestAsync(
1630 int command, Object argument, Phone phone, WorkSource workSource) {
1631 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001632 Message msg = mMainThreadHandler.obtainMessage(command, request);
1633 msg.sendToTarget();
1634 }
1635
1636 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001637 * Initialize the singleton PhoneInterfaceManager instance.
1638 * This is only done once, at startup, from PhoneApp.onCreate().
1639 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001640 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 synchronized (PhoneInterfaceManager.class) {
1642 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001643 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 } else {
1645 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1646 }
1647 return sInstance;
1648 }
1649 }
1650
1651 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001652 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001655 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001656 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1658 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001659 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001660 mTelephonySharedPreferences =
1661 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001662 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001663 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001664 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001665
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 publish();
1667 }
1668
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001669 private Phone getDefaultPhone() {
1670 Phone thePhone = getPhone(getDefaultSubscription());
1671 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1672 }
1673
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 private void publish() {
1675 if (DBG) log("publish: " + this);
1676
Peter Wangc035ce42020-01-08 21:00:22 -08001677 TelephonyFrameworkInitializer
1678 .getTelephonyServiceManager()
1679 .getTelephonyServiceRegisterer()
1680 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 }
1682
Stuart Scott584921c2015-01-15 17:10:34 -08001683 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001684 if (request.phone != null) {
1685 return request.phone;
1686 } else {
1687 return getPhoneFromSubId(request.subId);
1688 }
1689 }
1690
1691 private Phone getPhoneFromSubId(int subId) {
1692 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1693 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001694 }
1695
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001696 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1697 Phone phone = getPhoneFromRequest(request);
1698 return phone == null ? null :
1699 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1700 }
1701
Wink Saville36469e72014-06-11 15:17:00 -07001702 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001703 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001704 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706
Naina Nallurid63128d2019-09-17 14:10:30 -07001707 private void sendEraseModemConfig(Phone phone) {
1708 if (phone != null) {
1709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1710 mApp, phone.getSubId(), "eraseModemConfig");
1711 final long identity = Binder.clearCallingIdentity();
1712 try {
1713 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1714 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1715 } finally {
1716 Binder.restoreCallingIdentity(identity);
1717 }
1718 }
1719 }
1720
Peter Wang44b186e2020-01-13 23:33:09 -08001721 private boolean isImsAvailableOnDevice() {
1722 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1723 if (pm == null) {
1724 // For some reason package manger is not available.. This will fail internally anyway,
1725 // so do not throw error and allow.
1726 return true;
1727 }
1728 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1729 }
1730
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001731 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001732 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001733 }
1734
Wink Savilleb564aae2014-10-23 10:18:09 -07001735 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 if (DBG) log("dial: " + number);
1737 // No permission check needed here: This is just a wrapper around the
1738 // ACTION_DIAL intent, which is available to any app since it puts up
1739 // the UI before it does anything.
1740
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001741 final long identity = Binder.clearCallingIdentity();
1742 try {
1743 String url = createTelUrl(number);
1744 if (url == null) {
1745 return;
1746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001748 // PENDING: should we just silently fail if phone is offhook or ringing?
1749 PhoneConstants.State state = mCM.getState(subId);
1750 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1751 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1752 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1753 mApp.startActivity(intent);
1754 }
1755 } finally {
1756 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 }
1758 }
1759
1760 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001761 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001762 }
1763
Wink Savilleb564aae2014-10-23 10:18:09 -07001764 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 if (DBG) log("call: " + number);
1766
1767 // This is just a wrapper around the ACTION_CALL intent, but we still
1768 // need to do a permission check since we're calling startActivity()
1769 // from the context of the phone app.
1770 enforceCallPermission();
1771
Jordan Liu1617b712019-07-10 15:06:26 -07001772 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 != AppOpsManager.MODE_ALLOWED) {
1774 return;
1775 }
1776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001777 final long identity = Binder.clearCallingIdentity();
1778 try {
1779 String url = createTelUrl(number);
1780 if (url == null) {
1781 return;
1782 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001784 boolean isValid = false;
1785 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1786 if (slist != null) {
1787 for (SubscriptionInfo subInfoRecord : slist) {
1788 if (subInfoRecord.getSubscriptionId() == subId) {
1789 isValid = true;
1790 break;
1791 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001792 }
Wink Saville08874612014-08-31 19:19:58 -07001793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001794 if (!isValid) {
1795 return;
1796 }
Wink Saville08874612014-08-31 19:19:58 -07001797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001798 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1799 intent.putExtra(SUBSCRIPTION_KEY, subId);
1800 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1801 mApp.startActivity(intent);
1802 } finally {
1803 Binder.restoreCallingIdentity(identity);
1804 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 }
1806
Wink Savilleb564aae2014-10-23 10:18:09 -07001807 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001808 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001809 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1810 }
1811
Wink Savilleb564aae2014-10-23 10:18:09 -07001812 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001813 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001814 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1815 }
1816
Wink Savilleb564aae2014-10-23 10:18:09 -07001817 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001819
1820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1823 checkSimPin.start();
1824 return checkSimPin.unlockSim(null, pin);
1825 } finally {
1826 Binder.restoreCallingIdentity(identity);
1827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 }
1829
Wink Savilleb564aae2014-10-23 10:18:09 -07001830 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001832
1833 final long identity = Binder.clearCallingIdentity();
1834 try {
1835 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1836 checkSimPuk.start();
1837 return checkSimPuk.unlockSim(puk, pin);
1838 } finally {
1839 Binder.restoreCallingIdentity(identity);
1840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001841 }
1842
1843 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001844 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 * a synchronous one.
1846 */
1847 private static class UnlockSim extends Thread {
1848
1849 private final IccCard mSimCard;
1850
1851 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001852 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1853 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854
1855 // For replies from SimCard interface
1856 private Handler mHandler;
1857
1858 // For async handler to identify request type
1859 private static final int SUPPLY_PIN_COMPLETE = 100;
1860
1861 public UnlockSim(IccCard simCard) {
1862 mSimCard = simCard;
1863 }
1864
1865 @Override
1866 public void run() {
1867 Looper.prepare();
1868 synchronized (UnlockSim.this) {
1869 mHandler = new Handler() {
1870 @Override
1871 public void handleMessage(Message msg) {
1872 AsyncResult ar = (AsyncResult) msg.obj;
1873 switch (msg.what) {
1874 case SUPPLY_PIN_COMPLETE:
1875 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1876 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001877 mRetryCount = msg.arg1;
1878 if (ar.exception != null) {
1879 if (ar.exception instanceof CommandException &&
1880 ((CommandException)(ar.exception)).getCommandError()
1881 == CommandException.Error.PASSWORD_INCORRECT) {
1882 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1883 } else {
1884 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1885 }
1886 } else {
1887 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 mDone = true;
1890 UnlockSim.this.notifyAll();
1891 }
1892 break;
1893 }
1894 }
1895 };
1896 UnlockSim.this.notifyAll();
1897 }
1898 Looper.loop();
1899 }
1900
1901 /*
1902 * Use PIN or PUK to unlock SIM card
1903 *
1904 * If PUK is null, unlock SIM card with PIN
1905 *
1906 * If PUK is not null, unlock SIM card with PUK and set PIN code
1907 */
Wink Saville9de0f752013-10-22 19:04:03 -07001908 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909
1910 while (mHandler == null) {
1911 try {
1912 wait();
1913 } catch (InterruptedException e) {
1914 Thread.currentThread().interrupt();
1915 }
1916 }
1917 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1918
1919 if (puk == null) {
1920 mSimCard.supplyPin(pin, callback);
1921 } else {
1922 mSimCard.supplyPuk(puk, pin, callback);
1923 }
1924
1925 while (!mDone) {
1926 try {
1927 Log.d(LOG_TAG, "wait for done");
1928 wait();
1929 } catch (InterruptedException e) {
1930 // Restore the interrupted status
1931 Thread.currentThread().interrupt();
1932 }
1933 }
1934 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001935 int[] resultArray = new int[2];
1936 resultArray[0] = mResult;
1937 resultArray[1] = mRetryCount;
1938 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 }
1940 }
1941
1942 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001943 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001944
1945 }
1946
Wink Savilleb564aae2014-10-23 10:18:09 -07001947 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948 // No permission check needed here: this call is harmless, and it's
1949 // needed for the ServiceState.requestStateUpdate() call (which is
1950 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001951 final long identity = Binder.clearCallingIdentity();
1952 try {
1953 final Phone phone = getPhone(subId);
1954 if (phone != null) {
1955 phone.updateServiceLocation();
1956 }
1957 } finally {
1958 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001960 }
1961
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001962 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001963 @Override
1964 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001965 return isRadioOnWithFeature(callingPackage, null);
1966 }
1967
1968
1969 @Override
1970 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1971 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1972 callingFeatureId);
1973 }
1974
1975 @Deprecated
1976 @Override
1977 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1978 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001979 }
1980
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001981 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001982 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1983 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001984 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001985 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001986 return false;
1987 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001988
1989 final long identity = Binder.clearCallingIdentity();
1990 try {
1991 return isRadioOnForSubscriber(subId);
1992 } finally {
1993 Binder.restoreCallingIdentity(identity);
1994 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001995 }
1996
1997 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001998 final long identity = Binder.clearCallingIdentity();
1999 try {
2000 final Phone phone = getPhone(subId);
2001 if (phone != null) {
2002 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2003 } else {
2004 return false;
2005 }
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010
2011 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002012 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 }
Wink Saville36469e72014-06-11 15:17:00 -07002014
Wink Savilleb564aae2014-10-23 10:18:09 -07002015 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002017
2018 final long identity = Binder.clearCallingIdentity();
2019 try {
2020 final Phone phone = getPhone(subId);
2021 if (phone != null) {
2022 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2023 }
2024 } finally {
2025 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002026 }
Wink Saville36469e72014-06-11 15:17:00 -07002027 }
2028
2029 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002030 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002031 }
2032
Wink Savilleb564aae2014-10-23 10:18:09 -07002033 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002034 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002035
2036 final long identity = Binder.clearCallingIdentity();
2037 try {
2038 final Phone phone = getPhone(subId);
2039 if (phone == null) {
2040 return false;
2041 }
2042 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2043 toggleRadioOnOffForSubscriber(subId);
2044 }
2045 return true;
2046 } finally {
2047 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 }
Wink Saville36469e72014-06-11 15:17:00 -07002050
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002051 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002052 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002053 /*
2054 * If any of the Radios are available, it will need to be
2055 * shutdown. So return true if any Radio is available.
2056 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057 final long identity = Binder.clearCallingIdentity();
2058 try {
2059 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2060 Phone phone = PhoneFactory.getPhone(i);
2061 if (phone != null && phone.isRadioAvailable()) return true;
2062 }
2063 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2064 return false;
2065 } finally {
2066 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002067 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002068 }
2069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002070 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002071 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072 enforceModifyPermission();
2073
2074 final long identity = Binder.clearCallingIdentity();
2075 try {
2076 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2077 logv("Shutting down Phone " + i);
2078 shutdownRadioUsingPhoneId(i);
2079 }
2080 } finally {
2081 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002082 }
2083 }
2084
2085 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002086 Phone phone = PhoneFactory.getPhone(phoneId);
2087 if (phone != null && phone.isRadioAvailable()) {
2088 phone.shutdownRadio();
2089 }
2090 }
2091
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002092 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002093 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002094
2095 final long identity = Binder.clearCallingIdentity();
2096 try {
2097 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2098 if (defaultPhone != null) {
2099 defaultPhone.setRadioPower(turnOn);
2100 return true;
2101 } else {
2102 loge("There's no default phone.");
2103 return false;
2104 }
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002107 }
Wink Saville36469e72014-06-11 15:17:00 -07002108 }
2109
Wink Savilleb564aae2014-10-23 10:18:09 -07002110 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002112
2113 final long identity = Binder.clearCallingIdentity();
2114 try {
2115 final Phone phone = getPhone(subId);
2116 if (phone != null) {
2117 phone.setRadioPower(turnOn);
2118 return true;
2119 } else {
2120 return false;
2121 }
2122 } finally {
2123 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002124 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002125 }
2126
Wink Saville36469e72014-06-11 15:17:00 -07002127 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002128 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 public boolean enableDataConnectivity() {
2130 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002131
2132 final long identity = Binder.clearCallingIdentity();
2133 try {
2134 int subId = mSubscriptionController.getDefaultDataSubId();
2135 final Phone phone = getPhone(subId);
2136 if (phone != null) {
Sooraj Sasindran4872c7f2020-04-19 18:14:03 -07002137 phone.getDataEnabledSettings().setDataEnabled(
2138 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002139 return true;
2140 } else {
2141 return false;
2142 }
2143 } finally {
2144 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002145 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146 }
2147
Wink Saville36469e72014-06-11 15:17:00 -07002148 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002149 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 public boolean disableDataConnectivity() {
2151 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002152
2153 final long identity = Binder.clearCallingIdentity();
2154 try {
2155 int subId = mSubscriptionController.getDefaultDataSubId();
2156 final Phone phone = getPhone(subId);
2157 if (phone != null) {
Sooraj Sasindran4872c7f2020-04-19 18:14:03 -07002158 phone.getDataEnabledSettings().setDataEnabled(
2159 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002160 return true;
2161 } else {
2162 return false;
2163 }
2164 } finally {
2165 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 }
2168
Sanket Padawe356d7632015-06-22 14:03:32 -07002169 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002170 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171 final long identity = Binder.clearCallingIdentity();
2172 try {
2173 final Phone phone = getPhone(subId);
2174 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002175 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176 } else {
2177 return false;
2178 }
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 }
2183
2184 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002185 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002186 }
2187
pkanwarae03a6b2016-11-06 20:37:09 -08002188 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002189 enforceCallPermission();
2190
2191 final long identity = Binder.clearCallingIdentity();
2192 try {
2193 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2194 return;
2195 }
2196 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2197 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2198 } finally {
2199 Binder.restoreCallingIdentity(identity);
2200 }
pkanwar32d516d2016-10-14 19:37:38 -07002201 };
2202
Wink Savilleb564aae2014-10-23 10:18:09 -07002203 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205
2206 final long identity = Binder.clearCallingIdentity();
2207 try {
2208 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2209 return false;
2210 }
2211 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2212 } finally {
2213 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002214 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 }
2216
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002218 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002219 }
2220
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002221 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222 final long identity = Binder.clearCallingIdentity();
2223 try {
2224 Phone phone = PhoneFactory.getPhone(slotIndex);
2225 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2226 PhoneConstantConversions.convertCallState(phone.getState());
2227 } finally {
2228 Binder.restoreCallingIdentity(identity);
2229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 }
2231
Sanket Padawe356d7632015-06-22 14:03:32 -07002232 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002233 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002234 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2235 }
2236
2237 @Override
2238 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002239 final long identity = Binder.clearCallingIdentity();
2240 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002241 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242 if (phone != null) {
2243 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2244 } else {
2245 return PhoneConstantConversions.convertDataState(
2246 PhoneConstants.DataState.DISCONNECTED);
2247 }
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 }
2252
Sanket Padawe356d7632015-06-22 14:03:32 -07002253 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002254 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002255 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2256 }
2257
2258 @Override
2259 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260 final long identity = Binder.clearCallingIdentity();
2261 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002262 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002263 if (phone != null) {
2264 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2265 } else {
2266 return TelephonyManager.DATA_ACTIVITY_NONE;
2267 }
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 }
2272
2273 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002274 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002275 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002276 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002277
2278 LocationAccessPolicy.LocationPermissionResult locationResult =
2279 LocationAccessPolicy.checkLocationPermission(mApp,
2280 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2281 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002282 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002283 .setCallingPid(Binder.getCallingPid())
2284 .setCallingUid(Binder.getCallingUid())
2285 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002286 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002287 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2288 .build());
2289 switch (locationResult) {
2290 case DENIED_HARD:
2291 throw new SecurityException("Not allowed to access cell location");
2292 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002293 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2294 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 }
2296
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002297 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002298 final long identity = Binder.clearCallingIdentity();
2299 try {
2300 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002301 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002302 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002303 } finally {
2304 Binder.restoreCallingIdentity(identity);
2305 }
Svetoslav64fad262015-04-14 14:35:21 -07002306 }
2307
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002309 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002310 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2311 // registered cell info, so return a NULL country instead.
2312 final long identity = Binder.clearCallingIdentity();
2313 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002314 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2315 // Get default phone in this case.
2316 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2317 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002318 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002319 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002320 if (phone == null) return "";
2321 ServiceStateTracker sst = phone.getServiceStateTracker();
2322 if (sst == null) return "";
2323 LocaleTracker lt = sst.getLocaleTracker();
2324 if (lt == null) return "";
2325 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2326 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2327 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002328 } finally {
2329 Binder.restoreCallingIdentity(identity);
2330 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002331 }
2332
2333 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002335 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002336 }
2337
Sanket Padawe356d7632015-06-22 14:03:32 -07002338 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002339 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 mApp.enforceCallingOrSelfPermission(
2341 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002342
2343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 final Phone phone = getPhone(subId);
2346 if (phone != null) {
2347 phone.enableLocationUpdates();
2348 }
2349 } finally {
2350 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 }
2353
2354 @Override
2355 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002356 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002357 }
2358
Sanket Padawe356d7632015-06-22 14:03:32 -07002359 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002360 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 mApp.enforceCallingOrSelfPermission(
2362 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002363
2364 final long identity = Binder.clearCallingIdentity();
2365 try {
2366 final Phone phone = getPhone(subId);
2367 if (phone != null) {
2368 phone.disableLocationUpdates();
2369 }
2370 } finally {
2371 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002372 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 }
2374
Nathan Harold31d7ff32018-10-15 20:20:30 -07002375 /**
2376 * Returns the target SDK version number for a given package name.
2377 *
Nathan Haroldec184742019-07-10 17:04:16 -07002378 * This call MUST be invoked before clearing the calling UID.
2379 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002380 * @return target SDK if the package is found or INT_MAX.
2381 */
2382 private int getTargetSdk(String packageName) {
2383 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002384 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002385 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002386 if (ai != null) return ai.targetSdkVersion;
2387 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002388 loge("Failed to get package info for pkg="
2389 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002390 }
2391 return Integer.MAX_VALUE;
2392 }
2393
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 @Override
2395 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002396 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2397 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002398 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002399 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2400 throw new SecurityException(
2401 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2402 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002403
Jordan Liu1617b712019-07-10 15:06:26 -07002404 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2406 return null;
2407 }
Svetoslav64fad262015-04-14 14:35:21 -07002408
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002409 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002411 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002412 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413
Nathan Haroldf180aac2018-06-01 18:43:55 -07002414 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2415 for (CellInfo ci : info) {
2416 if (ci instanceof CellInfoGsm) {
2417 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2418 } else if (ci instanceof CellInfoWcdma) {
2419 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002422 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 }
2424
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002425 private List<CellInfo> getCachedCellInfo() {
2426 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2427 for (Phone phone : PhoneFactory.getPhones()) {
2428 List<CellInfo> info = phone.getAllCellInfo();
2429 if (info != null) cellInfos.addAll(info);
2430 }
2431 return cellInfos;
2432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433
2434 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002435 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002436 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002437 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002438
2439 LocationAccessPolicy.LocationPermissionResult locationResult =
2440 LocationAccessPolicy.checkLocationPermission(mApp,
2441 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2442 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002443 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002444 .setCallingPid(Binder.getCallingPid())
2445 .setCallingUid(Binder.getCallingUid())
2446 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002447 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002448 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2449 .build());
2450 switch (locationResult) {
2451 case DENIED_HARD:
2452 throw new SecurityException("Not allowed to access cell info");
2453 case DENIED_SOFT:
2454 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 }
2456
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002457 final int targetSdk = getTargetSdk(callingPackage);
2458 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2459 return getCachedCellInfo();
2460 }
2461
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002462 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002463 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002464 final long identity = Binder.clearCallingIdentity();
2465 try {
2466 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2467 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002468 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002469 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470 if (info != null) cellInfos.addAll(info);
2471 }
2472 return cellInfos;
2473 } finally {
2474 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 }
2476 }
2477
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002478 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002479 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2480 String callingFeatureId) {
2481 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2482 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002483 }
2484
2485 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002486 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2487 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002488 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002489 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002490 }
2491
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002492 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2493 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002494 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002495 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002496
2497 LocationAccessPolicy.LocationPermissionResult locationResult =
2498 LocationAccessPolicy.checkLocationPermission(mApp,
2499 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2500 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002501 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002502 .setCallingPid(Binder.getCallingPid())
2503 .setCallingUid(Binder.getCallingUid())
2504 .setMethod("requestCellInfoUpdate")
2505 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2506 .build());
2507 switch (locationResult) {
2508 case DENIED_HARD:
2509 throw new SecurityException("Not allowed to access cell info");
2510 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002511 try {
2512 cb.onCellInfo(new ArrayList<CellInfo>());
2513 } catch (RemoteException re) {
2514 // Drop without consequences
2515 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002516 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002517 }
2518
Nathan Harolda939a962019-05-09 10:13:47 -07002519
2520 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002521 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2522
2523 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2524 }
2525
2526 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002528 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002529 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530
2531 final long identity = Binder.clearCallingIdentity();
2532 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002533 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002534 } finally {
2535 Binder.restoreCallingIdentity(identity);
2536 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537 }
2538
Shishir Agrawala9f32182016-04-12 12:00:16 -07002539 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002540 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002541 Phone phone = PhoneFactory.getPhone(slotIndex);
2542 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002543 return null;
2544 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002545 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002546 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002547 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002548 return null;
2549 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002550
2551 final long identity = Binder.clearCallingIdentity();
2552 try {
2553 return phone.getImei();
2554 } finally {
2555 Binder.restoreCallingIdentity(identity);
2556 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002557 }
2558
2559 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002560 public String getTypeAllocationCodeForSlot(int slotIndex) {
2561 Phone phone = PhoneFactory.getPhone(slotIndex);
2562 String tac = null;
2563 if (phone != null) {
2564 String imei = phone.getImei();
2565 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2566 }
2567 return tac;
2568 }
2569
2570 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002571 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002572 Phone phone = PhoneFactory.getPhone(slotIndex);
2573 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002574 return null;
2575 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002576
Jeff Davidson913390f2018-02-23 17:11:49 -08002577 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002578 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002579 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002580 return null;
2581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582
2583 final long identity = Binder.clearCallingIdentity();
2584 try {
2585 return phone.getMeid();
2586 } finally {
2587 Binder.restoreCallingIdentity(identity);
2588 }
Jack Yu2af8d712017-03-15 17:14:14 -07002589 }
2590
2591 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002592 public String getManufacturerCodeForSlot(int slotIndex) {
2593 Phone phone = PhoneFactory.getPhone(slotIndex);
2594 String manufacturerCode = null;
2595 if (phone != null) {
2596 String meid = phone.getMeid();
2597 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2598 }
2599 return manufacturerCode;
2600 }
2601
2602 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002603 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2604 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002605 Phone phone = PhoneFactory.getPhone(slotIndex);
2606 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002607 return null;
2608 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002609 int subId = phone.getSubId();
2610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002611 mApp, subId, callingPackage, callingFeatureId,
2612 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002613 return null;
2614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615
2616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 return phone.getDeviceSvn();
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
2621 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002622 }
2623
fionaxu43304da2017-11-27 22:51:16 -08002624 @Override
2625 public int getSubscriptionCarrierId(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 ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2630 } finally {
2631 Binder.restoreCallingIdentity(identity);
2632 }
fionaxu43304da2017-11-27 22:51:16 -08002633 }
2634
2635 @Override
2636 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 final Phone phone = getPhone(subId);
2640 return phone == null ? null : phone.getCarrierName();
2641 } finally {
2642 Binder.restoreCallingIdentity(identity);
2643 }
fionaxu43304da2017-11-27 22:51:16 -08002644 }
2645
calvinpanffe225e2018-11-01 19:43:06 +08002646 @Override
chen xu0026ca62019-03-06 15:28:50 -08002647 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002648 final long identity = Binder.clearCallingIdentity();
2649 try {
2650 final Phone phone = getPhone(subId);
2651 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002652 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002653 } finally {
2654 Binder.restoreCallingIdentity(identity);
2655 }
2656 }
2657
2658 @Override
chen xu0026ca62019-03-06 15:28:50 -08002659 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002660 final long identity = Binder.clearCallingIdentity();
2661 try {
2662 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002663 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002664 } finally {
2665 Binder.restoreCallingIdentity(identity);
2666 }
2667 }
2668
chen xu651eec72018-11-11 19:03:44 -08002669 @Override
chen xu864e11c2018-12-06 22:10:03 -08002670 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2671 if (!isSubscriptionMccMnc) {
2672 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2673 }
chen xu651eec72018-11-11 19:03:44 -08002674 final Phone phone = PhoneFactory.getPhone(slotIndex);
2675 if (phone == null) {
2676 return TelephonyManager.UNKNOWN_CARRIER_ID;
2677 }
2678 final long identity = Binder.clearCallingIdentity();
2679 try {
2680 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2681 } finally {
2682 Binder.restoreCallingIdentity(identity);
2683 }
2684 }
2685
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 //
2687 // Internal helper methods.
2688 //
2689
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002690 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2692 *
2693 * @throws SecurityException if the caller does not have the required permission
2694 */
2695 private void enforceModifyPermission() {
2696 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2697 }
2698
Shuo Qiancd19c462020-01-16 20:51:11 -08002699 /**
2700 * Make sure the caller is system.
2701 *
2702 * @throws SecurityException if the caller is not system.
2703 */
2704 private void enforceSystemCaller() {
2705 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2706 throw new SecurityException("Caller must be system");
2707 }
2708 }
2709
Shuo Qian3b6ee772019-11-13 17:43:31 -08002710 private void enforceActiveEmergencySessionPermission() {
2711 mApp.enforceCallingOrSelfPermission(
2712 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2713 }
2714
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 /**
2716 * Make sure the caller has the CALL_PHONE permission.
2717 *
2718 * @throws SecurityException if the caller does not have the required permission
2719 */
2720 private void enforceCallPermission() {
2721 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2722 }
2723
paulhu5a773602019-08-23 19:17:33 +08002724 private void enforceSettingsPermission() {
2725 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002726 }
2727
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002728 private String createTelUrl(String number) {
2729 if (TextUtils.isEmpty(number)) {
2730 return null;
2731 }
2732
Jake Hambye994d462014-02-03 13:10:13 -08002733 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 }
2735
Ihab Awadf9e92732013-12-05 18:02:52 -08002736 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2738 }
2739
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002740 private static void logv(String msg) {
2741 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2742 }
2743
Ihab Awadf9e92732013-12-05 18:02:52 -08002744 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2746 }
2747
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002748 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002749 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002750 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002751 }
2752
Sanket Padawe356d7632015-06-22 14:03:32 -07002753 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002754 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755 final long identity = Binder.clearCallingIdentity();
2756 try {
2757 final Phone phone = PhoneFactory.getPhone(slotIndex);
2758 if (phone == null) {
2759 return PhoneConstants.PHONE_TYPE_NONE;
2760 } else {
2761 return phone.getPhoneType();
2762 }
2763 } finally {
2764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002766 }
2767
2768 /**
2769 * Returns the CDMA ERI icon index to display
2770 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002771 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002772 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2773 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2774 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002775 }
2776
Sanket Padawe356d7632015-06-22 14:03:32 -07002777 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002778 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2779 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002781 mApp, subId, callingPackage, callingFeatureId,
2782 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002783 return -1;
2784 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785
2786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 final Phone phone = getPhone(subId);
2789 if (phone != null) {
2790 return phone.getCdmaEriIconIndex();
2791 } else {
2792 return -1;
2793 }
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 }
2798
2799 /**
2800 * Returns the CDMA ERI icon mode,
2801 * 0 - ON
2802 * 1 - FLASHING
2803 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002804 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002805 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2806 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2807 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002808 }
2809
Sanket Padawe356d7632015-06-22 14:03:32 -07002810 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002811 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2812 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002813 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002814 mApp, subId, callingPackage, callingFeatureId,
2815 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002816 return -1;
2817 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818
2819 final long identity = Binder.clearCallingIdentity();
2820 try {
2821 final Phone phone = getPhone(subId);
2822 if (phone != null) {
2823 return phone.getCdmaEriIconMode();
2824 } else {
2825 return -1;
2826 }
2827 } finally {
2828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002830 }
2831
2832 /**
2833 * Returns the CDMA ERI text,
2834 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002835 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002836 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2837 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2838 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002839 }
2840
Sanket Padawe356d7632015-06-22 14:03:32 -07002841 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002842 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2843 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002845 mApp, subId, callingPackage, callingFeatureId,
2846 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002847 return null;
2848 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849
2850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 final Phone phone = getPhone(subId);
2853 if (phone != null) {
2854 return phone.getCdmaEriText();
2855 } else {
2856 return null;
2857 }
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002861 }
2862
2863 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002864 * Returns the CDMA MDN.
2865 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002866 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002867 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2869 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002870
2871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002874 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002875 return phone.getLine1Number();
2876 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002877 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878 return null;
2879 }
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002882 }
2883 }
2884
2885 /**
2886 * Returns the CDMA MIN.
2887 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002888 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002889 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2891 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892
2893 final long identity = Binder.clearCallingIdentity();
2894 try {
2895 final Phone phone = getPhone(subId);
2896 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2897 return phone.getCdmaMin();
2898 } else {
2899 return null;
2900 }
2901 } finally {
2902 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002903 }
2904 }
2905
Hall Liud892bec2018-11-30 14:51:45 -08002906 @Override
2907 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2908 INumberVerificationCallback callback, String callingPackage) {
2909 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2910 != PERMISSION_GRANTED) {
2911 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2912 }
2913 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2914
2915 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2916 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2917 throw new SecurityException("Calling package must be configured in the device config");
2918 }
2919
2920 if (range == null) {
2921 throw new NullPointerException("Range must be non-null");
2922 }
2923
2924 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002925 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002926
2927 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2928 }
2929
Junda Liuca05d5d2014-08-14 22:36:34 -07002930 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 * Returns true if CDMA provisioning needs to run.
2932 */
2933 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934 final long identity = Binder.clearCallingIdentity();
2935 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002936 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 } finally {
2938 Binder.restoreCallingIdentity(identity);
2939 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002940 }
2941
2942 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002943 * Sets the voice mail number of a given subId.
2944 */
2945 @Override
2946 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002947 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2948 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002949
2950 final long identity = Binder.clearCallingIdentity();
2951 try {
2952 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2953 new Pair<String, String>(alphaTag, number), new Integer(subId));
2954 return success;
2955 } finally {
2956 Binder.restoreCallingIdentity(identity);
2957 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002958 }
2959
Ta-wei Yen87c49842016-05-13 21:19:52 -07002960 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002961 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2962 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002963 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2964 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002965 if (!TextUtils.equals(callingPackage, systemDialer)) {
2966 throw new SecurityException("caller must be system dialer");
2967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002968
2969 final long identity = Binder.clearCallingIdentity();
2970 try {
2971 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2972 if (phoneAccountHandle == null) {
2973 return null;
2974 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002975 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976 } finally {
2977 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002978 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002979 }
2980
2981 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002982 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2983 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002984 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002986 mApp, subId, callingPackage, callingFeatureId,
2987 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002988 return null;
2989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002991 final long identity = Binder.clearCallingIdentity();
2992 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002993 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002994 } finally {
2995 Binder.restoreCallingIdentity(identity);
2996 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002997 }
2998
2999 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003000 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3001 VisualVoicemailSmsFilterSettings settings) {
3002 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003
3004 final long identity = Binder.clearCallingIdentity();
3005 try {
3006 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003007 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003011 }
3012
3013 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003014 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016
3017 final long identity = Binder.clearCallingIdentity();
3018 try {
3019 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003020 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021 } finally {
3022 Binder.restoreCallingIdentity(identity);
3023 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003024 }
3025
3026 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003027 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3028 String callingPackage, int subId) {
3029 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030
3031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003034 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003035 } finally {
3036 Binder.restoreCallingIdentity(identity);
3037 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003038 }
3039
3040 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003041 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003042 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043
3044 final long identity = Binder.clearCallingIdentity();
3045 try {
3046 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003047 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048 } finally {
3049 Binder.restoreCallingIdentity(identity);
3050 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003051 }
3052
3053 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003054 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3055 String callingAttributionTag, int subId, String number, int port, String text,
3056 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003057 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003058 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003059 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003060 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003061 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3062 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003063 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003064
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003065 /**
fionaxu0152e512016-11-14 13:36:14 -08003066 * Sets the voice activation state of a given subId.
3067 */
3068 @Override
3069 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3071 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003072
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 final Phone phone = getPhone(subId);
3076 if (phone != null) {
3077 phone.setVoiceActivationState(activationState);
3078 } else {
3079 loge("setVoiceActivationState fails with invalid subId: " + subId);
3080 }
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003083 }
3084 }
3085
3086 /**
3087 * Sets the data activation state of a given subId.
3088 */
3089 @Override
3090 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3092 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003093
3094 final long identity = Binder.clearCallingIdentity();
3095 try {
3096 final Phone phone = getPhone(subId);
3097 if (phone != null) {
3098 phone.setDataActivationState(activationState);
3099 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003100 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101 }
3102 } finally {
3103 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003104 }
3105 }
3106
3107 /**
3108 * Returns the voice activation state of a given subId.
3109 */
3110 @Override
3111 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003112 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113
fionaxu0152e512016-11-14 13:36:14 -08003114 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 if (phone != null) {
3118 return phone.getVoiceActivationState();
3119 } else {
3120 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3121 }
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003124 }
3125 }
3126
3127 /**
3128 * Returns the data activation state of a given subId.
3129 */
3130 @Override
3131 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003132 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003133
fionaxu0152e512016-11-14 13:36:14 -08003134 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 if (phone != null) {
3138 return phone.getDataActivationState();
3139 } else {
3140 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3141 }
3142 } finally {
3143 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003144 }
3145 }
3146
3147 /**
Wink Saville36469e72014-06-11 15:17:00 -07003148 * Returns the unread count of voicemails for a subId
3149 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003150 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003151 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3152 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003154 mApp, subId, callingPackage, callingFeatureId,
3155 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003156 return 0;
3157 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003158 final long identity = Binder.clearCallingIdentity();
3159 try {
3160 final Phone phone = getPhone(subId);
3161 if (phone != null) {
3162 return phone.getVoiceMessageCount();
3163 } else {
3164 return 0;
3165 }
3166 } finally {
3167 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003169 }
3170
3171 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003172 * returns true, if the device is in a state where both voice and data
3173 * are supported simultaneously. This can change based on location or network condition.
3174 */
3175 @Override
3176 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003177 final long identity = Binder.clearCallingIdentity();
3178 try {
3179 final Phone phone = getPhone(subId);
3180 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3181 } finally {
3182 Binder.restoreCallingIdentity(identity);
3183 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003184 }
3185
3186 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003187 * Send the dialer code if called from the current default dialer or the caller has
3188 * carrier privilege.
3189 * @param inputCode The dialer code to send
3190 */
3191 @Override
3192 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003193 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003194 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003195 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3196 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003197 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003198 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003199 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003200 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201
3202 final long identity = Binder.clearCallingIdentity();
3203 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003204 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 } finally {
3206 Binder.restoreCallingIdentity(identity);
3207 }
fionaxu235cc5e2017-03-06 22:25:57 -08003208 }
3209
Pengquan Menga1bb6272018-09-06 09:59:22 -07003210 @Override
3211 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003212 TelephonyPermissions
3213 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3214 mApp, subId, "getNetworkSelectionMode");
3215 final long identity = Binder.clearCallingIdentity();
3216 try {
3217 if (!isActiveSubscription(subId)) {
3218 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3219 }
3220 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3221 } finally {
3222 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003223 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003224 }
3225
Brad Ebinger35c841c2018-10-01 10:40:55 -07003226 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003227 public boolean isInEmergencySmsMode() {
3228 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3229 final long identity = Binder.clearCallingIdentity();
3230 try {
3231 for (Phone phone : PhoneFactory.getPhones()) {
3232 if (phone.isInEmergencySmsMode()) {
3233 return true;
3234 }
3235 }
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
3238 }
3239 return false;
3240 }
3241
shilu366312e2019-12-17 09:28:10 -08003242 /**
3243 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3244 * @param subId The subscription to use to check the configuration.
3245 * @param c The callback that will be used to send the result.
3246 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003247 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003248 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3249 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003250 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3251 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003252
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003253 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3254 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3255 "IMS not available on device.");
3256 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003257 final long token = Binder.clearCallingIdentity();
3258 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003259 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003260 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003261 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003262 } catch (ImsException e) {
3263 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003264 } finally {
3265 Binder.restoreCallingIdentity(token);
3266 }
3267 }
3268
shilu366312e2019-12-17 09:28:10 -08003269 /**
3270 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3271 * @param subId The subscription to use to check the configuration.
3272 * @param c The callback that will be used to send the result.
3273 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003275 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003276 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3277 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003278 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3279 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3280 }
Meng Wangafbc5852019-09-19 17:37:13 -07003281 final long token = Binder.clearCallingIdentity();
3282 try {
3283 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3284 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3285 .removeRegistrationCallbackForSubscription(c, subId);
3286 } catch (ImsException e) {
3287 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3288 + "is inactive, ignoring unregister.");
3289 // If the subscription is no longer active, just return, since the callback
3290 // will already have been removed internally.
3291 } finally {
3292 Binder.restoreCallingIdentity(token);
3293 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003294 }
3295
Brad Ebingera34a6c22019-10-22 17:36:18 -07003296 /**
3297 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3298 */
3299 @Override
3300 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3301 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3302 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3303 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3304 "IMS not available on device.");
3305 }
3306 final long token = Binder.clearCallingIdentity();
3307 try {
3308 Phone phone = getPhone(subId);
3309 if (phone == null) {
3310 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3311 + subId + "'");
3312 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3313 }
3314 phone.getImsRegistrationState(regState -> {
3315 try {
3316 consumer.accept((regState == null)
3317 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3318 } catch (RemoteException e) {
3319 // Ignore if the remote process is no longer available to call back.
3320 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3321 }
3322 });
3323 } finally {
3324 Binder.restoreCallingIdentity(token);
3325 }
3326 }
3327
3328 /**
3329 * Get the transport type for the IMS service registration state.
3330 */
3331 @Override
3332 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003333 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3334 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003335 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3336 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3337 "IMS not available on device.");
3338 }
3339 final long token = Binder.clearCallingIdentity();
3340 try {
3341 Phone phone = getPhone(subId);
3342 if (phone == null) {
3343 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3344 + subId + "'");
3345 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3346 }
3347 phone.getImsRegistrationTech(regTech -> {
3348 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3349 int regTechConverted = (regTech == null)
3350 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3351 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3352 regTechConverted);
3353 try {
3354 consumer.accept(regTechConverted);
3355 } catch (RemoteException e) {
3356 // Ignore if the remote process is no longer available to call back.
3357 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3358 }
3359 });
3360 } finally {
3361 Binder.restoreCallingIdentity(token);
3362 }
3363 }
3364
shilu366312e2019-12-17 09:28:10 -08003365 /**
3366 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3367 * @param subId The subscription to use to check the configuration.
3368 * @param c The callback that will be used to send the result.
3369 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003370 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003371 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3372 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003373 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3374 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003375 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3376 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3377 "IMS not available on device.");
3378 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003379 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3380 final long token = Binder.clearCallingIdentity();
3381 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003382 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003384 } catch (ImsException e) {
3385 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003386 } finally {
3387 Binder.restoreCallingIdentity(token);
3388 }
3389 }
3390
shilu366312e2019-12-17 09:28:10 -08003391 /**
3392 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3393 * @param subId The subscription to use to check the configuration.
3394 * @param c The callback that will be used to send the result.
3395 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003396 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003397 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003398 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3399 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003400 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3401 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3402 }
Meng Wangafbc5852019-09-19 17:37:13 -07003403
3404 final long token = Binder.clearCallingIdentity();
3405 try {
3406 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3407 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003408 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003409 } catch (ImsException e) {
3410 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3411 + "is inactive, ignoring unregister.");
3412 // If the subscription is no longer active, just return, since the callback
3413 // will already have been removed internally.
3414 } finally {
3415 Binder.restoreCallingIdentity(token);
3416 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003417 }
3418
3419 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003420 public boolean isCapable(int subId, int capability, int regTech) {
3421 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003422 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3423 final long token = Binder.clearCallingIdentity();
3424 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003425 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003427 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003428 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3429 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003430 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003431 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3432 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003433 } finally {
3434 Binder.restoreCallingIdentity(token);
3435 }
3436 }
3437
3438 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003439 public boolean isAvailable(int subId, int capability, int regTech) {
3440 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003441 final long token = Binder.clearCallingIdentity();
3442 try {
3443 Phone phone = getPhone(subId);
3444 if (phone == null) return false;
3445 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003446 } catch (com.android.ims.ImsException e) {
3447 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3448 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003449 } finally {
3450 Binder.restoreCallingIdentity(token);
3451 }
3452 }
3453
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003454 /**
3455 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3456 * subscription.
3457 * @param subId The subscription to use to check the configuration.
3458 * @param callback The callback that will be used to send the result.
3459 * @param capability The MmTelFeature capability that will be used to send the result.
3460 * @param transportType The transport type of the MmTelFeature capability.
3461 */
3462 @Override
3463 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3464 int transportType) {
3465 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3466 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3467 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3468 "IMS not available on device.");
3469 }
3470 final long token = Binder.clearCallingIdentity();
3471 try {
3472 int slotId = getSlotIndex(subId);
3473 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3474 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3475 + subId + "'");
3476 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3477 }
3478 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3479 transportType, aBoolean -> {
3480 try {
3481 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3482 } catch (RemoteException e) {
3483 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3484 + "running. Ignore");
3485 }
3486 });
3487 } finally {
3488 Binder.restoreCallingIdentity(token);
3489 }
3490 }
3491
shilu366312e2019-12-17 09:28:10 -08003492 /**
3493 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3494 * @param subId The subscription to use to check the configuration.
3495 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003496 @Override
3497 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003498 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3499 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003500
Brad Ebinger35c841c2018-10-01 10:40:55 -07003501 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3502 final long token = Binder.clearCallingIdentity();
3503 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003504 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003505 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003506 } catch (ImsException e) {
3507 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003508 } finally {
3509 Binder.restoreCallingIdentity(token);
3510 }
3511 }
3512
3513 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003514 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003516 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003517 final long identity = Binder.clearCallingIdentity();
3518 try {
3519 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003520 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003521 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003522 } catch (ImsException e) {
3523 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003524 } finally {
3525 Binder.restoreCallingIdentity(identity);
3526 }
3527 }
3528
shilu366312e2019-12-17 09:28:10 -08003529 /**
3530 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3531 * @param subId The subscription to use to check the configuration.
3532 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003533 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003534 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003535 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3536 mApp, subId, "isVtSettingEnabled");
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.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003540 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3541 } 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
3548 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003549 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003551 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003555 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003556 } catch (ImsException e) {
3557 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003558 } finally {
3559 Binder.restoreCallingIdentity(identity);
3560 }
3561 }
3562
shilu366312e2019-12-17 09:28:10 -08003563 /**
3564 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3565 * @param subId The subscription to use to check the configuration.
3566 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003567 @Override
3568 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003569 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3570 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003571 final long identity = Binder.clearCallingIdentity();
3572 try {
3573 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003574 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 getSlotIndexOrException(subId)).isWfcEnabledByUser();
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
3583 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003584 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003586 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003587 final long identity = Binder.clearCallingIdentity();
3588 try {
3589 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003590 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003591 } catch (ImsException e) {
3592 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003593 } finally {
3594 Binder.restoreCallingIdentity(identity);
3595 }
3596 }
3597
shilu366312e2019-12-17 09:28:10 -08003598 /**
3599 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3600 * @param subId The subscription to use to check the configuration.
3601 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 @Override
3603 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003604 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3605 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003609 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003610 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003611 } catch (ImsException e) {
3612 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003613 } finally {
3614 Binder.restoreCallingIdentity(identity);
3615 }
3616 }
3617
3618 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003619 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003621 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003625 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003626 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003627 } catch (ImsException e) {
3628 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003629 } finally {
3630 Binder.restoreCallingIdentity(identity);
3631 }
3632 }
3633
3634 @Override
3635 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3637 "setVoWiFiNonPersistent");
3638 final long identity = Binder.clearCallingIdentity();
3639 try {
3640 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003641 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003642 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003643 } catch (ImsException e) {
3644 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003645 } finally {
3646 Binder.restoreCallingIdentity(identity);
3647 }
3648 }
3649
shilu366312e2019-12-17 09:28:10 -08003650 /**
3651 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3652 * @param subId The subscription to use to check the configuration.
3653 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003654 @Override
3655 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003656 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3657 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003661 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003662 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003663 } catch (ImsException e) {
3664 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003665 } finally {
3666 Binder.restoreCallingIdentity(identity);
3667 }
3668 }
3669
3670 @Override
3671 public void setVoWiFiModeSetting(int subId, int mode) {
3672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3673 "setVoWiFiModeSetting");
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 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003678 getSlotIndexOrException(subId)).setWfcMode(mode, false /*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 int getVoWiFiRoamingModeSetting(int subId) {
3688 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003692 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003693 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003694 } catch (ImsException e) {
3695 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003696 } finally {
3697 Binder.restoreCallingIdentity(identity);
3698 }
3699 }
3700
3701 @Override
3702 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3704 "setVoWiFiRoamingModeSetting");
3705 final long identity = Binder.clearCallingIdentity();
3706 try {
3707 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003708 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003709 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003710 } 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
3717 @Override
3718 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3720 "setRttCapabilityEnabled");
3721 final long identity = Binder.clearCallingIdentity();
3722 try {
3723 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003724 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3725 } catch (ImsException e) {
3726 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
3730 }
3731
shilu366312e2019-12-17 09:28:10 -08003732 /**
3733 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3734 * @param subId The subscription to use to check the configuration.
3735 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003736 @Override
3737 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003738 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3739 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003743 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003744 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003745 } catch (ImsException e) {
3746 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
3750 }
3751
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003752 @Override
3753 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3754 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3755 final long identity = Binder.clearCallingIdentity();
3756 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003757 if (!isImsAvailableOnDevice()) {
3758 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3759 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003760 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003761 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003762 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003763 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003764 } catch (ImsException e) {
3765 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003766 } finally {
3767 Binder.restoreCallingIdentity(identity);
3768 }
3769 }
3770
3771 @Override
3772 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3773 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3774 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003775 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3776 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3777 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003778 try {
3779 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003780 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003781 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003782 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003783 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3784 + "is inactive, ignoring unregister.");
3785 // If the subscription is no longer active, just return, since the callback will already
3786 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003787 } finally {
3788 Binder.restoreCallingIdentity(identity);
3789 }
3790 }
3791
allenwtsu99c623b2020-01-03 18:24:23 +08003792
3793 private void checkModifyPhoneStatePermission(int subId, String message) {
3794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3795 message);
3796 }
3797
3798 private boolean isImsProvisioningRequired(int subId, int capability,
3799 boolean isMmtelCapability) {
3800 Phone phone = getPhone(subId);
3801 if (phone == null) {
3802 loge("phone instance null for subid " + subId);
3803 return false;
3804 }
3805 if (isMmtelCapability) {
3806 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3807 return false;
3808 }
3809 } else {
3810 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3811 return false;
3812 }
3813 }
3814 return true;
3815 }
3816
3817 @Override
3818 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3819 boolean isProvisioned) {
3820 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3821
3822 final long identity = Binder.clearCallingIdentity();
3823 try {
3824 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3825 if (!isImsProvisioningRequired(subId, capability, false)) {
3826 return;
3827 }
3828
3829 // this capability requires provisioning, route to the correct API.
3830 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3831 switch (capability) {
3832 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3833 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3834 ims.setEabProvisioned(isProvisioned);
3835 break;
3836 default: {
3837 throw new IllegalArgumentException("Tried to set provisioning for "
3838 + "rcs capability '" + capability + "', which does not require "
3839 + "provisioning.");
3840 }
3841 }
3842 } finally {
3843 Binder.restoreCallingIdentity(identity);
3844 }
3845
3846 }
3847
3848
3849 @Override
3850 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3851 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3852 final long identity = Binder.clearCallingIdentity();
3853 try {
3854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3855 if (!isImsProvisioningRequired(subId, capability, false)) {
3856 return true;
3857 }
3858
3859 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3860 switch (capability) {
3861 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3862 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3863 return ims.isEabProvisionedOnDevice();
3864
3865 default: {
3866 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3867 + "capability '" + capability + "', which does not require "
3868 + "provisioning.");
3869 }
3870 }
3871
3872 } finally {
3873 Binder.restoreCallingIdentity(identity);
3874 }
3875 }
3876
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003877 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003878 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3879 boolean isProvisioned) {
3880 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3881 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3882 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3883 }
allenwtsu99c623b2020-01-03 18:24:23 +08003884 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003885 final long identity = Binder.clearCallingIdentity();
3886 try {
3887 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003888 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003889 return;
3890 }
3891
3892 // this capability requires provisioning, route to the correct API.
3893 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3894 switch (capability) {
3895 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3896 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3897 ims.setVolteProvisioned(isProvisioned);
3898 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3899 ims.setWfcProvisioned(isProvisioned);
3900 }
3901 break;
3902 }
3903 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3904 // There is currently no difference in VT provisioning type.
3905 ims.setVtProvisioned(isProvisioned);
3906 break;
3907 }
3908 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3909 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3910 // change the capability of the feature instead if needed.
3911 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3912 == isProvisioned) {
3913 // No change in provisioning.
3914 return;
3915 }
3916 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3917 try {
3918 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003919 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003920 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3921 + ", Exception" + e.getMessage());
3922 }
3923 break;
3924 }
3925 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003926 throw new IllegalArgumentException("Tried to set provisioning for "
3927 + "MmTel capability '" + capability + "', which does not require "
3928 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003929 }
3930 }
3931
3932 } finally {
3933 Binder.restoreCallingIdentity(identity);
3934 }
3935 }
3936
3937 @Override
3938 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3939 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3940 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3941 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3942 }
3943 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3944 final long identity = Binder.clearCallingIdentity();
3945 try {
3946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003947 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003948 return true;
3949 }
3950
3951 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3952 switch (capability) {
3953 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3954 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3955 return ims.isVolteProvisionedOnDevice();
3956 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3957 return ims.isWfcProvisionedOnDevice();
3958 }
3959 // This should never happen, since we are checking tech above to make sure it
3960 // is either LTE or IWLAN.
3961 throw new IllegalArgumentException("Invalid radio technology for voice "
3962 + "capability.");
3963 }
3964 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3965 // There is currently no difference in VT provisioning type.
3966 return ims.isVtProvisionedOnDevice();
3967 }
3968 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3969 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3970 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3971 }
3972 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003973 throw new IllegalArgumentException(
3974 "Tried to get provisioning for MmTel capability '" + capability
3975 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003976 }
3977 }
3978
3979 } finally {
3980 Binder.restoreCallingIdentity(identity);
3981 }
3982 }
3983
3984 @Override
3985 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3986 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3987 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3988 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3989 }
3990 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3991 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3992 return (provisionedBits & capability) > 0;
3993 }
3994
3995 @Override
3996 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3997 boolean isProvisioned) {
3998 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3999 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4000 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4001 }
4002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4003 "setProvisioningStatusForCapability");
4004 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4005 // If the current provisioning status for capability already matches isProvisioned,
4006 // do nothing.
4007 if (((provisionedBits & capability) > 0) == isProvisioned) {
4008 return;
4009 }
4010 if (isProvisioned) {
4011 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4012 } else {
4013 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4014 }
4015 }
4016
4017 /**
4018 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4019 * technology. The bitfield should mirror the bitfield defined by
4020 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4021 */
4022 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4023 String key = getMmTelProvisioningKey(subId, tech);
4024 // Default is no capabilities are provisioned.
4025 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4026 }
4027
4028 /**
4029 * Sets the MmTel capability provisioning bitfield (defined by
4030 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4031 * technology specified.
4032 *
4033 * Note: This is a synchronous command and should not be called on UI thread.
4034 */
4035 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4036 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4037 String key = getMmTelProvisioningKey(subId, tech);
4038 editor.putInt(key, newField);
4039 editor.commit();
4040 }
4041
4042 private static String getMmTelProvisioningKey(int subId, int tech) {
4043 // resulting key is provision_ims_mmtel_{subId}_{tech}
4044 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4045 }
4046
4047 /**
4048 * Query CarrierConfig to see if the specified capability requires provisioning for the
4049 * carrier associated with the subscription id.
4050 */
4051 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4052 int capability) {
4053 CarrierConfigManager configManager = new CarrierConfigManager(context);
4054 PersistableBundle c = configManager.getConfigForSubId(subId);
4055 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004056 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004057 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4058 false);
4059 boolean requireVoiceVtProvisioning = c.getBoolean(
4060 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4061
4062 // First check to make sure that the capability requires provisioning.
4063 switch (capability) {
4064 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4065 // intentional fallthrough
4066 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4067 if (requireVoiceVtProvisioning) {
4068 // Voice and Video requires provisioning
4069 return true;
4070 }
4071 break;
4072 }
4073 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4074 if (requireUtProvisioning) {
4075 // UT requires provisioning
4076 return true;
4077 }
4078 break;
4079 }
4080 }
4081 return false;
4082 }
4083
allenwtsu99c623b2020-01-03 18:24:23 +08004084 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4085 int capability) {
4086 CarrierConfigManager configManager = new CarrierConfigManager(context);
4087 PersistableBundle c = configManager.getConfigForSubId(subId);
4088
4089 boolean requireRcsProvisioning = c.getBoolean(
4090 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4091
4092 // First check to make sure that the capability requires provisioning.
4093 switch (capability) {
4094 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4095 // intentional fallthrough
4096 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4097 if (requireRcsProvisioning) {
4098 // OPTION or PRESENCE requires provisioning
4099 return true;
4100 }
4101 break;
4102 }
4103 }
4104 return false;
4105 }
4106
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004107 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004108 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004109 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4110 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4111 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004112 enforceReadPrivilegedPermission("getImsProvisioningInt");
4113 final long identity = Binder.clearCallingIdentity();
4114 try {
4115 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004116 int slotId = getSlotIndex(subId);
4117 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4118 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4119 + subId + "' for key:" + key);
4120 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4121 }
4122 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004123 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004124 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4125 + subId + "' for key:" + key);
4126 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004127 } finally {
4128 Binder.restoreCallingIdentity(identity);
4129 }
4130 }
4131
4132 @Override
4133 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004134 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4135 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4136 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004137 enforceReadPrivilegedPermission("getImsProvisioningString");
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004141 int slotId = getSlotIndex(subId);
4142 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4143 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4144 + subId + "' for key:" + key);
4145 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4146 }
4147 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004148 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004149 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4150 + subId + "' for key:" + key);
4151 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004152 } finally {
4153 Binder.restoreCallingIdentity(identity);
4154 }
4155 }
4156
4157 @Override
4158 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004159 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4160 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4161 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4163 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004164 final long identity = Binder.clearCallingIdentity();
4165 try {
4166 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004167 int slotId = getSlotIndex(subId);
4168 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4169 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4170 + subId + "' for key:" + key);
4171 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4172 }
4173 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004174 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004175 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4176 + "' for key:" + key);
4177 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004178 } finally {
4179 Binder.restoreCallingIdentity(identity);
4180 }
4181 }
4182
4183 @Override
4184 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004185 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4186 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4187 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4189 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004190 final long identity = Binder.clearCallingIdentity();
4191 try {
4192 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004193 int slotId = getSlotIndex(subId);
4194 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4195 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4196 + subId + "' for key:" + key);
4197 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4198 }
4199 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004200 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004201 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4202 + "' for key:" + key);
4203 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004204 } finally {
4205 Binder.restoreCallingIdentity(identity);
4206 }
4207 }
4208
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004209 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 int slotId = SubscriptionManager.getSlotIndex(subId);
4211 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004212 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4213 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 }
4215 return slotId;
4216 }
4217
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004218 private int getSlotIndex(int subId) {
4219 int slotId = SubscriptionManager.getSlotIndex(subId);
4220 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4221 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4222 }
4223 return slotId;
4224 }
4225
Wink Saville36469e72014-06-11 15:17:00 -07004226 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004227 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004228 */
4229 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004230 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4231 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004232 final int targetSdk = getTargetSdk(callingPackage);
4233 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004234 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004235 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004236 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004237 mApp, subId, callingPackage, callingFeatureId,
4238 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004239 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4240 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004242 final long identity = Binder.clearCallingIdentity();
4243 try {
4244 final Phone phone = getPhone(subId);
4245 if (phone != null) {
4246 return phone.getServiceState().getDataNetworkType();
4247 } else {
4248 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4249 }
4250 } finally {
4251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004253 }
4254
4255 /**
4256 * Returns the data network type
4257 */
4258 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004259 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4260 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4261 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004262 }
4263
4264 /**
4265 * Returns the data network type for a subId
4266 */
4267 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004268 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4269 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004271 mApp, subId, callingPackage, callingFeatureId,
4272 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004273 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4274 }
4275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 final Phone phone = getPhone(subId);
4279 if (phone != null) {
4280 return phone.getServiceState().getDataNetworkType();
4281 } else {
4282 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4283 }
4284 } finally {
4285 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004287 }
4288
4289 /**
Wink Saville36469e72014-06-11 15:17:00 -07004290 * Returns the Voice network type for a subId
4291 */
4292 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004293 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4294 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004295 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004296 mApp, subId, callingPackage, callingFeatureId,
4297 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004298 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4299 }
4300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004301 final long identity = Binder.clearCallingIdentity();
4302 try {
4303 final Phone phone = getPhone(subId);
4304 if (phone != null) {
4305 return phone.getServiceState().getVoiceNetworkType();
4306 } else {
4307 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4308 }
4309 } finally {
4310 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004312 }
4313
4314 /**
4315 * @return true if a ICC card is present
4316 */
4317 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004318 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004319 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4320 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004321 }
4322
4323 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004324 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004325 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004326 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004327 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 final Phone phone = PhoneFactory.getPhone(slotIndex);
4331 if (phone != null) {
4332 return phone.getIccCard().hasIccCard();
4333 } else {
4334 return false;
4335 }
4336 } finally {
4337 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004339 }
4340
4341 /**
4342 * Return if the current radio is LTE on CDMA. This
4343 * is a tri-state return value as for a period of time
4344 * the mode may be unknown.
4345 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004346 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004347 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004348 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004349 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004350 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004351 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4352 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4353 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004354 }
4355
Sanket Padawe356d7632015-06-22 14:03:32 -07004356 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004357 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4358 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004359 try {
4360 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4361 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004362 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4363 }
4364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004365 final long identity = Binder.clearCallingIdentity();
4366 try {
4367 final Phone phone = getPhone(subId);
4368 if (phone == null) {
4369 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4370 } else {
4371 return phone.getLteOnCdmaMode();
4372 }
4373 } finally {
4374 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004375 }
Wink Saville36469e72014-06-11 15:17:00 -07004376 }
4377
Wink Saville36469e72014-06-11 15:17:00 -07004378 /**
4379 * {@hide}
4380 * Returns Default subId, 0 in the case of single standby.
4381 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004382 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004383 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004384 }
4385
Shishir Agrawala9f32182016-04-12 12:00:16 -07004386 private int getSlotForDefaultSubscription() {
4387 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4388 }
4389
Wink Savilleb564aae2014-10-23 10:18:09 -07004390 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004391 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004392 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004393
Pengquan Menge92a50d2018-09-21 15:54:48 -07004394 private boolean isActiveSubscription(int subId) {
4395 return mSubscriptionController.isActiveSubId(subId);
4396 }
4397
Ihab Awadf2177b72013-11-25 13:33:23 -08004398 /**
4399 * @see android.telephony.TelephonyManager.WifiCallingChoices
4400 */
4401 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 final long identity = Binder.clearCallingIdentity();
4403 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004404 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4406 getWhenToMakeWifiCallsDefaultPreference());
4407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004410 }
4411
4412 /**
4413 * @see android.telephony.TelephonyManager.WifiCallingChoices
4414 */
4415 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004416 final long identity = Binder.clearCallingIdentity();
4417 try {
4418 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004419 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4421 } finally {
4422 Binder.restoreCallingIdentity(identity);
4423 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004424 }
4425
Sailesh Nepald1e68152013-12-12 19:08:02 -08004426 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004427 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004428 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004429 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004430
Jordan Liu4c733742019-02-28 12:03:40 -08004431 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4432 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4433 if (phoneId == -1) {
4434 throw new IllegalArgumentException("Given slot index: " + slotIndex
4435 + " does not correspond to an active phone");
4436 }
4437 return PhoneFactory.getPhone(phoneId);
4438 }
4439
Shishir Agrawal566b7612013-10-28 14:41:00 -07004440 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004441 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4442 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4444 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004446 if (DBG) {
4447 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4448 }
4449 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4450 p2);
4451 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004452
Jordan Liu4c733742019-02-28 12:03:40 -08004453
4454 @Override
4455 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4456 int slotIndex, String callingPackage, String aid, int p2) {
4457 enforceModifyPermission();
4458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4459 if (DBG) {
4460 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4461 }
4462 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4463 callingPackage, aid, p2);
4464 }
4465
4466 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4467 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004468 final long identity = Binder.clearCallingIdentity();
4469 try {
4470 if (TextUtils.equals(ISDR_AID, aid)) {
4471 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004472 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4473 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474 if (bestComponent == null
4475 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4476 loge("The calling package is not allowed to access ISD-R.");
4477 throw new SecurityException(
4478 "The calling package is not allowed to access ISD-R.");
4479 }
Derek Tan740e1672017-06-27 14:56:27 -07004480 }
Derek Tan740e1672017-06-27 14:56:27 -07004481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004483 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4484 null /* workSource */);
4485 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004486 return response;
4487 } finally {
4488 Binder.restoreCallingIdentity(identity);
4489 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004490 }
4491
4492 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004493 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4495 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004496 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4497 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4498 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004499
Jordan Liu4c733742019-02-28 12:03:40 -08004500 @Override
4501 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4502 enforceModifyPermission();
4503 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4504 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4505 channel);
4506 }
4507
4508 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004509 final long identity = Binder.clearCallingIdentity();
4510 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004511 if (channel < 0) {
4512 return false;
4513 }
Jordan Liu4c733742019-02-28 12:03:40 -08004514 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4515 null /* workSource */);
4516 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517 return success;
4518 } finally {
4519 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004520 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004521 }
4522
4523 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004524 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004525 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4527 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004528 if (DBG) {
4529 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4530 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4531 + p3 + " data=" + data);
4532 }
4533 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4534 command, p1, p2, p3, data);
4535 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004536
Jordan Liu4c733742019-02-28 12:03:40 -08004537 @Override
4538 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4539 int command, int p1, int p2, int p3, String data) {
4540 enforceModifyPermission();
4541 if (DBG) {
4542 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4543 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4544 + p3 + " data=" + data);
4545 }
4546 return iccTransmitApduLogicalChannelWithPermission(
4547 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4548 data);
4549 }
4550
4551 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4552 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 final long identity = Binder.clearCallingIdentity();
4554 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004555 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556 return "";
4557 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004560 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4561 null /* workSource */);
4562 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004564 // Append the returned status code to the end of the response payload.
4565 String s = Integer.toHexString(
4566 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4567 if (response.payload != null) {
4568 s = IccUtils.bytesToHexString(response.payload) + s;
4569 }
4570 return s;
4571 } finally {
4572 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004573 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004574 }
Jake Hambye994d462014-02-03 13:10:13 -08004575
Evan Charltonc66da362014-05-16 14:06:40 -07004576 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004577 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4578 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4580 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004582 if (DBG) {
4583 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4584 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4585 }
4586 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4587 cla, command, p1, p2, p3, data);
4588 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004589
Jordan Liu4c733742019-02-28 12:03:40 -08004590 @Override
4591 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4592 int command, int p1, int p2, int p3, String data) {
4593 enforceModifyPermission();
4594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4595 if (DBG) {
4596 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4597 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4598 + " data=" + data);
4599 }
4600
4601 return iccTransmitApduBasicChannelWithPermission(
4602 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4603 p2, p3, data);
4604 }
4605
4606 // open APDU basic channel assuming the caller has sufficient permissions
4607 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4608 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004609 final long identity = Binder.clearCallingIdentity();
4610 try {
4611 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4612 && TextUtils.equals(ISDR_AID, data)) {
4613 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004614 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4615 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616 if (bestComponent == null
4617 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4618 loge("The calling package is not allowed to select ISD-R.");
4619 throw new SecurityException(
4620 "The calling package is not allowed to select ISD-R.");
4621 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004622 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004623
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004625 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4626 null /* workSource */);
4627 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629 // Append the returned status code to the end of the response payload.
4630 String s = Integer.toHexString(
4631 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4632 if (response.payload != null) {
4633 s = IccUtils.bytesToHexString(response.payload) + s;
4634 }
4635 return s;
4636 } finally {
4637 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004638 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004639 }
4640
4641 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004642 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004643 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4645 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004647 final long identity = Binder.clearCallingIdentity();
4648 try {
4649 if (DBG) {
4650 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4651 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4652 }
4653
4654 IccIoResult response =
4655 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4656 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4657 subId);
4658
4659 if (DBG) {
4660 log("Exchange SIM_IO [R]" + response);
4661 }
4662
4663 byte[] result = null;
4664 int length = 2;
4665 if (response.payload != null) {
4666 length = 2 + response.payload.length;
4667 result = new byte[length];
4668 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4669 } else {
4670 result = new byte[length];
4671 }
4672
4673 result[length - 1] = (byte) response.sw2;
4674 result[length - 2] = (byte) response.sw1;
4675 return result;
4676 } finally {
4677 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004678 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004679 }
4680
Nathan Haroldb3014052017-01-25 15:57:32 -08004681 /**
4682 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4683 * on a particular subscription
4684 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004685 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4686 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004687 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004688 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004689 return null;
4690 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691
4692 final long identity = Binder.clearCallingIdentity();
4693 try {
4694 if (appType != TelephonyManager.APPTYPE_USIM
4695 && appType != TelephonyManager.APPTYPE_SIM) {
4696 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4697 return null;
4698 }
4699 Object response = sendRequest(
4700 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4701 if (response instanceof String[]) {
4702 return (String[]) response;
4703 }
yincheng zhao2737e882019-09-06 17:06:54 -07004704 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004706 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004707 } finally {
4708 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004709 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004710 }
4711
yincheng zhao2737e882019-09-06 17:06:54 -07004712 /**
4713 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4714 * subscription.
4715 *
4716 * @param subId the id of the subscription.
4717 * @param appType the uicc app type, must be USIM or SIM.
4718 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4719 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004720 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004721 * @return number of fplmns that is successfully written to the SIM.
4722 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004723 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4724 String callingFeatureId) {
4725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4726 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004727 if (DBG) logv("no permissions for setForbiddenplmns");
4728 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4729 }
4730 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4731 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4732 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4733 }
4734 if (fplmns == null) {
4735 throw new IllegalArgumentException("Fplmn List provided is null");
4736 }
4737 for (String fplmn : fplmns) {
4738 if (!CellIdentity.isValidPlmn(fplmn)) {
4739 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4740 }
4741 }
4742 final long identity = Binder.clearCallingIdentity();
4743 try {
4744 Object response = sendRequest(
4745 CMD_SET_FORBIDDEN_PLMNS,
4746 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4747 subId);
4748 return (int) response;
4749 } finally {
4750 Binder.restoreCallingIdentity(identity);
4751 }
4752 }
4753
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004754 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004755 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4757 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 final long identity = Binder.clearCallingIdentity();
4760 try {
4761 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4762 if (response.payload == null) {
4763 return "";
4764 }
Evan Charltonc66da362014-05-16 14:06:40 -07004765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004766 // Append the returned status code to the end of the response payload.
4767 String s = Integer.toHexString(
4768 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4769 s = IccUtils.bytesToHexString(response.payload) + s;
4770 return s;
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
4773 }
Evan Charltonc66da362014-05-16 14:06:40 -07004774 }
4775
Jake Hambye994d462014-02-03 13:10:13 -08004776 /**
4777 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4778 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4779 *
4780 * @param itemID the ID of the item to read
4781 * @return the NV item as a String, or null on error.
4782 */
4783 @Override
4784 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004785 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4787 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004788
4789 final long identity = Binder.clearCallingIdentity();
4790 try {
4791 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004792 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004793 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4794 return value;
4795 } finally {
4796 Binder.restoreCallingIdentity(identity);
4797 }
Jake Hambye994d462014-02-03 13:10:13 -08004798 }
4799
4800 /**
4801 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4802 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4803 *
4804 * @param itemID the ID of the item to read
4805 * @param itemValue the value to write, as a String
4806 * @return true on success; false on any failure
4807 */
4808 @Override
4809 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004810 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4812 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813
4814 final long identity = Binder.clearCallingIdentity();
4815 try {
4816 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4817 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004818 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4820 return success;
4821 } finally {
4822 Binder.restoreCallingIdentity(identity);
4823 }
Jake Hambye994d462014-02-03 13:10:13 -08004824 }
4825
4826 /**
4827 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4828 * Used for device configuration by some CDMA operators.
4829 *
4830 * @param preferredRoamingList byte array containing the new PRL
4831 * @return true on success; false on any failure
4832 */
4833 @Override
4834 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4836 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004837
4838 final long identity = Binder.clearCallingIdentity();
4839 try {
4840 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4841 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4842 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4843 return success;
4844 } finally {
4845 Binder.restoreCallingIdentity(identity);
4846 }
Jake Hambye994d462014-02-03 13:10:13 -08004847 }
4848
4849 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004850 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004851 * Used for device configuration by some CDMA operators.
4852 *
chen xu6dac5ab2018-10-26 17:39:23 -07004853 * @param slotIndex - device slot.
4854 *
Jake Hambye994d462014-02-03 13:10:13 -08004855 * @return true on success; false on any failure
4856 */
4857 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004858 public boolean resetModemConfig(int slotIndex) {
4859 Phone phone = PhoneFactory.getPhone(slotIndex);
4860 if (phone != null) {
4861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4862 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004863
chen xu6dac5ab2018-10-26 17:39:23 -07004864 final long identity = Binder.clearCallingIdentity();
4865 try {
4866 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4867 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4868 return success;
4869 } finally {
4870 Binder.restoreCallingIdentity(identity);
4871 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004872 }
chen xu6dac5ab2018-10-26 17:39:23 -07004873 return false;
4874 }
4875
4876 /**
4877 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4878 *
4879 * @param slotIndex - device slot.
4880 *
4881 * @return true on success; false on any failure
4882 */
4883 @Override
4884 public boolean rebootModem(int slotIndex) {
4885 Phone phone = PhoneFactory.getPhone(slotIndex);
4886 if (phone != null) {
4887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4888 mApp, phone.getSubId(), "rebootModem");
4889
4890 final long identity = Binder.clearCallingIdentity();
4891 try {
4892 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4893 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4894 return success;
4895 } finally {
4896 Binder.restoreCallingIdentity(identity);
4897 }
4898 }
4899 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004900 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004901
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004902 public String[] getPcscfAddress(String apnType, String callingPackage,
4903 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004904 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4906 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004907 return new String[0];
4908 }
4909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 final long identity = Binder.clearCallingIdentity();
4911 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004912 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004913 } finally {
4914 Binder.restoreCallingIdentity(identity);
4915 }
Wink Saville36469e72014-06-11 15:17:00 -07004916 }
4917
Brad Ebinger51f743a2017-01-23 13:50:20 -08004918 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004919 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4920 * {@link #disableIms(int)}.
4921 * @param slotIndex device slot.
4922 */
4923 public void resetIms(int slotIndex) {
4924 enforceModifyPermission();
4925
4926 final long identity = Binder.clearCallingIdentity();
4927 try {
4928 if (mImsResolver == null) {
4929 // may happen if the does not support IMS.
4930 return;
4931 }
4932 mImsResolver.disableIms(slotIndex);
4933 mImsResolver.enableIms(slotIndex);
4934 } finally {
4935 Binder.restoreCallingIdentity(identity);
4936 }
4937 }
4938
4939 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004940 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4941 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004942 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004943 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004944 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945
4946 final long identity = Binder.clearCallingIdentity();
4947 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004948 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004949 // may happen if the device does not support IMS.
4950 return;
4951 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004952 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 } finally {
4954 Binder.restoreCallingIdentity(identity);
4955 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004956 }
4957
4958 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004959 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4960 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004961 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004962 public void disableIms(int slotId) {
4963 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964
4965 final long identity = Binder.clearCallingIdentity();
4966 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004967 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004968 // may happen if the device does not support IMS.
4969 return;
4970 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004971 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004975 }
4976
4977 /**
4978 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4979 * feature or {@link null} if the service is not available. If the feature is available, the
4980 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4981 */
4982 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004983 IImsServiceFeatureCallback callback) {
4984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985
4986 final long identity = Binder.clearCallingIdentity();
4987 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004988 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004989 // may happen if the device does not support IMS.
4990 return null;
4991 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004992 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004996 }
4997
4998 /**
4999 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5000 * feature during emergency calling or {@link null} if the service is not available. If the
5001 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5002 * listener for feature updates.
5003 */
5004 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5005 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006
5007 final long identity = Binder.clearCallingIdentity();
5008 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005009 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005010 // may happen if the device does not support IMS.
5011 return null;
5012 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005013 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014 } finally {
5015 Binder.restoreCallingIdentity(identity);
5016 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005017 }
5018
Brad Ebinger5f64b052017-12-14 14:26:15 -08005019 /**
5020 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005021 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005022 */
5023 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5024 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025
5026 final long identity = Binder.clearCallingIdentity();
5027 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005028 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005029 // may happen if the device does not support IMS.
5030 return null;
5031 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005032 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005033 } finally {
5034 Binder.restoreCallingIdentity(identity);
5035 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005036 }
5037
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005038 /**
5039 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005040 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005041 */
5042 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5043 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044
5045 final long identity = Binder.clearCallingIdentity();
5046 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005047 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005048 // may happen if the device does not support IMS.
5049 return null;
5050 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005051 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 } finally {
5053 Binder.restoreCallingIdentity(identity);
5054 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005055 }
5056
Brad Ebinger884c07b2018-02-15 16:17:40 -08005057 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005058 * Sets the ImsService Package Name that Telephony will bind to.
5059 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005060 * @param slotIndex the slot ID that the ImsService should bind for.
5061 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005062 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005063 * @param featureTypes An integer array of feature types associated with a packageName.
5064 * @param packageName The name of the package that the current configuration will be replaced
5065 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005066 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005067 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005068 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5069 int[] featureTypes, String packageName) {
5070 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5071 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5073 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005074 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005076 final long identity = Binder.clearCallingIdentity();
5077 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005078 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005079 // may happen if the device does not support IMS.
5080 return false;
5081 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005082 Map<Integer, String> featureConfig = new HashMap<>();
5083 for (int featureType : featureTypes) {
5084 featureConfig.put(featureType, packageName);
5085 }
5086 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5087 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005088 } finally {
5089 Binder.restoreCallingIdentity(identity);
5090 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005091 }
5092
5093 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005094 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005095 *
5096 * @param slotId The slot that the ImsService is associated with.
5097 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5098 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005099 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005100 * @return the package name of the ImsService configuration.
5101 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005102 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5103 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005104 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005105 TelephonyPermissions
5106 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5107 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5108 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005110 final long identity = Binder.clearCallingIdentity();
5111 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005112 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005113 // may happen if the device does not support IMS.
5114 return "";
5115 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005116 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005117 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5118 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119 } finally {
5120 Binder.restoreCallingIdentity(identity);
5121 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005122 }
5123
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005124 /**
5125 * Get the MmTelFeature state associated with the requested subscription id.
5126 * @param subId The subscription that the MmTelFeature is associated with.
5127 * @param callback A callback with an integer containing the
5128 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5129 */
5130 @Override
5131 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5132 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5133 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5134 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5135 "IMS not available on device.");
5136 }
5137 final long token = Binder.clearCallingIdentity();
5138 try {
5139 int slotId = getSlotIndex(subId);
5140 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5141 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5142 + subId + "'");
5143 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5144 }
5145 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5146 try {
5147 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5148 } catch (RemoteException e) {
5149 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5150 + "Ignore");
5151 }
5152 });
5153 } finally {
5154 Binder.restoreCallingIdentity(token);
5155 }
5156 }
5157
Wink Saville36469e72014-06-11 15:17:00 -07005158 public void setImsRegistrationState(boolean registered) {
5159 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005160
5161 final long identity = Binder.clearCallingIdentity();
5162 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005163 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164 } finally {
5165 Binder.restoreCallingIdentity(identity);
5166 }
Wink Saville36469e72014-06-11 15:17:00 -07005167 }
5168
5169 /**
Stuart Scott54788802015-03-30 13:18:01 -07005170 * Set the network selection mode to automatic.
5171 *
5172 */
5173 @Override
5174 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5176 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177
5178 final long identity = Binder.clearCallingIdentity();
5179 try {
shilufc958392020-01-20 11:36:01 -08005180 if (!isActiveSubscription(subId)) {
5181 return;
5182 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005183 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5184 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5185 } finally {
5186 Binder.restoreCallingIdentity(identity);
5187 }
Stuart Scott54788802015-03-30 13:18:01 -07005188 }
5189
Pengquan Mengea84e042018-09-20 14:57:26 -07005190 /**
5191 * Ask the radio to connect to the input network and change selection mode to manual.
5192 *
5193 * @param subId the id of the subscription.
5194 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5195 * the operator to attach to.
5196 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5197 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5198 * normal network selection next time.
5199 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005200 */
5201 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005202 public boolean setNetworkSelectionModeManual(
5203 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5205 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005206
5207 if (!isActiveSubscription(subId)) {
5208 return false;
5209 }
5210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211 final long identity = Binder.clearCallingIdentity();
5212 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005213 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005215 if (DBG) {
5216 log("setNetworkSelectionModeManual: subId: " + subId
5217 + " operator: " + operatorInfo);
5218 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005219 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5220 } finally {
5221 Binder.restoreCallingIdentity(identity);
5222 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005223 }
shilu84f6e8b2019-12-19 13:58:01 -08005224 /**
5225 * Get the manual network selection
5226 *
5227 * @param subId the id of the subscription.
5228 *
5229 * @return the previously saved user selected PLMN
5230 */
5231 @Override
5232 public String getManualNetworkSelectionPlmn(int subId) {
5233 TelephonyPermissions
5234 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5235 mApp, subId, "getManualNetworkSelectionPlmn");
5236
5237 final long identity = Binder.clearCallingIdentity();
5238 try {
5239 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005240 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005241 }
5242
5243 final Phone phone = getPhone(subId);
5244 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005245 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005246 }
5247 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5248 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5249 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5250 } finally {
5251 Binder.restoreCallingIdentity(identity);
5252 }
5253 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005254
5255 /**
5256 * Scans for available networks.
5257 */
5258 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005259 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5260 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5262 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005263 LocationAccessPolicy.LocationPermissionResult locationResult =
5264 LocationAccessPolicy.checkLocationPermission(mApp,
5265 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5266 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005267 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005268 .setCallingPid(Binder.getCallingPid())
5269 .setCallingUid(Binder.getCallingUid())
5270 .setMethod("getCellNetworkScanResults")
5271 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5272 .build());
5273 switch (locationResult) {
5274 case DENIED_HARD:
5275 throw new SecurityException("Not allowed to access scan results -- location");
5276 case DENIED_SOFT:
5277 return null;
5278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279
Pengquan Menga1bb6272018-09-06 09:59:22 -07005280 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 try {
5282 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005283 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 } finally {
5286 Binder.restoreCallingIdentity(identity);
5287 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005288 }
5289
5290 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005291 * Get the call forwarding info, given the call forwarding reason.
5292 */
5293 @Override
5294 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5295 enforceReadPrivilegedPermission("getCallForwarding");
5296 long identity = Binder.clearCallingIdentity();
5297 try {
5298 if (DBG) {
5299 log("getCallForwarding: subId " + subId
5300 + " callForwardingReason" + callForwardingReason);
5301 }
5302 return (CallForwardingInfo) sendRequest(
5303 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5304 } finally {
5305 Binder.restoreCallingIdentity(identity);
5306 }
5307 }
5308
5309 /**
5310 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5311 * reason, the number to forward, and the timeout before the forwarding is attempted.
5312 */
5313 @Override
5314 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5315 enforceModifyPermission();
5316 long identity = Binder.clearCallingIdentity();
5317 try {
5318 if (DBG) {
5319 log("setCallForwarding: subId " + subId
5320 + " callForwardingInfo" + callForwardingInfo);
5321 }
5322 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5323 } finally {
5324 Binder.restoreCallingIdentity(identity);
5325 }
5326 }
5327
5328 /**
5329 * Get the call forwarding info, given the call forwarding reason.
5330 */
5331 @Override
5332 public int getCallWaitingStatus(int subId) {
5333 enforceReadPrivilegedPermission("getCallForwarding");
5334 long identity = Binder.clearCallingIdentity();
5335 try {
5336 if (DBG) log("getCallWaitingStatus: subId " + subId);
5337 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5338 } finally {
5339 Binder.restoreCallingIdentity(identity);
5340 }
5341 }
5342
5343 /**
5344 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5345 * reason, the number to forward, and the timeout before the forwarding is attempted.
5346 */
5347 @Override
5348 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5349 enforceModifyPermission();
5350 long identity = Binder.clearCallingIdentity();
5351 try {
5352 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5353 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5354 } finally {
5355 Binder.restoreCallingIdentity(identity);
5356 }
5357 }
5358
5359 /**
yinxub1bed742017-04-17 11:45:04 -07005360 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005361 *
yinxub1bed742017-04-17 11:45:04 -07005362 * @param subId id of the subscription
5363 * @param request contains the radio access networks with bands/channels to scan
5364 * @param messenger callback messenger for scan results or errors
5365 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005366 * @return the id of the requested scan which can be used to stop the scan.
5367 */
5368 @Override
5369 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005370 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5372 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005373 LocationAccessPolicy.LocationPermissionResult locationResult =
5374 LocationAccessPolicy.checkLocationPermission(mApp,
5375 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5376 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005377 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005378 .setCallingPid(Binder.getCallingPid())
5379 .setCallingUid(Binder.getCallingUid())
5380 .setMethod("requestNetworkScan")
5381 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5382 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005383 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005384 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005385 if (e != null) {
5386 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5387 throw e;
5388 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005389 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005390 return TelephonyScanManager.INVALID_SCAN_ID;
5391 }
5392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 }
Hall Liu912dfd32019-04-25 14:02:26 -07005394 int callingUid = Binder.getCallingUid();
5395 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005396 final long identity = Binder.clearCallingIdentity();
5397 try {
5398 return mNetworkScanRequestTracker.startNetworkScan(
5399 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005400 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005401 } finally {
5402 Binder.restoreCallingIdentity(identity);
5403 }
yinxu504e1392017-04-12 16:03:22 -07005404 }
5405
Hall Liub2ac8ef2019-02-28 15:56:23 -08005406 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005407 NetworkScanRequest request, int subId) {
5408 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5409 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5410 boolean hasNetworkScanPermission =
5411 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5412 == PERMISSION_GRANTED;
5413
5414 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5415 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5416 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005417 }
5418
5419 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5420 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005421 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5422 return new SecurityException("Specific channels must not be"
5423 + " scanned without location access.");
5424 }
5425 }
5426 }
5427
Hall Liub2ac8ef2019-02-28 15:56:23 -08005428 return null;
5429 }
5430
yinxu504e1392017-04-12 16:03:22 -07005431 /**
5432 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005433 *
5434 * @param subId id of the subscription
5435 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005436 */
5437 @Override
5438 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5440 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441
Hall Liu912dfd32019-04-25 14:02:26 -07005442 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443 final long identity = Binder.clearCallingIdentity();
5444 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005445 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 } finally {
5447 Binder.restoreCallingIdentity(identity);
5448 }
yinxu504e1392017-04-12 16:03:22 -07005449 }
5450
5451 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005452 * Get the calculated preferred network type.
5453 * Used for debugging incorrect network type.
5454 *
5455 * @return the preferred network type, defined in RILConstants.java.
5456 */
5457 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005458 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005459 final Phone defaultPhone = getDefaultPhone();
5460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005461 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005462 return RILConstants.PREFERRED_NETWORK_MODE;
5463 }
5464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005468 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469 } finally {
5470 Binder.restoreCallingIdentity(identity);
5471 }
Junda Liu84d15a22014-07-02 11:21:04 -07005472 }
5473
5474 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005475 * Get the preferred network type.
5476 * Used for device configuration by some CDMA operators.
5477 *
5478 * @return the preferred network type, defined in RILConstants.java.
5479 */
5480 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005481 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005482 TelephonyPermissions
5483 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5484 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485
5486 final long identity = Binder.clearCallingIdentity();
5487 try {
5488 if (DBG) log("getPreferredNetworkType");
5489 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5490 int networkType = (result != null ? result[0] : -1);
5491 if (DBG) log("getPreferredNetworkType: " + networkType);
5492 return networkType;
5493 } finally {
5494 Binder.restoreCallingIdentity(identity);
5495 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005496 }
5497
5498 /**
5499 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005500 *
5501 * @param networkType the preferred network type, defined in RILConstants.java.
5502 * @return true on success; false on any failure.
5503 */
5504 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005505 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5507 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508
5509 final long identity = Binder.clearCallingIdentity();
5510 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005511 Settings.Global.putInt(mApp.getContentResolver(),
5512 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan8ed33732020-03-12 14:17:55 +08005513
5514 Boolean success = (Boolean) sendRequest(
5515 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5516 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5517 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518 } finally {
5519 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005520 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005521 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005522
5523 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005524 * Get the allowed network types that store in the telephony provider.
5525 *
5526 * @param subId the id of the subscription.
5527 * @return allowedNetworkTypes the allowed network types.
5528 */
5529 @Override
5530 public long getAllowedNetworkTypes(int subId) {
5531 TelephonyPermissions
5532 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5533 mApp, subId, "getAllowedNetworkTypes");
5534
5535 final long identity = Binder.clearCallingIdentity();
5536 try {
5537 return SubscriptionManager.getLongSubscriptionProperty(
5538 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5539 } finally {
5540 Binder.restoreCallingIdentity(identity);
5541 }
5542 }
5543
5544 /**
5545 * Set the allowed network types.
5546 *
5547 * @param subId the id of the subscription.
5548 * @param allowedNetworkTypes the allowed network types.
5549 * @return true on success; false on any failure.
5550 */
5551 @Override
5552 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5554 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005555
calvinpan8ed33732020-03-12 14:17:55 +08005556 SubscriptionManager.setSubscriptionProperty(subId,
5557 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5558 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005559
calvinpan8ed33732020-03-12 14:17:55 +08005560 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5561 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5562 RILConstants.PREFERRED_NETWORK_MODE);
5563 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005564 }
5565
5566 /**
Miaoa84611c2019-03-15 09:21:10 +08005567 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005568 *
Miaoa84611c2019-03-15 09:21:10 +08005569 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005570 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005571 * @hide
5572 */
5573 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005574 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005575 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005576 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005577 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 try {
Miaoa84611c2019-03-15 09:21:10 +08005579 if (phone != null) {
5580 return phone.hasMatchedTetherApnSetting();
5581 } else {
5582 return false;
5583 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 } finally {
5585 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005586 }
Junda Liu475951f2014-11-07 16:45:03 -08005587 }
5588
5589 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005590 * Enable or disable always reporting signal strength changes from radio.
5591 *
5592 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5593 */
5594 @Override
5595 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5596 enforceModifyPermission();
5597 enforceSystemCaller();
5598
5599 final long identity = Binder.clearCallingIdentity();
5600 final Phone phone = getPhone(subId);
5601 try {
5602 if (phone != null) {
5603 if (DBG) {
5604 log("setAlwaysReportSignalStrength: subId=" + subId
5605 + " isEnable=" + isEnable);
5606 }
5607 phone.setAlwaysReportSignalStrength(isEnable);
5608 } else {
5609 loge("setAlwaysReportSignalStrength: no phone found for subId="
5610 + subId);
5611 }
5612 } finally {
5613 Binder.restoreCallingIdentity(identity);
5614 }
5615 }
5616
5617 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005618 * Get the user enabled state of Mobile Data.
5619 *
5620 * TODO: remove and use isUserDataEnabled.
5621 * This can't be removed now because some vendor codes
5622 * calls through ITelephony directly while they should
5623 * use TelephonyManager.
5624 *
5625 * @return true on enabled
5626 */
5627 @Override
5628 public boolean getDataEnabled(int subId) {
5629 return isUserDataEnabled(subId);
5630 }
5631
5632 /**
5633 * Get whether mobile data is enabled per user setting.
5634 *
5635 * There are other factors deciding whether mobile data is actually enabled, but they are
5636 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005637 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005638 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005639 *
5640 * @return {@code true} if data is enabled else {@code false}
5641 */
5642 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005643 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005644 try {
5645 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5646 null);
5647 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5649 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005650 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005651
5652 final long identity = Binder.clearCallingIdentity();
5653 try {
5654 int phoneId = mSubscriptionController.getPhoneId(subId);
5655 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5656 Phone phone = PhoneFactory.getPhone(phoneId);
5657 if (phone != null) {
5658 boolean retVal = phone.isUserDataEnabled();
5659 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5660 return retVal;
5661 } else {
5662 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5663 return false;
5664 }
5665 } finally {
5666 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005667 }
5668 }
5669
5670 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005671 * Checks if the device is capable of mobile data by considering whether whether the
5672 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5673 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005674 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005675 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005676 */
5677 @Override
5678 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005679 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680
5681 final long identity = Binder.clearCallingIdentity();
5682 try {
5683 int phoneId = mSubscriptionController.getPhoneId(subId);
5684 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5685 Phone phone = PhoneFactory.getPhone(phoneId);
5686 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005687 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5689 return retVal;
5690 } else {
5691 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5692 return false;
5693 }
5694 } finally {
5695 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005696 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005697 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005698
Sooraj Sasindran4872c7f2020-04-19 18:14:03 -07005699 /**
5700 * Check if data is enabled for a specific reason
5701 * @param subId Subscription index
5702 * @param reason the reason the data enable change is taking place
5703 * @return {@code true} if the overall data is enabled; {@code false} if not.
5704 */
5705 @Override
5706 public boolean isDataEnabledWithReason(int subId,
5707 @TelephonyManager.DataEnabledReason int reason) {
5708 try {
5709 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5710 null);
5711 } catch (Exception e) {
5712 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
5713 "isDataEnabledWithReason");
5714 }
5715
5716
5717 final long identity = Binder.clearCallingIdentity();
5718 try {
5719 int phoneId = mSubscriptionController.getPhoneId(subId);
5720 if (DBG) {
5721 log("isDataEnabledWithReason: subId=" + subId + " phoneId=" + phoneId
5722 + " reason=" + reason);
5723 }
5724 Phone phone = PhoneFactory.getPhone(phoneId);
5725 if (phone != null) {
5726 boolean retVal;
5727 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
5728 retVal = phone.isUserDataEnabled();
5729 } else {
5730 retVal = phone.getDataEnabledSettings().isDataEnabledWithReason(reason);
5731 }
5732 if (DBG) log("isDataEnabledWithReason: retVal=" + retVal);
5733 return retVal;
5734 } else {
5735 if (DBG) {
5736 loge("isDataEnabledWithReason: no phone subId="
5737 + subId + " retVal=false");
5738 }
5739 return false;
5740 }
5741 } finally {
5742 Binder.restoreCallingIdentity(identity);
5743 }
5744 }
5745
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005746 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005747 Phone phone) {
5748 //load access rules from carrier configs, and check those as well: b/139133814
5749 SubscriptionController subController = SubscriptionController.getInstance();
5750 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5751 || subController == null) return privilegeFromSim;
5752
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005753 PackageManager pkgMgr = phone.getContext().getPackageManager();
5754 String[] packages = pkgMgr.getPackagesForUid(uid);
5755
5756 final long identity = Binder.clearCallingIdentity();
5757 try {
5758 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5759 SubscriptionManager subManager = (SubscriptionManager)
5760 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5761 for (String pkg : packages) {
5762 if (subManager.canManageSubscription(subInfo, pkg)) {
5763 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5764 }
5765 }
5766 return privilegeFromSim;
5767 } finally {
5768 Binder.restoreCallingIdentity(identity);
5769 }
5770 }
5771
5772 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5773 String pkgName) {
5774 //load access rules from carrier configs, and check those as well: b/139133814
5775 SubscriptionController subController = SubscriptionController.getInstance();
5776 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5777 || subController == null) return privilegeFromSim;
5778
5779 final long identity = Binder.clearCallingIdentity();
5780 try {
5781 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5782 SubscriptionManager subManager = (SubscriptionManager)
5783 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5784 return subManager.canManageSubscription(subInfo, pkgName)
5785 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5786 } finally {
5787 Binder.restoreCallingIdentity(identity);
5788 }
5789 }
5790
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005791 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005792 public int getCarrierPrivilegeStatus(int subId) {
5793 final Phone phone = getPhone(subId);
5794 if (phone == null) {
5795 loge("getCarrierPrivilegeStatus: Invalid subId");
5796 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5797 }
5798 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005799 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005800 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005801 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5802 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005803
5804 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5805 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005806 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005807 }
Junda Liu29340342014-07-10 15:23:27 -07005808
5809 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005810 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005811 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005812 final Phone phone = getPhone(subId);
5813 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005814 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005815 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5816 }
5817 UiccProfile profile =
5818 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5819 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005820 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005821 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5822 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005823 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005824 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005825 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005826 }
5827
5828 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005829 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5830 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005831 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005832 }
5833
5834 int phoneId = SubscriptionManager.getPhoneId(subId);
5835 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005836 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005837 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005838 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5839 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005840 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5841 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5842 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005843 }
5844
5845 @Override
5846 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005847 if (TextUtils.isEmpty(pkgName))
5848 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005849 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5850 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5851 UiccCard card = UiccController.getInstance().getUiccCard(i);
5852 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005853 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005854 continue;
5855 }
5856
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005857 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5858 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5859 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005860 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5861 break;
5862 }
5863 }
5864
5865 return result;
Junda Liu29340342014-07-10 15:23:27 -07005866 }
Derek Tan89e89d42014-07-08 17:00:10 -07005867
5868 @Override
Junda Liue64de782015-04-16 17:19:16 -07005869 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5870 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5871 loge("phoneId " + phoneId + " is not valid.");
5872 return null;
5873 }
5874 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005875 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005876 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005877 return null ;
5878 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005879 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005880 }
5881
Amith Yamasani6e118872016-02-19 12:53:51 -08005882 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005883 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005884 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005885 List<String> privilegedPackages = new ArrayList<>();
5886 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005887 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5888 // has UICC in that slot.
5889 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005890 if (card.hasCarrierPrivilegeRules()) {
5891 if (packages == null) {
5892 // Only check packages in user 0 for now
5893 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005894 PackageManager.MATCH_DISABLED_COMPONENTS
5895 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005896 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005897 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005898 }
5899 for (int p = packages.size() - 1; p >= 0; p--) {
5900 PackageInfo pkgInfo = packages.get(p);
5901 if (pkgInfo != null && pkgInfo.packageName != null
5902 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005903 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005904 privilegedPackages.add(pkgInfo.packageName);
5905 }
5906 }
5907 }
5908 }
5909 return privilegedPackages;
5910 }
5911
chen xuf7e9fe82019-05-09 19:31:02 -07005912 @Override
5913 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005914 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5915
5916 final long identity = Binder.clearCallingIdentity();
5917
chen xuf7e9fe82019-05-09 19:31:02 -07005918 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005919 try {
5920 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5921 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5922 }
5923 } finally {
5924 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005925 }
5926 return privilegedPackages;
5927 }
5928
Wink Savilleb564aae2014-10-23 10:18:09 -07005929 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005930 final Phone phone = getPhone(subId);
5931 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005932 if (card == null) {
5933 loge("getIccId: No UICC");
5934 return null;
5935 }
5936 String iccId = card.getIccId();
5937 if (TextUtils.isEmpty(iccId)) {
5938 loge("getIccId: ICC ID is null or empty.");
5939 return null;
5940 }
5941 return iccId;
5942 }
5943
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005944 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005945 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5946 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005947 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005948 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950 final long identity = Binder.clearCallingIdentity();
5951 try {
5952 final String iccId = getIccId(subId);
5953 final Phone phone = getPhone(subId);
5954 if (phone == null) {
5955 return false;
5956 }
5957 final String subscriberId = phone.getSubscriberId();
5958
5959 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08005960 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 + subscriberId + " to " + number);
5962 }
5963
5964 if (TextUtils.isEmpty(iccId)) {
5965 return false;
5966 }
5967
5968 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5969
5970 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5971 if (alphaTag == null) {
5972 editor.remove(alphaTagPrefKey);
5973 } else {
5974 editor.putString(alphaTagPrefKey, alphaTag);
5975 }
5976
5977 // Record both the line number and IMSI for this ICCID, since we need to
5978 // track all merged IMSIs based on line number
5979 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5980 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5981 if (number == null) {
5982 editor.remove(numberPrefKey);
5983 editor.remove(subscriberPrefKey);
5984 } else {
5985 editor.putString(numberPrefKey, number);
5986 editor.putString(subscriberPrefKey, subscriberId);
5987 }
5988
5989 editor.commit();
5990 return true;
5991 } finally {
5992 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005993 }
Derek Tan7226c842014-07-02 17:42:23 -07005994 }
5995
5996 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005997 public String getLine1NumberForDisplay(int subId, String callingPackage,
5998 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005999 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006000 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006001 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006002 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006003 return null;
6004 }
Derek Tan97ebb422014-09-05 16:55:38 -07006005
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 final long identity = Binder.clearCallingIdentity();
6007 try {
6008 String iccId = getIccId(subId);
6009 if (iccId != null) {
6010 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6011 if (DBG_MERGE) {
6012 log("getLine1NumberForDisplay returning "
6013 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6014 }
6015 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006016 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6018 return null;
6019 } finally {
6020 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006021 }
Derek Tan7226c842014-07-02 17:42:23 -07006022 }
6023
6024 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006025 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6026 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006027 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006028 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006029 return null;
6030 }
Derek Tan97ebb422014-09-05 16:55:38 -07006031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006032 final long identity = Binder.clearCallingIdentity();
6033 try {
6034 String iccId = getIccId(subId);
6035 if (iccId != null) {
6036 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6037 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6038 }
6039 return null;
6040 } finally {
6041 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006042 }
Derek Tan7226c842014-07-02 17:42:23 -07006043 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006044
6045 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006046 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6047 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006048 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6049 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006051 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006052 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006053 return null;
6054 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006055
Jordan Liub49b04b2019-05-06 14:45:15 -07006056 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6057 // the process, where TelephonyManager was instantiated.
6058 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006059 final long identity = Binder.clearCallingIdentity();
6060 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006061 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 final TelephonyManager tele = TelephonyManager.from(context);
6063 final SubscriptionManager sub = SubscriptionManager.from(context);
6064
6065 // Figure out what subscribers are currently active
6066 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067
Jordan Liub49b04b2019-05-06 14:45:15 -07006068 // Only consider subs which match the current subId
6069 // This logic can be simplified. See b/131189269 for progress.
6070 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006071 activeSubscriberIds.add(tele.getSubscriberId(subId));
6072 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073
6074 // First pass, find a number override for an active subscriber
6075 String mergeNumber = null;
6076 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6077 for (String key : prefs.keySet()) {
6078 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6079 final String subscriberId = (String) prefs.get(key);
6080 if (activeSubscriberIds.contains(subscriberId)) {
6081 final String iccId = key.substring(
6082 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6083 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6084 mergeNumber = (String) prefs.get(numberKey);
6085 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006086 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 + " for active subscriber " + subscriberId);
6088 }
6089 if (!TextUtils.isEmpty(mergeNumber)) {
6090 break;
6091 }
6092 }
6093 }
6094 }
6095
6096 // Shortcut when no active merged subscribers
6097 if (TextUtils.isEmpty(mergeNumber)) {
6098 return null;
6099 }
6100
6101 // Second pass, find all subscribers under that line override
6102 final ArraySet<String> result = new ArraySet<>();
6103 for (String key : prefs.keySet()) {
6104 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6105 final String number = (String) prefs.get(key);
6106 if (mergeNumber.equals(number)) {
6107 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6108 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6109 final String subscriberId = (String) prefs.get(subscriberKey);
6110 if (!TextUtils.isEmpty(subscriberId)) {
6111 result.add(subscriberId);
6112 }
6113 }
6114 }
6115 }
6116
6117 final String[] resultArray = result.toArray(new String[result.size()]);
6118 Arrays.sort(resultArray);
6119 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006120 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6122 }
6123 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006124 } finally {
6125 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006126 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006127 }
6128
6129 @Override
zoey chen38003472019-12-13 17:16:31 +08006130 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6131 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006132
6133 final long identity = Binder.clearCallingIdentity();
6134 try {
6135 final TelephonyManager telephonyManager = mApp.getSystemService(
6136 TelephonyManager.class);
6137 String subscriberId = telephonyManager.getSubscriberId(subId);
6138 if (subscriberId == null) {
6139 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006140 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006141 + subId);
6142 }
6143 return null;
6144 }
6145
6146 final SubscriptionInfo info = SubscriptionController.getInstance()
6147 .getSubscriptionInfo(subId);
6148 final ParcelUuid groupUuid = info.getGroupUuid();
6149 // If it doesn't belong to any group, return just subscriberId of itself.
6150 if (groupUuid == null) {
6151 return new String[]{subscriberId};
6152 }
6153
6154 // Get all subscriberIds from the group.
6155 final List<String> mergedSubscriberIds = new ArrayList<>();
6156 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006157 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006158 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006159 for (SubscriptionInfo subInfo : groupInfos) {
6160 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6161 if (subscriberId != null) {
6162 mergedSubscriberIds.add(subscriberId);
6163 }
6164 }
6165
6166 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169
6170 }
6171 }
6172
6173 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006174 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006175 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006176 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006177
6178 final long identity = Binder.clearCallingIdentity();
6179 try {
6180 final Phone phone = getPhone(subId);
6181 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6182 } finally {
6183 Binder.restoreCallingIdentity(identity);
6184 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006185 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006186
6187 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006188 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006189 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6190 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006191 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6192 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193
6194 final long identity = Binder.clearCallingIdentity();
6195 try {
6196 final Phone phone = getPhone(subId);
6197 if (phone == null) {
6198 return false;
6199 }
6200 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6201 cdmaNonRoamingList);
6202 } finally {
6203 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006204 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006205 }
6206
6207 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006208 @Deprecated
6209 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6210 enforceModifyPermission();
6211
6212 int returnValue = 0;
6213 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006214 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006215 if(result.exception == null) {
6216 if (result.result != null) {
6217 byte[] responseData = (byte[])(result.result);
6218 if(responseData.length > oemResp.length) {
6219 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6220 responseData.length + "bytes. Buffer Size is " +
6221 oemResp.length + "bytes.");
6222 }
6223 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6224 returnValue = responseData.length;
6225 }
6226 } else {
6227 CommandException ex = (CommandException) result.exception;
6228 returnValue = ex.getCommandError().ordinal();
6229 if(returnValue > 0) returnValue *= -1;
6230 }
6231 } catch (RuntimeException e) {
6232 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6233 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6234 if(returnValue > 0) returnValue *= -1;
6235 }
6236
6237 return returnValue;
6238 }
6239
6240 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006241 public void setRadioCapability(RadioAccessFamily[] rafs) {
6242 try {
6243 ProxyController.getInstance().setRadioCapability(rafs);
6244 } catch (RuntimeException e) {
6245 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6246 }
6247 }
6248
6249 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006250 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006251 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006252 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006253 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006254 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006255 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006256 final long identity = Binder.clearCallingIdentity();
6257 try {
chen xub97461a2018-10-26 14:17:57 -07006258 TelephonyPermissions
6259 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6260 mApp, phone.getSubId(), "getRadioAccessFamily");
6261 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262 } finally {
6263 Binder.restoreCallingIdentity(identity);
6264 }
chen xub97461a2018-10-26 14:17:57 -07006265 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006266 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006267
6268 @Override
6269 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006270 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006271 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272
6273 final long identity = Binder.clearCallingIdentity();
6274 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006275 ImsManager.getInstance(defaultPhone.getContext(),
6276 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006277 } finally {
6278 Binder.restoreCallingIdentity(identity);
6279 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006280 }
6281
6282 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006283 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006284 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6286 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006287 return false;
6288 }
Svet Ganovb320e182015-04-16 12:30:10 -07006289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 final long identity = Binder.clearCallingIdentity();
6291 try {
6292 // Check the user preference and the system-level IMS setting. Even if the user has
6293 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6294 // In the long run, we may instead need to check if there exists a connection service
6295 // which can support video calling.
6296 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006297 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 return imsManager.isVtEnabledByPlatform()
6299 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6300 && imsManager.isVtEnabledByUser();
6301 } finally {
6302 Binder.restoreCallingIdentity(identity);
6303 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006304 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006305
Andrew Leea1239f22015-03-02 17:44:07 -08006306 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006307 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6308 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006310 mApp, subId, callingPackage, callingFeatureId,
6311 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006312 return false;
6313 }
6314
6315 final long identity = Binder.clearCallingIdentity();
6316 try {
6317 CarrierConfigManager configManager =
6318 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006319 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006320 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6321 } finally {
6322 Binder.restoreCallingIdentity(identity);
6323 }
Andrew Leea1239f22015-03-02 17:44:07 -08006324 }
6325
6326 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006327 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006329 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006330 return false;
6331 }
6332
6333 final long identity = Binder.clearCallingIdentity();
6334 try {
6335 CarrierConfigManager configManager =
6336 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006337 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006338 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6339 } finally {
6340 Binder.restoreCallingIdentity(identity);
6341 }
Andrew Leea1239f22015-03-02 17:44:07 -08006342 }
6343
Andrew Lee9431b832015-03-09 18:46:45 -07006344 @Override
6345 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006346 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006347 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006348 }
6349
6350 @Override
6351 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006352 final long identity = Binder.clearCallingIdentity();
6353 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006354 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006355 } finally {
6356 Binder.restoreCallingIdentity(identity);
6357 }
Andrew Lee9431b832015-03-09 18:46:45 -07006358 }
6359
Hall Liuf6668912018-10-31 17:05:23 -07006360 /**
6361 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6362 * support for the feature and device firmware support.
6363 *
6364 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6365 */
6366 @Override
6367 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006369 final Phone phone = getPhone(subscriptionId);
6370 if (phone == null) {
6371 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6372 return false;
6373 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006375 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6377 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006378 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 return isCarrierSupported && isDeviceSupported;
6380 } finally {
6381 Binder.restoreCallingIdentity(identity);
6382 }
Hall Liu98187582018-01-22 19:15:32 -08006383 }
6384
Hall Liuf6668912018-10-31 17:05:23 -07006385 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006386 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6387 * RTT setting, will return true if the device and carrier both support RTT.
6388 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006389 */
6390 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006391 final long identity = Binder.clearCallingIdentity();
6392 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006393 boolean isRttSupported = isRttSupported(subscriptionId);
6394 boolean isUserRttSettingOn = Settings.Secure.getInt(
6395 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6396 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6397 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6398 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399 } finally {
6400 Binder.restoreCallingIdentity(identity);
6401 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006402 }
6403
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006404 @Deprecated
6405 @Override
6406 public String getDeviceId(String callingPackage) {
6407 return getDeviceIdWithFeature(callingPackage, null);
6408 }
6409
Sanket Padawe7310cc72015-01-14 09:53:20 -08006410 /**
6411 * Returns the unique device ID of phone, for example, the IMEI for
6412 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6413 *
6414 * <p>Requires Permission:
6415 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6416 */
6417 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006418 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006419 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006420 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006421 return null;
6422 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006423 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006424 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006425 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006426 return null;
6427 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006428
6429 final long identity = Binder.clearCallingIdentity();
6430 try {
6431 return phone.getDeviceId();
6432 } finally {
6433 Binder.restoreCallingIdentity(identity);
6434 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006435 }
6436
Ping Sunc67b7c22016-03-02 19:16:45 +08006437 /**
6438 * {@hide}
6439 * Returns the IMS Registration Status on a particular subid
6440 *
6441 * @param subId
6442 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006443 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006444 Phone phone = getPhone(subId);
6445 if (phone != null) {
6446 return phone.isImsRegistered();
6447 } else {
6448 return false;
6449 }
6450 }
6451
Santos Cordon7a1885b2015-02-03 11:15:19 -08006452 @Override
6453 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006454 final long identity = Binder.clearCallingIdentity();
6455 try {
6456 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6457 } finally {
6458 Binder.restoreCallingIdentity(identity);
6459 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006460 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006461
Tyler Gunnf70ed162019-04-03 15:28:53 -07006462 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006463 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006464 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006466 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006467 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6468 }
6469 final long identity = Binder.clearCallingIdentity();
6470 try {
6471 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
6474 }
6475 }
6476
6477 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006478 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6479 final long identity = Binder.clearCallingIdentity();
6480 try {
6481 Phone phone = getPhone(subscriptionId);
6482 if (phone == null) {
6483 return null;
6484 }
6485 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6486 } finally {
6487 Binder.restoreCallingIdentity(identity);
6488 }
6489 }
6490
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006491 /**
6492 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006493 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006494 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006495 final long identity = Binder.clearCallingIdentity();
6496 try {
6497 Phone phone = getPhone(subId);
6498 if (phone != null) {
6499 return phone.isWifiCallingEnabled();
6500 } else {
6501 return false;
6502 }
6503 } finally {
6504 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006505 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006506 }
6507
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006508 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006509 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006510 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006511 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006512 final long identity = Binder.clearCallingIdentity();
6513 try {
6514 Phone phone = getPhone(subId);
6515 if (phone != null) {
6516 return phone.isVideoEnabled();
6517 } else {
6518 return false;
6519 }
6520 } finally {
6521 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006522 }
6523 }
6524
6525 /**
6526 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6527 * defined in {@link ImsRegistrationImplBase}.
6528 */
6529 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530 final long identity = Binder.clearCallingIdentity();
6531 try {
6532 Phone phone = getPhone(subId);
6533 if (phone != null) {
6534 return phone.getImsRegistrationTech();
6535 } else {
6536 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6537 }
6538 } finally {
6539 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006540 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006541 }
6542
Stuart Scott8eef64f2015-04-08 15:13:54 -07006543 @Override
6544 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006545 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006546 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6547 return;
6548 }
6549
Svet Ganovcc087f82015-05-12 20:35:54 -07006550 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006551
Svet Ganovcc087f82015-05-12 20:35:54 -07006552 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006553 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6554 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran4872c7f2020-04-19 18:14:03 -07006555 setDataEnabledWithReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
6556 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006557 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006558 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006559 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6560 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006561 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006562 // There has been issues when Sms raw table somehow stores orphan
6563 // fragments. They lead to garbled message when new fragments come
6564 // in and combined with those stale ones. In case this happens again,
6565 // user can reset all network settings which will clean up this table.
6566 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006567 // Clean up IMS settings as well here.
6568 int slotId = getSlotIndex(subId);
6569 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6570 ImsManager.getInstance(mApp, slotId).factoryReset();
6571 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006572
6573 // Erase modem config if erase modem on network setting is enabled.
6574 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6575 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6576 if (configValue != null && Boolean.parseBoolean(configValue)) {
6577 sendEraseModemConfig(getDefaultPhone());
6578 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006579 } finally {
6580 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006581 }
6582 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006583
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006584 private void cleanUpSmsRawTable(Context context) {
6585 ContentResolver resolver = context.getContentResolver();
6586 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6587 resolver.delete(uri, null, null);
6588 }
6589
Narayan Kamath1c496c22015-04-16 14:40:19 +01006590 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006591 public String getSimLocaleForSubscriber(int subId) {
6592 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6593 final Phone phone = getPhone(subId);
6594 if (phone == null) {
6595 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006596 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598 final long identity = Binder.clearCallingIdentity();
6599 try {
chen xu5d3637b2019-01-21 23:31:38 -08006600 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006601 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006602 if (info == null) {
6603 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6604 return null;
6605 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006606 // Try and fetch the locale from the carrier properties or from the SIM language
6607 // preferences (EF-PL and EF-LI)...
6608 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006610 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6611 if (localeFromDefaultSim != null) {
6612 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6613 if (DBG) log("Using locale from subId: " + subId + " locale: "
6614 + localeFromDefaultSim);
6615 return localeFromDefaultSim.toLanguageTag();
6616 } else {
6617 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006618 }
6619 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006621 // The SIM language preferences only store a language (e.g. fr = French), not an
6622 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6623 // the SIM and carrier preferences does not include a country we add the country
6624 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006625 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006626 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006627 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628 return mccLocale.toLanguageTag();
6629 }
6630
6631 if (DBG) log("No locale found - returning null");
6632 return null;
6633 } finally {
6634 Binder.restoreCallingIdentity(identity);
6635 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006636 }
6637
6638 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006639 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006640 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006641 }
6642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643 /**
6644 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6645 */
6646 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006647 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006648 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006649 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006650
Chenjie Yu1ba97252018-01-11 18:16:20 -08006651 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006652 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006653
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006654 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006655 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6656 * representing the state of the modem.
6657 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006658 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6659 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006660 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006661 */
6662 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006663 public void requestModemActivityInfo(ResultReceiver result) {
6664 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006665 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006666
6667 final long identity = Binder.clearCallingIdentity();
6668 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08006669 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006670 } finally {
6671 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006672 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006673 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006674
Siddharth Rayb8114062018-06-17 15:02:38 -07006675 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6676 // less than total activity duration.
6677 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6678 if (info == null) {
6679 return false;
6680 }
6681 int activityDurationMs =
6682 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6683 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006684 int[] txTimeMs = info.getTransmitTimeMillis();
6685 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6686 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006687 }
6688 return (info.isValid()
6689 && (info.getSleepTimeMillis() <= activityDurationMs)
6690 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006691 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006692 && (totalTxTimeMs <= activityDurationMs));
6693 }
6694
Jack Yu85bd38a2015-11-09 11:34:32 -08006695 /**
6696 * {@hide}
6697 * Returns the service state information on specified subscription.
6698 */
6699 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006700 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6701 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006702 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006703 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006704 return null;
6705 }
6706
Hall Liuf19c44f2018-11-27 14:38:17 -08006707 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6708 LocationAccessPolicy.checkLocationPermission(mApp,
6709 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6710 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006711 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006712 .setCallingPid(Binder.getCallingPid())
6713 .setCallingUid(Binder.getCallingUid())
6714 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006715 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006716 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6717 .build());
6718
6719 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6720 LocationAccessPolicy.checkLocationPermission(mApp,
6721 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6722 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006723 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006724 .setCallingPid(Binder.getCallingPid())
6725 .setCallingUid(Binder.getCallingUid())
6726 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006727 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006728 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6729 .build());
6730 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6731 boolean hasFinePermission =
6732 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6733 boolean hasCoarsePermission =
6734 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736 final long identity = Binder.clearCallingIdentity();
6737 try {
6738 final Phone phone = getPhone(subId);
6739 if (phone == null) {
6740 return null;
6741 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006742
Hall Liuf19c44f2018-11-27 14:38:17 -08006743 ServiceState ss = phone.getServiceState();
6744
6745 // Scrub out the location info in ServiceState depending on what level of access
6746 // the caller has.
6747 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006748 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6749 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006750 } finally {
6751 Binder.restoreCallingIdentity(identity);
6752 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006753 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006754
6755 /**
6756 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6757 *
6758 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6759 * voicemail ringtone.
6760 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6761 * PhoneAccount.
6762 */
6763 @Override
6764 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006765 final long identity = Binder.clearCallingIdentity();
6766 try {
6767 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6768 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006769 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006770 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006771
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6773 } finally {
6774 Binder.restoreCallingIdentity(identity);
6775 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006776 }
6777
6778 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006779 * Sets the per-account voicemail ringtone.
6780 *
6781 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6782 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6783 *
6784 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6785 * voicemail ringtone.
6786 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6787 * PhoneAccount.
6788 */
6789 @Override
6790 public void setVoicemailRingtoneUri(String callingPackage,
6791 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006792 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006793 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006794 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6795 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6797 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6798 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006800
6801 final long identity = Binder.clearCallingIdentity();
6802 try {
6803 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6804 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006805 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 }
6807 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6808 } finally {
6809 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006810 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006811 }
6812
6813 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006814 * Returns whether vibration is set for voicemail notification in Phone settings.
6815 *
6816 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6817 * voicemail vibration setting.
6818 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6819 */
6820 @Override
6821 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006822 final long identity = Binder.clearCallingIdentity();
6823 try {
6824 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6825 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006826 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006827 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6830 } finally {
6831 Binder.restoreCallingIdentity(identity);
6832 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006833 }
6834
Youhan Wange64578a2016-05-02 15:32:42 -07006835 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006836 * Sets the per-account voicemail vibration.
6837 *
6838 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6839 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6840 *
6841 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6842 * voicemail vibration setting.
6843 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6844 * specific PhoneAccount.
6845 */
6846 @Override
6847 public void setVoicemailVibrationEnabled(String callingPackage,
6848 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006849 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006850 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006851 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6852 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6854 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6855 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006856 }
6857
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006858 final long identity = Binder.clearCallingIdentity();
6859 try {
6860 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6861 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006862 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863 }
6864 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6865 } finally {
6866 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006867 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006868 }
6869
6870 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006871 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6872 *
6873 * @throws SecurityException if the caller does not have the required permission
6874 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006875 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006876 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006877 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006878 }
6879
6880 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006881 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6882 * permission.
6883 *
6884 * @throws SecurityException if the caller does not have the required permission
6885 */
6886 private void enforceSendSmsPermission() {
6887 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6888 }
6889
6890 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006891 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006892 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006893 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006894 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006895 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006896 final long identity = Binder.clearCallingIdentity();
6897 try {
6898 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006899 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006900 if (componentName == null) {
6901 throw new SecurityException(
6902 "Caller not current active visual voicemail package[null]");
6903 }
6904 String vvmPackage = componentName.getPackageName();
6905 if (!callingPackage.equals(vvmPackage)) {
6906 throw new SecurityException("Caller not current active visual voicemail package["
6907 + vvmPackage + "]");
6908 }
6909 } finally {
6910 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006911 }
6912 }
6913
6914 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006915 * Return the application ID for the app type.
6916 *
6917 * @param subId the subscription ID that this request applies to.
6918 * @param appType the uicc app type.
6919 * @return Application ID for specificied app type, or null if no uicc.
6920 */
6921 @Override
6922 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006923 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006924 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006925
6926 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006927 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928 if (phone == null) {
6929 return null;
6930 }
6931 String aid = null;
6932 try {
6933 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6934 .getApplicationByType(appType).getAid();
6935 } catch (Exception e) {
6936 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6937 }
6938 return aid;
6939 } finally {
6940 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006941 }
Youhan Wange64578a2016-05-02 15:32:42 -07006942 }
6943
Youhan Wang4001d252016-05-11 10:29:41 -07006944 /**
6945 * Return the Electronic Serial Number.
6946 *
6947 * @param subId the subscription ID that this request applies to.
6948 * @return ESN or null if error.
6949 */
6950 @Override
6951 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006952 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006953 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006954
6955 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006956 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006957 if (phone == null) {
6958 return null;
6959 }
6960 String esn = null;
6961 try {
6962 esn = phone.getEsn();
6963 } catch (Exception e) {
6964 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6965 }
6966 return esn;
6967 } finally {
6968 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006969 }
Youhan Wang4001d252016-05-11 10:29:41 -07006970 }
6971
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006972 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006973 * Return the Preferred Roaming List Version.
6974 *
6975 * @param subId the subscription ID that this request applies to.
6976 * @return PRLVersion or null if error.
6977 */
6978 @Override
6979 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006980 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006981 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982
6983 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006984 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006985 if (phone == null) {
6986 return null;
6987 }
6988 String cdmaPrlVersion = null;
6989 try {
6990 cdmaPrlVersion = phone.getCdmaPrlVersion();
6991 } catch (Exception e) {
6992 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6993 }
6994 return cdmaPrlVersion;
6995 } finally {
6996 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006997 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006998 }
6999
7000 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007001 * Get snapshot of Telephony histograms
7002 * @return List of Telephony histograms
7003 * @hide
7004 */
7005 @Override
7006 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7008 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007009
7010 final long identity = Binder.clearCallingIdentity();
7011 try {
7012 return RIL.getTelephonyRILTimingHistograms();
7013 } finally {
7014 Binder.restoreCallingIdentity(identity);
7015 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007016 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007017
7018 /**
7019 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007020 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7021 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007022 * Require system privileges. In the future we may add this to carrier APIs.
7023 *
Michele Berionne482f8202018-11-27 18:57:59 -08007024 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007025 */
7026 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007027 @TelephonyManager.SetCarrierRestrictionResult
7028 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007029 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007030 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007031
Michele Berionne482f8202018-11-27 18:57:59 -08007032 if (carrierRestrictionRules == null) {
7033 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007034 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007035
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007036 final long identity = Binder.clearCallingIdentity();
7037 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007038 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007039 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 } finally {
7041 Binder.restoreCallingIdentity(identity);
7042 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007043 }
7044
7045 /**
7046 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007047 * Get the allowed carrier list and the excluded carrier list, including the priority between
7048 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007049 * Require system privileges. In the future we may add this to carrier APIs.
7050 *
Michele Berionne482f8202018-11-27 18:57:59 -08007051 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007052 */
7053 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007054 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007055 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007056 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057
7058 final long identity = Binder.clearCallingIdentity();
7059 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007060 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7061 if (response instanceof CarrierRestrictionRules) {
7062 return (CarrierRestrictionRules) response;
7063 }
7064 // Response is an Exception of some kind,
7065 // which is signalled to the user as a NULL retval
7066 return null;
7067 } catch (Exception e) {
7068 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7069 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070 } finally {
7071 Binder.restoreCallingIdentity(identity);
7072 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007073 }
7074
fionaxu59545b42016-05-25 15:53:37 -07007075 /**
fionaxu59545b42016-05-25 15:53:37 -07007076 * Action set from carrier signalling broadcast receivers to enable/disable radio
7077 * @param subId the subscription ID that this action applies to.
7078 * @param enabled control enable or disable radio.
7079 * {@hide}
7080 */
7081 @Override
7082 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7083 enforceModifyPermission();
7084 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007085
7086 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007087 if (phone == null) {
7088 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7089 return;
7090 }
7091 try {
7092 phone.carrierActionSetRadioEnabled(enabled);
7093 } catch (Exception e) {
7094 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095 } finally {
7096 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007097 }
7098 }
7099
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007100 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007101 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7102 * network status based on which carrier apps could apply actions accordingly,
7103 * enable/disable default url handler for example.
7104 *
7105 * @param subId the subscription ID that this action applies to.
7106 * @param report control start/stop reporting the default network status.
7107 * {@hide}
7108 */
7109 @Override
7110 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7111 enforceModifyPermission();
7112 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007113
7114 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007115 if (phone == null) {
7116 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7117 return;
7118 }
7119 try {
7120 phone.carrierActionReportDefaultNetworkStatus(report);
7121 } catch (Exception e) {
7122 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007123 } finally {
7124 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007125 }
7126 }
7127
7128 /**
fionaxud9622282017-07-17 17:51:30 -07007129 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7130 * @param subId the subscription ID that this action applies to.
7131 * {@hide}
7132 */
7133 @Override
7134 public void carrierActionResetAll(int subId) {
7135 enforceModifyPermission();
7136 final Phone phone = getPhone(subId);
7137 if (phone == null) {
7138 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7139 return;
7140 }
7141 try {
7142 phone.carrierActionResetAll();
7143 } catch (Exception e) {
7144 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7145 }
7146 }
7147
7148 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007149 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7150 * bug report is being generated.
7151 */
7152 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007153 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007154 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7155 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007156 writer.println("Permission Denial: can't dump Phone from pid="
7157 + Binder.getCallingPid()
7158 + ", uid=" + Binder.getCallingUid()
7159 + "without permission "
7160 + android.Manifest.permission.DUMP);
7161 return;
7162 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007163 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007164 }
Jack Yueb89b242016-06-22 13:27:47 -07007165
Brad Ebingerdac2f002018-04-03 15:17:52 -07007166 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007167 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7168 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7169 @NonNull String[] args) {
7170 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7171 this, in.getFileDescriptor(), out.getFileDescriptor(),
7172 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007173 }
7174
Jack Yueb89b242016-06-22 13:27:47 -07007175 /**
Sooraj Sasindran4872c7f2020-04-19 18:14:03 -07007176 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007177 * @param subId Subscription index
Sooraj Sasindran4872c7f2020-04-19 18:14:03 -07007178 * @param reason the reason the data enable change is taking place
7179 * @param enabled True if enabling the data, otherwise disabling.
7180 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007181 */
7182 @Override
Sooraj Sasindran4872c7f2020-04-19 18:14:03 -07007183 public void setDataEnabledWithReason(int subId, @TelephonyManager.DataEnabledReason int reason,
7184 boolean enabled) {
7185 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7186 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7187 try {
7188 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7189 mApp, subId, "setDataEnabledWithReason");
7190 } catch (SecurityException se) {
7191 enforceModifyPermission();
7192 }
7193 } else {
7194 enforceModifyPermission();
7195 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196
7197 final long identity = Binder.clearCallingIdentity();
7198 try {
7199 Phone phone = getPhone(subId);
7200 if (phone != null) {
Sooraj Sasindran4872c7f2020-04-19 18:14:03 -07007201 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7202 phone.carrierActionSetMeteredApnsEnabled(enabled);
7203 } else {
7204 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7205 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007206 }
7207 } finally {
7208 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007209 }
7210 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007211
7212 /**
7213 * Get Client request stats
7214 * @return List of Client Request Stats
7215 * @hide
7216 */
7217 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007218 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7219 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007220 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007221 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007222 return null;
7223 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007224 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007226 final long identity = Binder.clearCallingIdentity();
7227 try {
7228 if (phone != null) {
7229 return phone.getClientRequestStats();
7230 }
7231
7232 return null;
7233 } finally {
7234 Binder.restoreCallingIdentity(identity);
7235 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007236 }
7237
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007238 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007239 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007240 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007241 }
Jack Yueb4124c2017-02-16 15:32:43 -08007242
7243 /**
Grace Chen70990072017-03-24 17:21:30 -07007244 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007245 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007246 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007247 * @param state State of SIM (power down, power up, pass through)
7248 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7249 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7250 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007251 *
7252 **/
7253 @Override
Grace Chen70990072017-03-24 17:21:30 -07007254 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007255 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007256 Phone phone = PhoneFactory.getPhone(slotIndex);
7257
vagdeviaf9a5b92018-08-15 16:01:53 -07007258 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260 final long identity = Binder.clearCallingIdentity();
7261 try {
7262 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007263 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007264 }
7265 } finally {
7266 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007267 }
7268 }
Shuo Qiandd210312017-04-12 22:11:33 +00007269
Tyler Gunn65d45c22017-06-05 11:22:26 -07007270 private boolean isUssdApiAllowed(int subId) {
7271 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007272 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007273 if (configManager == null) {
7274 return false;
7275 }
7276 PersistableBundle pb = configManager.getConfigForSubId(subId);
7277 if (pb == null) {
7278 return false;
7279 }
7280 return pb.getBoolean(
7281 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7282 }
7283
Shuo Qiandd210312017-04-12 22:11:33 +00007284 /**
7285 * Check if phone is in emergency callback mode
7286 * @return true if phone is in emergency callback mode
7287 * @param subId sub id
7288 */
goneil9c5f4872017-12-05 14:07:56 -08007289 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007290 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007291 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007292 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007293
7294 final long identity = Binder.clearCallingIdentity();
7295 try {
7296 if (phone != null) {
7297 return phone.isInEcm();
7298 } else {
7299 return false;
7300 }
7301 } finally {
7302 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007303 }
7304 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007305
7306 /**
7307 * Get the current signal strength information for the given subscription.
7308 * Because this information is not updated when the device is in a low power state
7309 * it should not be relied-upon to be current.
7310 * @param subId Subscription index
7311 * @return the most recent cached signal strength info from the modem
7312 */
7313 @Override
7314 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315 final long identity = Binder.clearCallingIdentity();
7316 try {
7317 Phone p = getPhone(subId);
7318 if (p == null) {
7319 return null;
7320 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007322 return p.getSignalStrength();
7323 } finally {
7324 Binder.restoreCallingIdentity(identity);
7325 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007326 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007327
Pengquan Meng77b7f132018-08-22 14:49:57 -07007328 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007329 * Get the current modem radio state for the given slot.
7330 * @param slotIndex slot index.
7331 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007332 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007333 * @return the current radio power state from the modem
7334 */
7335 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007336 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007337 Phone phone = PhoneFactory.getPhone(slotIndex);
7338 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007339 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7340 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007341 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7342 }
7343
7344 final long identity = Binder.clearCallingIdentity();
7345 try {
7346 return phone.getRadioPowerState();
7347 } finally {
7348 Binder.restoreCallingIdentity(identity);
7349 }
7350 }
7351 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7352 }
7353
7354 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007355 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7356 *
7357 * <p>Requires one of the following permissions:
7358 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7359 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7360 * privileges.
7361 *
7362 * @param subId subscription id
7363 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7364 * {@code false}.
7365 */
7366 @Override
7367 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007368 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7369 null /* message */);
7370
Pengquan Menga1bb6272018-09-06 09:59:22 -07007371 boolean isEnabled = false;
7372 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007373 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007374 Phone phone = getPhone(subId);
7375 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007376 } catch (Exception e) {
7377 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7378 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007379 } finally {
7380 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007381 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007382 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007383 }
7384
7385
7386 /**
7387 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7388 *
7389 * <p> Requires permission:
7390 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7391 * privileges.
7392 *
7393 * @param subId subscription id
7394 * @param isEnabled {@code true} means enable, {@code false} means disable.
7395 */
7396 @Override
7397 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7399 mApp, subId, "setDataRoamingEnabled");
7400
Pengquan Menga1bb6272018-09-06 09:59:22 -07007401 final long identity = Binder.clearCallingIdentity();
7402 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007403 Phone phone = getPhone(subId);
7404 if (phone != null) {
7405 phone.setDataRoamingEnabled(isEnabled);
7406 }
7407 } finally {
7408 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007409 }
7410 }
7411
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007412 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007413 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007414 TelephonyPermissions
7415 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007416 mApp, subId, "isManualNetworkSelectionAllowed");
7417
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007418 boolean isAllowed = true;
7419 final long identity = Binder.clearCallingIdentity();
7420 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007421 Phone phone = getPhone(subId);
7422 if (phone != null) {
7423 isAllowed = phone.isCspPlmnEnabled();
7424 }
7425 } finally {
7426 Binder.restoreCallingIdentity(identity);
7427 }
7428 return isAllowed;
7429 }
7430
7431 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007432 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007433 // Verify that tha callingPackage belongs to the calling UID
7434 mApp.getSystemService(AppOpsManager.class)
7435 .checkPackage(Binder.getCallingUid(), callingPackage);
7436
Jordan Liu1e142fc2019-04-22 15:10:43 -07007437 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007438 try {
7439 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007440 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007441 } catch (SecurityException e) {
7442 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7443 // has carrier privileges on an active UICC
7444 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7445 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007446 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007447 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007448 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007449
7450 final long identity = Binder.clearCallingIdentity();
7451 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007452 UiccController uiccController = UiccController.getInstance();
7453 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007454 if (hasReadPermission) {
7455 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007456 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007457
7458 // Remove private info if the caller doesn't have access
7459 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7460 for (UiccCardInfo cardInfo : cardInfos) {
7461 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7462 // is available
7463 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7464 if (card == null || card.getUiccProfile() == null) {
7465 // assume no access if the card or profile is unavailable
7466 filteredInfos.add(cardInfo.getUnprivileged());
7467 continue;
7468 }
7469 UiccProfile profile = card.getUiccProfile();
7470 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7471 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7472 filteredInfos.add(cardInfo);
7473 } else {
7474 filteredInfos.add(cardInfo.getUnprivileged());
7475 }
7476 }
7477 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007478 } finally {
7479 Binder.restoreCallingIdentity(identity);
7480 }
7481 }
7482
7483 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007484 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007485 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 final long identity = Binder.clearCallingIdentity();
7488 try {
7489 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7490 if (slots == null) {
7491 Rlog.i(LOG_TAG, "slots is null.");
7492 return null;
7493 }
7494
7495 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7496 for (int i = 0; i < slots.length; i++) {
7497 UiccSlot slot = slots[i];
7498 if (slot == null) {
7499 continue;
7500 }
7501
Jordan Liu7be7e652019-05-06 18:55:02 +00007502 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 UiccCard card = slot.getUiccCard();
7504 if (card != null) {
7505 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007506 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007507 cardId = slot.getEid();
7508 if (TextUtils.isEmpty(cardId)) {
7509 cardId = slot.getIccId();
7510 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 }
7512
Jordan Liu857451f2019-05-09 16:35:35 -07007513 if (cardId != null) {
7514 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7515 // if cardId is an EID, it's all digits so this is fine
7516 cardId = IccUtils.stripTrailingFs(cardId);
7517 }
7518
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007519 int cardState = 0;
7520 switch (slot.getCardState()) {
7521 case CARDSTATE_ABSENT:
7522 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7523 break;
7524 case CARDSTATE_PRESENT:
7525 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7526 break;
7527 case CARDSTATE_ERROR:
7528 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7529 break;
7530 case CARDSTATE_RESTRICTED:
7531 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7532 break;
7533 default:
7534 break;
7535
7536 }
7537
7538 infos[i] = new UiccSlotInfo(
7539 slot.isActive(),
7540 slot.isEuicc(),
7541 cardId,
7542 cardState,
7543 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007544 slot.isExtendedApduSupported(),
7545 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007546 }
7547 return infos;
7548 } finally {
7549 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007550 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007551 }
7552
7553 @Override
7554 public boolean switchSlots(int[] physicalSlots) {
7555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556
7557 final long identity = Binder.clearCallingIdentity();
7558 try {
7559 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7560 } finally {
7561 Binder.restoreCallingIdentity(identity);
7562 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007563 }
Jack Yu4c988042018-02-27 15:30:01 -08007564
7565 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007566 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007567 final long identity = Binder.clearCallingIdentity();
7568 try {
7569 return UiccController.getInstance().getCardIdForDefaultEuicc();
7570 } finally {
7571 Binder.restoreCallingIdentity(identity);
7572 }
7573 }
7574
Pengquan Meng85728fb2018-03-12 16:31:21 -07007575 /**
goneil47ffb6e2018-04-06 15:40:58 -07007576 * A test API to reload the UICC profile.
7577 *
7578 * <p>Requires that the calling app has permission
7579 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7580 * @hide
7581 */
7582 @Override
7583 public void refreshUiccProfile(int subId) {
7584 enforceModifyPermission();
7585
7586 final long identity = Binder.clearCallingIdentity();
7587 try {
7588 Phone phone = getPhone(subId);
7589 if (phone == null) {
7590 return;
7591 }
7592 UiccCard uiccCard = phone.getUiccCard();
7593 if (uiccCard == null) {
7594 return;
7595 }
7596 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7597 if (uiccProfile == null) {
7598 return;
7599 }
7600 uiccProfile.refresh();
7601 } finally {
7602 Binder.restoreCallingIdentity(identity);
7603 }
7604 }
7605
7606 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007607 * Returns false if the mobile data is disabled by default, otherwise return true.
7608 */
7609 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007610 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007611 }
7612
7613 /**
7614 * Returns true if the data roaming is enabled by default, i.e the system property
7615 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7616 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7617 */
7618 private boolean getDefaultDataRoamingEnabled(int subId) {
7619 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007620 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007621 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007622 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7623 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7624 return isDataRoamingEnabled;
7625 }
7626
7627 /**
7628 * Returns the default network type for the given {@code subId}, if the default network type is
7629 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7630 */
7631 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007632 List<Integer> list = TelephonyProperties.default_network();
7633 int phoneId = mSubscriptionController.getPhoneId(subId);
7634 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7635 return list.get(phoneId);
7636 }
7637 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007638 }
fionaxua13278b2018-03-21 00:08:13 -07007639
7640 @Override
7641 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007642 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007643 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007644
7645 final long identity = Binder.clearCallingIdentity();
7646 try {
7647 final Phone phone = getPhone(subId);
7648 if (phone == null) {
7649 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7650 return;
7651 }
chen xueaba88a2019-03-15 13:15:10 -07007652 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7653 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007654 } finally {
7655 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007656 }
fionaxua13278b2018-03-21 00:08:13 -07007657 }
7658
7659 @Override
7660 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007661 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662
7663 final long identity = Binder.clearCallingIdentity();
7664 try {
7665 final Phone phone = getPhone(subId);
7666 if (phone == null) {
7667 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7668 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7669 }
7670 return phone.getCarrierIdListVersion();
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007673 }
fionaxua13278b2018-03-21 00:08:13 -07007674 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007675
7676 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007677 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7678 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007679 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007680 mApp, subId, callingPackage, callingFeatureId,
7681 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007682 return -1;
7683 }
7684
7685 final long identity = Binder.clearCallingIdentity();
7686 try {
7687 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7688 } finally {
7689 Binder.restoreCallingIdentity(identity);
7690 }
7691 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007692
7693 @Override
7694 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007695 TelephonyPermissions
7696 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007697 mApp, subId, "getCdmaRoamingMode");
7698
7699 final long identity = Binder.clearCallingIdentity();
7700 try {
7701 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7702 } finally {
7703 Binder.restoreCallingIdentity(identity);
7704 }
7705 }
7706
7707 @Override
7708 public boolean setCdmaRoamingMode(int subId, int mode) {
7709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7710 mApp, subId, "setCdmaRoamingMode");
7711
7712 final long identity = Binder.clearCallingIdentity();
7713 try {
7714 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7715 } finally {
7716 Binder.restoreCallingIdentity(identity);
7717 }
7718 }
7719
7720 @Override
7721 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7723 mApp, subId, "setCdmaSubscriptionMode");
7724
7725 final long identity = Binder.clearCallingIdentity();
7726 try {
7727 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7728 } finally {
7729 Binder.restoreCallingIdentity(identity);
7730 }
7731 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007732
sqianc5eccab2018-10-19 18:46:41 -07007733 @Override
sqian8c685422019-02-22 15:55:18 -08007734 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007735 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007737 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7738 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007739 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7740 }
7741 final long identity = Binder.clearCallingIdentity();
7742 try {
sqian854d44b2018-12-12 16:48:18 -08007743 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7744 for (Phone phone: PhoneFactory.getPhones()) {
7745 if (phone.getEmergencyNumberTracker() != null
7746 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7747 emergencyNumberListInternal.put(
7748 phone.getSubId(),
7749 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7750 }
sqian11b7a0e2018-12-05 18:48:28 -08007751 }
sqian854d44b2018-12-12 16:48:18 -08007752 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007753 } finally {
7754 Binder.restoreCallingIdentity(identity);
7755 }
sqianc5eccab2018-10-19 18:46:41 -07007756 }
7757
7758 @Override
sqian8c685422019-02-22 15:55:18 -08007759 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007760 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007761 if (!exactMatch) {
7762 TelephonyPermissions
7763 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007764 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007765 }
7766 final long identity = Binder.clearCallingIdentity();
7767 try {
sqian854d44b2018-12-12 16:48:18 -08007768 for (Phone phone: PhoneFactory.getPhones()) {
7769 if (phone.getEmergencyNumberTracker() != null
7770 && phone.getEmergencyNumberTracker() != null) {
7771 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7772 number, exactMatch)) {
7773 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007774 }
7775 }
sqian11b7a0e2018-12-05 18:48:28 -08007776 }
7777 return false;
7778 } finally {
7779 Binder.restoreCallingIdentity(identity);
7780 }
7781 }
7782
sqianf4ca7ed2019-01-15 18:32:07 -08007783 /**
7784 * Update emergency number list for test mode.
7785 */
7786 @Override
7787 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7788 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7789 "updateEmergencyNumberListTestMode");
7790
7791 final long identity = Binder.clearCallingIdentity();
7792 try {
7793 for (Phone phone: PhoneFactory.getPhones()) {
7794 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7795 if (tracker != null) {
7796 tracker.executeEmergencyNumberTestModeCommand(action, num);
7797 }
7798 }
7799 } finally {
7800 Binder.restoreCallingIdentity(identity);
7801 }
7802 }
7803
7804 /**
7805 * Get the full emergency number list for test mode.
7806 */
7807 @Override
7808 public List<String> getEmergencyNumberListTestMode() {
7809 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7810 "getEmergencyNumberListTestMode");
7811
7812 final long identity = Binder.clearCallingIdentity();
7813 try {
7814 Set<String> emergencyNumbers = new HashSet<>();
7815 for (Phone phone: PhoneFactory.getPhones()) {
7816 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7817 if (tracker != null) {
7818 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7819 emergencyNumbers.add(num.getNumber());
7820 }
7821 }
7822 }
7823 return new ArrayList<>(emergencyNumbers);
7824 } finally {
7825 Binder.restoreCallingIdentity(identity);
7826 }
7827 }
7828
chen xud6b45bd2018-10-30 22:27:10 -07007829 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007830 public int getEmergencyNumberDbVersion(int subId) {
7831 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7832
7833 final long identity = Binder.clearCallingIdentity();
7834 try {
7835 final Phone phone = getPhone(subId);
7836 if (phone == null) {
7837 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7838 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7839 }
7840 return phone.getEmergencyNumberDbVersion();
7841 } finally {
7842 Binder.restoreCallingIdentity(identity);
7843 }
7844 }
7845
7846 @Override
7847 public void notifyOtaEmergencyNumberDbInstalled() {
7848 enforceModifyPermission();
7849
7850 final long identity = Binder.clearCallingIdentity();
7851 try {
7852 for (Phone phone: PhoneFactory.getPhones()) {
7853 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7854 if (tracker != null) {
7855 tracker.updateOtaEmergencyNumberDatabase();
7856 }
7857 }
7858 } finally {
7859 Binder.restoreCallingIdentity(identity);
7860 }
7861 }
7862
7863 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08007864 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08007865 enforceActiveEmergencySessionPermission();
7866
7867 final long identity = Binder.clearCallingIdentity();
7868 try {
7869 for (Phone phone: PhoneFactory.getPhones()) {
7870 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7871 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08007872 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7873 }
7874 }
7875 } finally {
7876 Binder.restoreCallingIdentity(identity);
7877 }
7878 }
7879
7880 @Override
7881 public void resetOtaEmergencyNumberDbFilePath() {
7882 enforceActiveEmergencySessionPermission();
7883
7884 final long identity = Binder.clearCallingIdentity();
7885 try {
7886 for (Phone phone: PhoneFactory.getPhones()) {
7887 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7888 if (tracker != null) {
7889 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08007890 }
7891 }
7892 } finally {
7893 Binder.restoreCallingIdentity(identity);
7894 }
7895 }
7896
7897 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007898 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7899 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7900 Phone phone = getPhone(subId);
7901 if (phone == null) {
7902 return null;
7903 }
7904 final long identity = Binder.clearCallingIdentity();
7905 try {
7906 UiccProfile profile = UiccController.getInstance()
7907 .getUiccProfileForPhone(phone.getPhoneId());
7908 if (profile != null) {
7909 return profile.getCertsFromCarrierPrivilegeAccessRules();
7910 }
7911 } finally {
7912 Binder.restoreCallingIdentity(identity);
7913 }
7914 return null;
7915 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007916
7917 /**
7918 * Enable or disable a modem stack.
7919 */
7920 @Override
7921 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7922 enforceModifyPermission();
7923
7924 final long identity = Binder.clearCallingIdentity();
7925 try {
7926 Phone phone = PhoneFactory.getPhone(slotIndex);
7927 if (phone == null) {
7928 return false;
7929 } else {
7930 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7931 }
7932 } finally {
7933 Binder.restoreCallingIdentity(identity);
7934 }
7935 }
Michelecea4cf22018-12-21 15:00:11 -08007936
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007937 /**
7938 * Whether a modem stack is enabled or not.
7939 */
7940 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007941 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7942 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007943 Phone phone = PhoneFactory.getPhone(slotIndex);
7944 if (phone == null) return false;
7945
7946 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007947 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7948 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007949 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7950 }
7951
7952 final long identity = Binder.clearCallingIdentity();
7953 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007954 try {
7955 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7956 } catch (NoSuchElementException ex) {
7957 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7958 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007959 } finally {
7960 Binder.restoreCallingIdentity(identity);
7961 }
7962 }
7963
Michelecea4cf22018-12-21 15:00:11 -08007964 @Override
Michele0ea7d782019-03-19 14:58:42 -07007965 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007966 enforceModifyPermission();
7967
7968 final long identity = Binder.clearCallingIdentity();
7969 try {
7970 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007971 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007972 .commit();
7973 } finally {
7974 Binder.restoreCallingIdentity(identity);
7975 }
7976 }
7977
7978 @Override
Michele0ea7d782019-03-19 14:58:42 -07007979 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007980 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007982 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7983 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007984 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007985 }
Michelecea4cf22018-12-21 15:00:11 -08007986
7987 final long identity = Binder.clearCallingIdentity();
7988 try {
Michele0ea7d782019-03-19 14:58:42 -07007989 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007990 } finally {
7991 Binder.restoreCallingIdentity(identity);
7992 }
7993 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007994
Michele0ea7d782019-03-19 14:58:42 -07007995 @TelephonyManager.IsMultiSimSupportedResult
7996 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007997 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7998 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7999 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008000 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8001 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008002 }
8003 // Check if the hardware supports multisim functionality. If usage of multisim is not
8004 // supported by the modem, indicate that it is restricted.
8005 PhoneCapability staticCapability =
8006 mPhoneConfigurationManager.getStaticPhoneCapability();
8007 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008008 loge("isMultiSimSupportedInternal: no static configuration available");
8009 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008010 }
Sarah Chin7caee492020-02-18 20:49:02 +00008011 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008012 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8013 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008014 }
8015 // Check if support of multiple SIMs is restricted by carrier
8016 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008017 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008018 }
8019
Michele0ea7d782019-03-19 14:58:42 -07008020 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008021 }
8022
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008023 /**
8024 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008025 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8026 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8027 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008028 * @param numOfSims number of active sims we want to switch to
8029 */
8030 @Override
8031 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008032 if (numOfSims == 1) {
8033 enforceModifyPermission();
8034 } else {
8035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8036 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8037 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008038 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008039
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008040 try {
Michele30b57b22019-03-01 12:01:14 -08008041 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008042 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008043 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8044 return;
8045 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008046 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8047 } finally {
8048 Binder.restoreCallingIdentity(identity);
8049 }
8050 }
8051
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008052 @Override
8053 public boolean isApplicationOnUicc(int subId, int appType) {
8054 enforceReadPrivilegedPermission("isApplicationOnUicc");
8055 Phone phone = getPhone(subId);
8056 if (phone == null) {
8057 return false;
8058 }
8059 final long identity = Binder.clearCallingIdentity();
8060 try {
8061 UiccCard uiccCard = phone.getUiccCard();
8062 if (uiccCard == null) {
8063 return false;
8064 }
8065 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8066 if (uiccProfile == null) {
8067 return false;
8068 }
8069 if (TelephonyManager.APPTYPE_SIM <= appType
8070 && appType <= TelephonyManager.APPTYPE_ISIM) {
8071 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8072 }
8073 return false;
8074 } finally {
8075 Binder.restoreCallingIdentity(identity);
8076 }
8077 }
8078
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008079 /**
chen xub4baa772019-04-03 10:23:41 -07008080 * Get whether making changes to modem configurations will trigger reboot.
8081 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008082 */
8083 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008084 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8085 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008086 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008087 mApp, subId, callingPackage, callingFeatureId,
8088 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008089 return false;
8090 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008091 final long identity = Binder.clearCallingIdentity();
8092 try {
8093 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8094 } finally {
8095 Binder.restoreCallingIdentity(identity);
8096 }
8097 }
8098
Nathan Harold29f5f052019-02-15 13:41:57 -08008099 private void updateModemStateMetrics() {
8100 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8101 // TODO: check the state for each modem if the api is ready.
8102 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8103 }
8104
Pengquan Meng3889a572019-01-23 11:16:29 -08008105 @Override
8106 public int[] getSlotsMapping() {
8107 enforceReadPrivilegedPermission("getSlotsMapping");
8108
8109 final long identity = Binder.clearCallingIdentity();
8110 try {
8111 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8112 // All logical slots should have a mapping to a physical slot.
8113 int[] logicalSlotsMapping = new int[phoneCount];
8114 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8115 for (int i = 0; i < slotInfos.length; i++) {
8116 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8117 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8118 }
8119 }
8120 return logicalSlotsMapping;
8121 } finally {
8122 Binder.restoreCallingIdentity(identity);
8123 }
8124 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008125
8126 /**
8127 * Get the IRadio HAL Version
8128 */
8129 @Override
8130 public int getRadioHalVersion() {
8131 Phone phone = getDefaultPhone();
8132 if (phone == null) return -1;
8133 HalVersion hv = phone.getHalVersion();
8134 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8135 return hv.major * 100 + hv.minor;
8136 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008137
8138 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008139 * Get the current calling package name.
8140 * @return the current calling package name
8141 */
8142 @Override
8143 public String getCurrentPackageName() {
8144 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8145 }
8146
8147 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008148 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8149 * corresponding network requests on a subId.
8150 *
8151 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008152 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008153 * 2) APN is un-metered for this subscription, or
8154 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008155 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008156 *
8157 * @return whether data is allowed for a apn type.
8158 *
8159 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008160 */
8161 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008162 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008163 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8164 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008165
8166 // Now that all security checks passes, perform the operation as ourselves.
8167 final long identity = Binder.clearCallingIdentity();
8168 try {
8169 Phone phone = getPhone(subId);
8170 if (phone == null) return false;
8171
Jack Yu41407ee2019-05-13 16:54:09 -07008172 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008173 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8174 } finally {
8175 Binder.restoreCallingIdentity(identity);
8176 }
8177 }
8178
8179 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008180 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008181 enforceReadPrivilegedPermission("isApnMetered");
8182
8183 // Now that all security checks passes, perform the operation as ourselves.
8184 final long identity = Binder.clearCallingIdentity();
8185 try {
8186 Phone phone = getPhone(subId);
8187 if (phone == null) return true; // By default return true.
8188
Jack Yu41407ee2019-05-13 16:54:09 -07008189 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008190 } finally {
8191 Binder.restoreCallingIdentity(identity);
8192 }
8193 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008194
8195 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008196 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8197 int subscriptionId, IBooleanConsumer resultCallback) {
8198 enforceModifyPermission();
8199 long token = Binder.clearCallingIdentity();
8200 try {
8201 Phone phone = getPhone(subscriptionId);
8202 if (phone == null) {
8203 try {
8204 if (resultCallback != null) {
8205 resultCallback.accept(false);
8206 }
8207 } catch (RemoteException e) {
8208 // ignore
8209 }
8210 return;
8211 }
8212 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8213 Pair.create(specifiers, (x) -> {
8214 try {
8215 if (resultCallback != null) {
8216 resultCallback.accept(x);
8217 }
8218 } catch (RemoteException e) {
8219 // ignore
8220 }
8221 });
8222 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8223 } finally {
8224 Binder.restoreCallingIdentity(token);
8225 }
8226 }
8227
8228 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008229 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008230 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008231 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8232 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8233 if (iccRecords == null) {
8234 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8235 return false;
8236 }
8237 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8238 }
8239
8240 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008241 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8242 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008243 if (callingPackage == null) {
8244 callingPackage = getCurrentPackageName();
8245 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008246 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8247 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008248 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8249 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008250 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 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008507
8508 @Override
8509 public boolean canConnectTo5GInDsdsMode() {
8510 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8511 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008512}