blob: 1a131e42a83fb37c416d3c142b6d39c610200002 [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.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700108import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700109import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800110import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800111import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800113import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700116import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800119
Andrew Lee312e8172014-10-23 17:01:36 -0700120import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800121import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800122import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800129import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800131import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800132import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700133import com.android.internal.telephony.ICallForwardingInfoCallback;
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;
Hall Liu27d24262020-09-18 19:04:59 -0700174import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800175import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700176import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800178import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700179import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700180import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800181import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800182
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700183import java.io.FileDescriptor;
184import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800187import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800189import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100190import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800191import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700192import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800193import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800194import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197/**
198 * Implementation of the ITelephony interface.
199 */
Santos Cordon117fee72014-05-16 17:56:12 -0700200public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 private static final String LOG_TAG = "PhoneInterfaceManager";
202 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
203 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800204 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205
206 // Message codes used with mMainThreadHandler
207 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700208 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
209 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700210 private static final int CMD_OPEN_CHANNEL = 9;
211 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
212 private static final int CMD_CLOSE_CHANNEL = 11;
213 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800214 private static final int CMD_NV_READ_ITEM = 13;
215 private static final int EVENT_NV_READ_ITEM_DONE = 14;
216 private static final int CMD_NV_WRITE_ITEM = 15;
217 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
218 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
219 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700220 private static final int CMD_RESET_MODEM_CONFIG = 19;
221 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800222 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
223 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
224 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
225 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800226 private static final int CMD_SEND_ENVELOPE = 25;
227 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000228 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
229 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700230 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
231 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
232 private static final int CMD_EXCHANGE_SIM_IO = 31;
233 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800234 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
235 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700236 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
237 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700238 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
239 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700240 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
241 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
242 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
243 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700244 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
245 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
246 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
247 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700248 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800249 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
250 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000251 private static final int CMD_SWITCH_SLOTS = 50;
252 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700253 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
254 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
255 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
256 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
257 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
258 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
259 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
260 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700261 private static final int CMD_GET_ALL_CELL_INFO = 60;
262 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
263 private static final int CMD_GET_CELL_LOCATION = 62;
264 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_MODEM_REBOOT = 64;
266 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700267 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
268 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800269 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
270 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700271 private static final int CMD_GET_MODEM_STATUS = 70;
272 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700273 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
274 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700275 private static final int CMD_ERASE_MODEM_CONFIG = 74;
276 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800277 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
278 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
279 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
280 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800281 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
282 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800283 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800284 private static final int CMD_GET_CALL_FORWARDING = 83;
285 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
286 private static final int CMD_SET_CALL_FORWARDING = 85;
287 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
288 private static final int CMD_GET_CALL_WAITING = 87;
289 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
290 private static final int CMD_SET_CALL_WAITING = 89;
291 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800293 // Parameters of select command.
294 private static final int SELECT_COMMAND = 0xA4;
295 private static final int SELECT_P1 = 0x04;
296 private static final int SELECT_P2 = 0;
297 private static final int SELECT_P3 = 0x10;
298
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 /** The singleton instance. */
300 private static PhoneInterfaceManager sInstance;
301
Wink Saville3ab207e2014-11-20 13:07:20 -0800302 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800303 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800304 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700305 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800306 private AppOpsManager mAppOps;
307 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800308 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800309 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700310 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311
Peter Wangdafb9ac2020-01-15 14:13:38 -0800312 /** User Activity */
313 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800314 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
315
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700316 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
317
Derek Tan97ebb422014-09-05 16:55:38 -0700318 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
319 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800320 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800321 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700322
Michelecea4cf22018-12-21 15:00:11 -0800323 // String to store multi SIM allowed
324 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
325
Derek Tan740e1672017-06-27 14:56:27 -0700326 // The AID of ISD-R.
327 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
328
yinxub1bed742017-04-17 11:45:04 -0700329 private NetworkScanRequestTracker mNetworkScanRequestTracker;
330
David Kelly5e06a7f2018-03-12 14:10:59 +0000331 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
332 private static final int MANUFACTURER_CODE_LENGTH = 8;
333
Derek Tan89e89d42014-07-08 17:00:10 -0700334 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700335 * Experiment flag to enable erase modem config on reset network, default value is false
336 */
337 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
338 "reset_network_erase_modem_config_enabled";
339
340 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700341 * A request object to use for transmitting data to an ICC.
342 */
343 private static final class IccAPDUArgument {
344 public int channel, cla, command, p1, p2, p3;
345 public String data;
346
347 public IccAPDUArgument(int channel, int cla, int command,
348 int p1, int p2, int p3, String data) {
349 this.channel = channel;
350 this.cla = cla;
351 this.command = command;
352 this.p1 = p1;
353 this.p2 = p2;
354 this.p3 = p3;
355 this.data = data;
356 }
357 }
358
359 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700360 * A request object to use for transmitting data to an ICC.
361 */
362 private static final class ManualNetworkSelectionArgument {
363 public OperatorInfo operatorInfo;
364 public boolean persistSelection;
365
366 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
367 this.operatorInfo = operatorInfo;
368 this.persistSelection = persistSelection;
369 }
370 }
371
372 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
374 * request after sending. The main thread will notify the request when it is complete.
375 */
376 private static final class MainThreadRequest {
377 /** The argument to use for the request */
378 public Object argument;
379 /** The result of the request that is run on the main thread */
380 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800381 // The subscriber id that this request applies to. Defaults to
382 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
383 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
Nathan Harold92bed182018-10-12 18:16:49 -0700385 // In cases where subId is unavailable, the caller needs to specify the phone.
386 public Phone phone;
387
vagdeviaf9a5b92018-08-15 16:01:53 -0700388 public WorkSource workSource;
389
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390 public MainThreadRequest(Object argument) {
391 this.argument = argument;
392 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800393
Nathan Harold92bed182018-10-12 18:16:49 -0700394 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
395 this.argument = argument;
396 if (phone != null) {
397 this.phone = phone;
398 }
399 this.workSource = workSource;
400 }
401
vagdeviaf9a5b92018-08-15 16:01:53 -0700402 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800403 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800404 if (subId != null) {
405 this.subId = subId;
406 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700407 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 }
410
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800411 private static final class IncomingThirdPartyCallArgs {
412 public final ComponentName component;
413 public final String callId;
414 public final String callerDisplayName;
415
416 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
417 String callerDisplayName) {
418 this.component = component;
419 this.callId = callId;
420 this.callerDisplayName = callerDisplayName;
421 }
422 }
423
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 /**
425 * A handler that processes messages on the main thread in the phone process. Since many
426 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
427 * inbound binder threads to the main thread in the phone process. The Binder thread
428 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
429 * on, which will be notified when the operation completes and will contain the result of the
430 * request.
431 *
432 * <p>If a MainThreadRequest object is provided in the msg.obj field,
433 * note that request.result must be set to something non-null for the calling thread to
434 * unblock.
435 */
436 private final class MainThreadHandler extends Handler {
437 @Override
438 public void handleMessage(Message msg) {
439 MainThreadRequest request;
440 Message onCompleted;
441 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800442 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800444 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
446 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700447 case CMD_HANDLE_USSD_REQUEST: {
448 request = (MainThreadRequest) msg.obj;
449 final Phone phone = getPhoneFromRequest(request);
450 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
451 String ussdRequest = ussdObject.first;
452 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700453
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 if (!isUssdApiAllowed(request.subId)) {
455 // Carrier does not support use of this API, return failure.
456 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
457 UssdResponse response = new UssdResponse(ussdRequest, null);
458 Bundle returnData = new Bundle();
459 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
460 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700461
Pengquan Menga1bb6272018-09-06 09:59:22 -0700462 request.result = true;
463 notifyRequester(request);
464 return;
465 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700466
Pengquan Menga1bb6272018-09-06 09:59:22 -0700467 try {
468 request.result = phone != null
469 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
470 } catch (CallStateException cse) {
471 request.result = false;
472 }
473 // Wake up the requesting thread
474 notifyRequester(request);
475 break;
pkanwar32d516d2016-10-14 19:37:38 -0700476 }
477
Yorke Lee716f67e2015-06-17 15:39:16 -0700478 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700480 final Phone phone = getPhoneFromRequest(request);
481 request.result = phone != null ?
482 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
483 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700493 if (uiccCard == null) {
494 loge("iccTransmitApduLogicalChannel: No UICC");
495 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700497 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
499 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700500 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 iccArgument.channel, iccArgument.cla, iccArgument.command,
502 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700504 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 break;
506
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 ar = (AsyncResult) msg.obj;
509 request = (MainThreadRequest) ar.userObj;
510 if (ar.exception == null && ar.result != null) {
511 request.result = ar.result;
512 } else {
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
514 if (ar.result == null) {
515 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800516 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800518 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700519 } else {
520 loge("iccTransmitApduLogicalChannel: Unknown exception");
521 }
522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700524 break;
525
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
527 request = (MainThreadRequest) msg.obj;
528 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 if (uiccCard == null) {
531 loge("iccTransmitApduBasicChannel: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 } else {
535 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
536 request);
537 uiccCard.iccTransmitApduBasicChannel(
538 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
539 iccArgument.p3, iccArgument.data, onCompleted);
540 }
541 break;
542
543 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
544 ar = (AsyncResult) msg.obj;
545 request = (MainThreadRequest) ar.userObj;
546 if (ar.exception == null && ar.result != null) {
547 request.result = ar.result;
548 } else {
549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
550 if (ar.result == null) {
551 loge("iccTransmitApduBasicChannel: Empty response");
552 } else if (ar.exception instanceof CommandException) {
553 loge("iccTransmitApduBasicChannel: CommandException: " +
554 ar.exception);
555 } else {
556 loge("iccTransmitApduBasicChannel: Unknown exception");
557 }
558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 break;
561
562 case CMD_EXCHANGE_SIM_IO:
563 request = (MainThreadRequest) msg.obj;
564 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 if (uiccCard == null) {
567 loge("iccExchangeSimIO: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
572 request);
573 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
574 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
575 iccArgument.data, onCompleted);
576 }
577 break;
578
579 case EVENT_EXCHANGE_SIM_IO_DONE:
580 ar = (AsyncResult) msg.obj;
581 request = (MainThreadRequest) ar.userObj;
582 if (ar.exception == null && ar.result != null) {
583 request.result = ar.result;
584 } else {
585 request.result = new IccIoResult(0x6f, 0, (byte[])null);
586 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 break;
589
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 case CMD_SEND_ENVELOPE:
591 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800592 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 if (uiccCard == null) {
594 loge("sendEnvelopeWithStatus: No UICC");
595 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 } else {
598 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
599 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
600 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800601 break;
602
603 case EVENT_SEND_ENVELOPE_DONE:
604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800608 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700609 request.result = new IccIoResult(0x6F, 0, (byte[])null);
610 if (ar.result == null) {
611 loge("sendEnvelopeWithStatus: Empty response");
612 } else if (ar.exception instanceof CommandException) {
613 loge("sendEnvelopeWithStatus: CommandException: " +
614 ar.exception);
615 } else {
616 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
617 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800620 break;
621
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 case CMD_OPEN_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800624 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800625 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 if (uiccCard == null) {
627 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800628 request.result = new IccOpenLogicalChannelResponse(-1,
629 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 } else {
632 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800633 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
634 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 break;
637
638 case EVENT_OPEN_CHANNEL_DONE:
639 ar = (AsyncResult) msg.obj;
640 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 int[] result = (int[]) ar.result;
644 int channelId = result[0];
645 byte[] selectResponse = null;
646 if (result.length > 1) {
647 selectResponse = new byte[result.length - 1];
648 for (int i = 1; i < result.length; ++i) {
649 selectResponse[i - 1] = (byte) result[i];
650 }
651 }
652 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700653 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 if (ar.result == null) {
656 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 if (ar.exception != null) {
659 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
660 }
661
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700662 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700663 if (ar.exception instanceof CommandException) {
664 CommandException.Error error =
665 ((CommandException) (ar.exception)).getCommandError();
666 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700667 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700668 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700669 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 }
671 }
672 openChannelResp = new IccOpenLogicalChannelResponse(
673 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700675 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
679 case CMD_CLOSE_CHANNEL:
680 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800681 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 if (uiccCard == null) {
683 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900684 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 } else {
687 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
688 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
689 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 break;
691
692 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800693 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
694 break;
695
696 case CMD_NV_READ_ITEM:
697 request = (MainThreadRequest) msg.obj;
698 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800699 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
700 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
703 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800706 if (ar.exception == null && ar.result != null) {
707 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800709 request.result = "";
710 if (ar.result == null) {
711 loge("nvReadItem: Empty response");
712 } else if (ar.exception instanceof CommandException) {
713 loge("nvReadItem: CommandException: " +
714 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800716 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 }
718 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700719 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 break;
721
Jake Hambye994d462014-02-03 13:10:13 -0800722 case CMD_NV_WRITE_ITEM:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
725 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800726 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700727 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800728 break;
729
730 case EVENT_NV_WRITE_ITEM_DONE:
731 handleNullReturnEvent(msg, "nvWriteItem");
732 break;
733
734 case CMD_NV_WRITE_CDMA_PRL:
735 request = (MainThreadRequest) msg.obj;
736 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800737 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800738 break;
739
740 case EVENT_NV_WRITE_CDMA_PRL_DONE:
741 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
742 break;
743
chen xu6dac5ab2018-10-26 17:39:23 -0700744 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800745 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700746 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800747 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800748 break;
749
chen xu6dac5ab2018-10-26 17:39:23 -0700750 case EVENT_RESET_MODEM_CONFIG_DONE:
751 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800752 break;
753
Jake Hamby7c27be32014-03-03 13:25:59 -0800754 case CMD_GET_PREFERRED_NETWORK_TYPE:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700757 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800758 break;
759
760 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
761 ar = (AsyncResult) msg.obj;
762 request = (MainThreadRequest) ar.userObj;
763 if (ar.exception == null && ar.result != null) {
764 request.result = ar.result; // Integer
765 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530766 // request.result must be set to something non-null
767 // for the calling thread to unblock
768 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800769 if (ar.result == null) {
770 loge("getPreferredNetworkType: Empty response");
771 } else if (ar.exception instanceof CommandException) {
772 loge("getPreferredNetworkType: CommandException: " +
773 ar.exception);
774 } else {
775 loge("getPreferredNetworkType: Unknown exception");
776 }
777 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700778 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800779 break;
780
781 case CMD_SET_PREFERRED_NETWORK_TYPE:
782 request = (MainThreadRequest) msg.obj;
783 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
784 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700785 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800786 break;
787
788 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
789 handleNullReturnEvent(msg, "setPreferredNetworkType");
790 break;
791
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000792 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
793 request = (MainThreadRequest)msg.obj;
794 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800795 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000796 break;
797
798 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
799 ar = (AsyncResult)msg.obj;
800 request = (MainThreadRequest)ar.userObj;
801 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700802 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000803 break;
804
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800805 case CMD_SET_VOICEMAIL_NUMBER:
806 request = (MainThreadRequest) msg.obj;
807 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
808 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800809 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
810 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800811 break;
812
813 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
814 handleNullReturnEvent(msg, "setVoicemailNumber");
815 break;
816
Stuart Scott54788802015-03-30 13:18:01 -0700817 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
818 request = (MainThreadRequest) msg.obj;
819 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
820 request);
821 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
822 break;
823
824 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
825 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
826 break;
827
Shishir Agrawal302c8692015-06-19 13:49:39 -0700828 case CMD_PERFORM_NETWORK_SCAN:
829 request = (MainThreadRequest) msg.obj;
830 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
831 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
832 break;
833
Hall Liu27d24262020-09-18 19:04:59 -0700834 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800835 request = (MainThreadRequest) msg.obj;
836 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700837 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
838 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
839 request.argument;
840 int callForwardingReason = args.first;
841 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800842 break;
Hall Liu27d24262020-09-18 19:04:59 -0700843 }
844 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800845 ar = (AsyncResult) msg.obj;
846 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700847 TelephonyManager.CallForwardingInfoCallback callback =
848 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
849 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800850 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700851 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800852 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
853 for (CallForwardInfo callForwardInfo : callForwardInfos) {
854 // Service Class is a bit mask per 3gpp 27.007. Search for
855 // any service for voice call.
856 if ((callForwardInfo.serviceClass
857 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700858 callForwardingInfo = new CallForwardingInfo(true,
859 callForwardInfo.reason,
860 callForwardInfo.number,
861 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800862 break;
863 }
864 }
865 // Didn't find a call forward info for voice call.
866 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700867 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
868 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800869 }
Hall Liu27d24262020-09-18 19:04:59 -0700870 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800871 } else {
872 if (ar.result == null) {
873 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
874 }
875 if (ar.exception != null) {
876 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
877 }
Hall Liu940c4ca2020-09-29 17:10:18 -0700878 int errorCode = TelephonyManager
879 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800880 if (ar.exception instanceof CommandException) {
881 CommandException.Error error =
882 ((CommandException) (ar.exception)).getCommandError();
883 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700884 errorCode = TelephonyManager
885 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -0800886 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700887 errorCode = TelephonyManager
888 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -0800889 }
890 }
Hall Liu27d24262020-09-18 19:04:59 -0700891 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -0800892 }
Shuo Qian4a594052020-01-23 11:59:30 -0800893 break;
Hall Liu27d24262020-09-18 19:04:59 -0700894 }
Shuo Qian4a594052020-01-23 11:59:30 -0800895
Hall Liu27d24262020-09-18 19:04:59 -0700896 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800897 request = (MainThreadRequest) msg.obj;
898 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700899 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -0800900 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -0700901 ((Pair<CallForwardingInfo, Consumer<Integer>>)
902 request.argument).first;
903 request.phone.setCallForwardingOption(
904 callForwardingInfoToSet.isEnabled()
905 ? CommandsInterface.CF_ACTION_ENABLE
906 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -0800907 callForwardingInfoToSet.getReason(),
908 callForwardingInfoToSet.getNumber(),
909 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
910 break;
Hall Liu27d24262020-09-18 19:04:59 -0700911 }
Shuo Qian4a594052020-01-23 11:59:30 -0800912
Hall Liu27d24262020-09-18 19:04:59 -0700913 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700916 Consumer<Integer> callback =
917 ((Pair<CallForwardingInfo, Consumer<Integer>>)
918 request.argument).second;
919 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -0800920 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -0700921 int errorCode = TelephonyManager.CallForwardingInfoCallback
922 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -0700923 if (ar.exception instanceof CommandException) {
924 CommandException.Error error =
925 ((CommandException) (ar.exception)).getCommandError();
926 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700927 errorCode = TelephonyManager.CallForwardingInfoCallback
928 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -0700929 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700930 errorCode = TelephonyManager.CallForwardingInfoCallback
931 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -0700932 }
933 }
934 callback.accept(errorCode);
935 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -0700936 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -0800937 }
Shuo Qian4a594052020-01-23 11:59:30 -0800938 break;
Hall Liu27d24262020-09-18 19:04:59 -0700939 }
Shuo Qian4a594052020-01-23 11:59:30 -0800940
Hall Liu27d24262020-09-18 19:04:59 -0700941 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800942 request = (MainThreadRequest) msg.obj;
943 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
944 getPhoneFromRequest(request).getCallWaiting(onCompleted);
945 break;
Hall Liu27d24262020-09-18 19:04:59 -0700946 }
Shuo Qian4a594052020-01-23 11:59:30 -0800947
Hall Liu27d24262020-09-18 19:04:59 -0700948 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700951 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -0800952 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
953 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800954 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800955 // Service Class is a bit mask per 3gpp 27.007.
956 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800957 if (callForwardResults.length > 1
958 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -0700959 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800960 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -0700961 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
962 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -0800963 } else {
Hall Liu27d24262020-09-18 19:04:59 -0700964 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -0800965 }
966 } else {
967 if (ar.result == null) {
968 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
969 }
970 if (ar.exception != null) {
971 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
972 }
973 if (ar.exception instanceof CommandException) {
974 CommandException.Error error =
975 ((CommandException) (ar.exception)).getCommandError();
976 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
977 callForwardingStatus =
978 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
979 }
980 }
981 }
Hall Liu27d24262020-09-18 19:04:59 -0700982 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -0800983 break;
Hall Liu27d24262020-09-18 19:04:59 -0700984 }
Shuo Qian4a594052020-01-23 11:59:30 -0800985
Hall Liu27d24262020-09-18 19:04:59 -0700986 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800987 request = (MainThreadRequest) msg.obj;
988 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700989 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
990 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800991 break;
Hall Liu27d24262020-09-18 19:04:59 -0700992 }
Shuo Qian4a594052020-01-23 11:59:30 -0800993
Hall Liu27d24262020-09-18 19:04:59 -0700994 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700997 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
998 Consumer<Integer> callback =
999 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1000 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001001 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001002 if (ar.exception instanceof CommandException) {
1003 CommandException.Error error =
1004 ((CommandException) (ar.exception)).getCommandError();
1005 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1006 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1007 } else {
1008 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1009 }
1010 } else {
1011 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1012 }
1013 } else {
1014 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1015 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001016 }
Shuo Qian4a594052020-01-23 11:59:30 -08001017 break;
Hall Liu27d24262020-09-18 19:04:59 -07001018 }
Shuo Qian4a594052020-01-23 11:59:30 -08001019
Shishir Agrawal302c8692015-06-19 13:49:39 -07001020 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
1023 CellNetworkScanResult cellScanResult;
1024 if (ar.exception == null && ar.result != null) {
1025 cellScanResult = new CellNetworkScanResult(
1026 CellNetworkScanResult.STATUS_SUCCESS,
1027 (List<OperatorInfo>) ar.result);
1028 } else {
1029 if (ar.result == null) {
1030 loge("getCellNetworkScanResults: Empty response");
1031 }
1032 if (ar.exception != null) {
1033 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1034 }
1035 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1036 if (ar.exception instanceof CommandException) {
1037 CommandException.Error error =
1038 ((CommandException) (ar.exception)).getCommandError();
1039 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1040 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1041 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1042 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1043 }
1044 }
1045 cellScanResult = new CellNetworkScanResult(errorCode, null);
1046 }
1047 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001048 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001049 break;
1050
1051 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1052 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001053 ManualNetworkSelectionArgument selArg =
1054 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001055 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1056 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001057 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1058 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001059 break;
1060
1061 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001062 ar = (AsyncResult) msg.obj;
1063 request = (MainThreadRequest) ar.userObj;
1064 if (ar.exception == null) {
1065 request.result = true;
1066 } else {
1067 request.result = false;
1068 loge("setNetworkSelectionModeManual " + ar.exception);
1069 }
1070 notifyRequester(request);
1071 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001072 break;
1073
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001074 case CMD_GET_MODEM_ACTIVITY_INFO:
1075 request = (MainThreadRequest) msg.obj;
1076 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001077 if (defaultPhone != null) {
1078 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001079 } else {
1080 ResultReceiver result = (ResultReceiver) request.argument;
1081 Bundle bundle = new Bundle();
1082 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001083 new ModemActivityInfo(0, 0, 0,
1084 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001085 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001086 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001087 break;
1088
Hall Liud0f208c2020-10-14 16:54:44 -07001089 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001090 ar = (AsyncResult) msg.obj;
1091 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001092 ResultReceiver result = (ResultReceiver) request.argument;
1093
Hall Liud0f208c2020-10-14 16:54:44 -07001094 ModemActivityInfo ret = null;
1095 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001096 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001097 // Update the last modem activity info and the result of the request.
1098 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1099 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001100 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001101 int[] txTimeMs = info.getTransmitTimeMillis();
1102 int[] lastModemTxTimeMs = mLastModemActivityInfo
1103 .getTransmitTimeMillis();
1104 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1105 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1106 }
Hall Liu49656c02020-10-09 19:00:11 -07001107 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001108 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1109 + mLastModemActivityInfo.getSleepTimeMillis());
1110 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1111 + mLastModemActivityInfo.getIdleTimeMillis());
1112 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1113 mLastModemActivityInfo.setReceiveTimeMillis(
1114 info.getReceiveTimeMillis()
1115 + mLastModemActivityInfo.getReceiveTimeMillis());
1116 }
Hall Liu49656c02020-10-09 19:00:11 -07001117 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001118 mLastModemActivityInfo.getSleepTimeMillis(),
1119 mLastModemActivityInfo.getIdleTimeMillis(),
1120 mLastModemActivityInfo.getTransmitTimeMillis(),
1121 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001122 } else {
1123 if (ar.result == null) {
1124 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001125 error = TelephonyManager.ModemActivityInfoException
1126 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001127 } else if (ar.exception instanceof CommandException) {
1128 loge("queryModemActivityInfo: CommandException: " +
1129 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001130 error = TelephonyManager.ModemActivityInfoException
1131 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001132 } else {
1133 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001134 error = TelephonyManager.ModemActivityInfoException
1135 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001136 }
1137 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001138 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001139 if (ret != null) {
1140 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1141 } else {
1142 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1143 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001144 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001145 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001146 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001147 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001148
Meng Wang1a7c35a2016-05-05 20:56:15 -07001149 case CMD_SET_ALLOWED_CARRIERS:
1150 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001151 CarrierRestrictionRules argument =
1152 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001153 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001154 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001155 break;
1156
1157 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1158 ar = (AsyncResult) msg.obj;
1159 request = (MainThreadRequest) ar.userObj;
1160 if (ar.exception == null && ar.result != null) {
1161 request.result = ar.result;
1162 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001163 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1164 if (ar.exception instanceof CommandException) {
1165 loge("setAllowedCarriers: CommandException: " + ar.exception);
1166 CommandException.Error error =
1167 ((CommandException) (ar.exception)).getCommandError();
1168 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1169 request.result =
1170 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1171 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001172 } else {
1173 loge("setAllowedCarriers: Unknown exception");
1174 }
1175 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001176 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001177 break;
1178
1179 case CMD_GET_ALLOWED_CARRIERS:
1180 request = (MainThreadRequest) msg.obj;
1181 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001182 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001183 break;
1184
1185 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1186 ar = (AsyncResult) msg.obj;
1187 request = (MainThreadRequest) ar.userObj;
1188 if (ar.exception == null && ar.result != null) {
1189 request.result = ar.result;
1190 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001191 request.result = new IllegalStateException(
1192 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001193 if (ar.result == null) {
1194 loge("getAllowedCarriers: Empty response");
1195 } else if (ar.exception instanceof CommandException) {
1196 loge("getAllowedCarriers: CommandException: " +
1197 ar.exception);
1198 } else {
1199 loge("getAllowedCarriers: Unknown exception");
1200 }
1201 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001202 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001203 break;
1204
Nathan Haroldb3014052017-01-25 15:57:32 -08001205 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1206 ar = (AsyncResult) msg.obj;
1207 request = (MainThreadRequest) ar.userObj;
1208 if (ar.exception == null && ar.result != null) {
1209 request.result = ar.result;
1210 } else {
1211 request.result = new IllegalArgumentException(
1212 "Failed to retrieve Forbidden Plmns");
1213 if (ar.result == null) {
1214 loge("getForbiddenPlmns: Empty response");
1215 } else {
1216 loge("getForbiddenPlmns: Unknown exception");
1217 }
1218 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001219 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001220 break;
1221
1222 case CMD_GET_FORBIDDEN_PLMNS:
1223 request = (MainThreadRequest) msg.obj;
1224 uiccCard = getUiccCardFromRequest(request);
1225 if (uiccCard == null) {
1226 loge("getForbiddenPlmns() UiccCard is null");
1227 request.result = new IllegalArgumentException(
1228 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001229 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001230 break;
1231 }
1232 Integer appType = (Integer) request.argument;
1233 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1234 if (uiccApp == null) {
1235 loge("getForbiddenPlmns() no app with specified type -- "
1236 + appType);
1237 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001238 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001239 break;
1240 } else {
1241 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1242 + " specified type -- " + appType);
1243 }
1244 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1245 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1246 onCompleted);
1247 break;
1248
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001249 case CMD_SWITCH_SLOTS:
1250 request = (MainThreadRequest) msg.obj;
1251 int[] physicalSlots = (int[]) request.argument;
1252 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1253 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1254 break;
1255
1256 case EVENT_SWITCH_SLOTS_DONE:
1257 ar = (AsyncResult) msg.obj;
1258 request = (MainThreadRequest) ar.userObj;
1259 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001260 notifyRequester(request);
1261 break;
1262 case CMD_GET_NETWORK_SELECTION_MODE:
1263 request = (MainThreadRequest) msg.obj;
1264 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1265 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1266 break;
1267
1268 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1269 ar = (AsyncResult) msg.obj;
1270 request = (MainThreadRequest) ar.userObj;
1271 if (ar.exception != null) {
1272 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1273 } else {
1274 int mode = ((int[]) ar.result)[0];
1275 if (mode == 0) {
1276 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1277 } else {
1278 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1279 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001280 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001281 notifyRequester(request);
1282 break;
1283 case CMD_GET_CDMA_ROAMING_MODE:
1284 request = (MainThreadRequest) msg.obj;
1285 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1286 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1287 break;
1288 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1289 ar = (AsyncResult) msg.obj;
1290 request = (MainThreadRequest) ar.userObj;
1291 if (ar.exception != null) {
1292 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1293 } else {
1294 request.result = ((int[]) ar.result)[0];
1295 }
1296 notifyRequester(request);
1297 break;
1298 case CMD_SET_CDMA_ROAMING_MODE:
1299 request = (MainThreadRequest) msg.obj;
1300 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1301 int mode = (int) request.argument;
1302 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1303 break;
1304 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1305 ar = (AsyncResult) msg.obj;
1306 request = (MainThreadRequest) ar.userObj;
1307 request.result = ar.exception == null;
1308 notifyRequester(request);
1309 break;
1310 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1311 request = (MainThreadRequest) msg.obj;
1312 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1313 int subscriptionMode = (int) request.argument;
1314 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1315 break;
1316 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1317 ar = (AsyncResult) msg.obj;
1318 request = (MainThreadRequest) ar.userObj;
1319 request.result = ar.exception == null;
1320 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001321 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001322 case CMD_GET_ALL_CELL_INFO:
1323 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001324 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001325 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001326 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001327 case EVENT_GET_ALL_CELL_INFO_DONE:
1328 ar = (AsyncResult) msg.obj;
1329 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001330 // If a timeout occurs, the response will be null
1331 request.result = (ar.exception == null && ar.result != null)
1332 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001333 synchronized (request) {
1334 request.notifyAll();
1335 }
1336 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001337 case CMD_REQUEST_CELL_INFO_UPDATE:
1338 request = (MainThreadRequest) msg.obj;
1339 request.phone.requestCellInfoUpdate(request.workSource,
1340 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1341 break;
1342 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1343 ar = (AsyncResult) msg.obj;
1344 request = (MainThreadRequest) ar.userObj;
1345 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1346 try {
1347 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001348 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001349 cb.onError(
1350 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1351 ar.exception.getClass().getName(),
1352 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001353 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001354 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001355 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001356 } else {
1357 // use the result as returned
1358 cb.onCellInfo((List<CellInfo>) ar.result);
1359 }
1360 } catch (RemoteException re) {
1361 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1362 }
1363 break;
1364 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001365 request = (MainThreadRequest) msg.obj;
1366 WorkSource ws = (WorkSource) request.argument;
1367 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001368 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001369 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001370 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001371 ar = (AsyncResult) msg.obj;
1372 request = (MainThreadRequest) ar.userObj;
1373 if (ar.exception == null) {
1374 request.result = ar.result;
1375 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001376 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001377 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001378 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001379 }
1380
1381 synchronized (request) {
1382 request.notifyAll();
1383 }
1384 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001385 case CMD_MODEM_REBOOT:
1386 request = (MainThreadRequest) msg.obj;
1387 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001388 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001389 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001390 case EVENT_CMD_MODEM_REBOOT_DONE:
1391 handleNullReturnEvent(msg, "rebootModem");
1392 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001393 case CMD_REQUEST_ENABLE_MODEM:
1394 request = (MainThreadRequest) msg.obj;
1395 boolean enable = (boolean) request.argument;
1396 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001397 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001398 PhoneConfigurationManager.getInstance()
1399 .enablePhone(request.phone, enable, onCompleted);
1400 break;
1401 case EVENT_ENABLE_MODEM_DONE:
1402 ar = (AsyncResult) msg.obj;
1403 request = (MainThreadRequest) ar.userObj;
1404 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001405 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001406 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001407 if ((boolean) request.result) {
1408 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1409 updateModemStateMetrics();
1410 } else {
1411 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1412 + ar.exception);
1413 }
1414 notifyRequester(request);
1415 break;
1416 case CMD_GET_MODEM_STATUS:
1417 request = (MainThreadRequest) msg.obj;
1418 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1419 PhoneConfigurationManager.getInstance()
1420 .getPhoneStatusFromModem(request.phone, onCompleted);
1421 break;
1422 case EVENT_GET_MODEM_STATUS_DONE:
1423 ar = (AsyncResult) msg.obj;
1424 request = (MainThreadRequest) ar.userObj;
1425 int id = request.phone.getPhoneId();
1426 if (ar.exception == null && ar.result != null) {
1427 request.result = ar.result;
1428 //update the cache as modem status has changed
1429 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1430 (boolean) request.result);
1431 } else {
1432 // Return true if modem status cannot be retrieved. For most cases,
1433 // modem status is on. And for older version modems, GET_MODEM_STATUS
1434 // and disable modem are not supported. Modem is always on.
1435 // TODO: this should be fixed in R to support a third
1436 // status UNKNOWN b/131631629
1437 request.result = true;
1438 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1439 + ar.exception);
1440 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001441 notifyRequester(request);
1442 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001443 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1444 request = (MainThreadRequest) msg.obj;
1445 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1446 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1447 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1448 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1449 break;
1450 }
1451 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1452 ar = (AsyncResult) msg.obj;
1453 request = (MainThreadRequest) ar.userObj;
1454 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1455 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1456 args.second.accept(ar.exception == null);
1457 notifyRequester(request);
1458 break;
1459 }
yincheng zhao2737e882019-09-06 17:06:54 -07001460 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1461 ar = (AsyncResult) msg.obj;
1462 request = (MainThreadRequest) ar.userObj;
1463 if (ar.exception == null && ar.result != null) {
1464 request.result = ar.result;
1465 } else {
1466 request.result = -1;
1467 loge("Failed to set Forbidden Plmns");
1468 if (ar.result == null) {
1469 loge("setForbidenPlmns: Empty response");
1470 } else if (ar.exception != null) {
1471 loge("setForbiddenPlmns: Exception: " + ar.exception);
1472 request.result = -1;
1473 } else {
1474 loge("setForbiddenPlmns: Unknown exception");
1475 }
1476 }
1477 notifyRequester(request);
1478 break;
1479 case CMD_SET_FORBIDDEN_PLMNS:
1480 request = (MainThreadRequest) msg.obj;
1481 uiccCard = getUiccCardFromRequest(request);
1482 if (uiccCard == null) {
1483 loge("setForbiddenPlmns: UiccCard is null");
1484 request.result = -1;
1485 notifyRequester(request);
1486 break;
1487 }
1488 Pair<Integer, List<String>> setFplmnsArgs =
1489 (Pair<Integer, List<String>>) request.argument;
1490 appType = setFplmnsArgs.first;
1491 List<String> fplmns = setFplmnsArgs.second;
1492 uiccApp = uiccCard.getApplicationByType(appType);
1493 if (uiccApp == null) {
1494 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1495 request.result = -1;
1496 loge("Failed to get UICC App");
1497 notifyRequester(request);
1498 } else {
1499 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1500 ((SIMRecords) uiccApp.getIccRecords())
1501 .setForbiddenPlmns(onCompleted, fplmns);
1502 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001503 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001504 case CMD_ERASE_MODEM_CONFIG:
1505 request = (MainThreadRequest) msg.obj;
1506 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1507 defaultPhone.eraseModemConfig(onCompleted);
1508 break;
1509 case EVENT_ERASE_MODEM_CONFIG_DONE:
1510 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001511 break;
zoey chene02881a2019-12-30 16:11:23 +08001512
1513 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1514 request = (MainThreadRequest) msg.obj;
1515 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1516 Pair<String, String> changed = (Pair<String, String>) request.argument;
1517 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1518 changed.first, changed.second, onCompleted);
1519 break;
1520 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1521 ar = (AsyncResult) msg.obj;
1522 request = (MainThreadRequest) ar.userObj;
1523 if (ar.exception == null) {
1524 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1525 } else {
1526 request.result = msg.arg1;
1527 }
1528 notifyRequester(request);
1529 break;
1530
1531 case CMD_SET_ICC_LOCK_ENABLED:
1532 request = (MainThreadRequest) msg.obj;
1533 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1534 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1535 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1536 enabled.first, enabled.second, onCompleted);
1537 break;
1538 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1539 ar = (AsyncResult) msg.obj;
1540 request = (MainThreadRequest) ar.userObj;
1541 if (ar.exception == null) {
1542 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1543 } else {
1544 request.result = msg.arg1;
1545 }
1546 notifyRequester(request);
1547 break;
1548
Peter Wangdafb9ac2020-01-15 14:13:38 -08001549 case MSG_NOTIFY_USER_ACTIVITY:
1550 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001551 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001552 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1553 getDefaultPhone().getContext().sendBroadcastAsUser(
1554 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1555 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 default:
1557 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1558 break;
1559 }
1560 }
Jake Hambye994d462014-02-03 13:10:13 -08001561
Pengquan Menga1bb6272018-09-06 09:59:22 -07001562 private void notifyRequester(MainThreadRequest request) {
1563 synchronized (request) {
1564 request.notifyAll();
1565 }
1566 }
1567
Jake Hambye994d462014-02-03 13:10:13 -08001568 private void handleNullReturnEvent(Message msg, String command) {
1569 AsyncResult ar = (AsyncResult) msg.obj;
1570 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1571 if (ar.exception == null) {
1572 request.result = true;
1573 } else {
1574 request.result = false;
1575 if (ar.exception instanceof CommandException) {
1576 loge(command + ": CommandException: " + ar.exception);
1577 } else {
1578 loge(command + ": Unknown exception");
1579 }
1580 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001581 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
1585 /**
1586 * Posts the specified command to be executed on the main thread,
1587 * waits for the request to complete, and returns the result.
1588 * @see #sendRequestAsync
1589 */
1590 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001591 return sendRequest(
1592 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001593 }
1594
1595 /**
1596 * Posts the specified command to be executed on the main thread,
1597 * waits for the request to complete, and returns the result.
1598 * @see #sendRequestAsync
1599 */
1600 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1601 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001602 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001603 }
1604
1605 /**
1606 * Posts the specified command to be executed on the main thread,
1607 * waits for the request to complete, and returns the result.
1608 * @see #sendRequestAsync
1609 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001610 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001611 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001612 }
1613
1614 /**
1615 * Posts the specified command to be executed on the main thread,
1616 * waits for the request to complete, and returns the result.
1617 * @see #sendRequestAsync
1618 */
Nathan Harold92bed182018-10-12 18:16:49 -07001619 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1620 return sendRequest(command, argument, subId, null, workSource);
1621 }
1622
1623 /**
1624 * Posts the specified command to be executed on the main thread,
1625 * waits for the request to complete, and returns the result.
1626 * @see #sendRequestAsync
1627 */
1628 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1629 return sendRequest(
1630 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1631 }
1632
1633 /**
1634 * Posts the specified command to be executed on the main thread,
1635 * waits for the request to complete, and returns the result.
1636 * @see #sendRequestAsync
1637 */
1638 private Object sendRequest(
1639 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001640 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1641 throw new RuntimeException("This method will deadlock if called from the main thread.");
1642 }
1643
Nathan Harold92bed182018-10-12 18:16:49 -07001644 MainThreadRequest request = null;
1645 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1646 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1647 } else if (phone != null) {
1648 request = new MainThreadRequest(argument, phone, workSource);
1649 } else {
1650 request = new MainThreadRequest(argument, subId, workSource);
1651 }
1652
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653 Message msg = mMainThreadHandler.obtainMessage(command, request);
1654 msg.sendToTarget();
1655
1656 // Wait for the request to complete
1657 synchronized (request) {
1658 while (request.result == null) {
1659 try {
1660 request.wait();
1661 } catch (InterruptedException e) {
1662 // Do nothing, go back and wait until the request is complete
1663 }
1664 }
1665 }
1666 return request.result;
1667 }
1668
1669 /**
1670 * Asynchronous ("fire and forget") version of sendRequest():
1671 * Posts the specified command to be executed on the main thread, and
1672 * returns immediately.
1673 * @see #sendRequest
1674 */
1675 private void sendRequestAsync(int command) {
1676 mMainThreadHandler.sendEmptyMessage(command);
1677 }
1678
1679 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001680 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001681 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001682 */
1683 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001684 sendRequestAsync(command, argument, null, null);
1685 }
1686
1687 /**
1688 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1689 * @see {@link #sendRequest(int,Object)}
1690 */
1691 private void sendRequestAsync(
1692 int command, Object argument, Phone phone, WorkSource workSource) {
1693 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001694 Message msg = mMainThreadHandler.obtainMessage(command, request);
1695 msg.sendToTarget();
1696 }
1697
1698 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 * Initialize the singleton PhoneInterfaceManager instance.
1700 * This is only done once, at startup, from PhoneApp.onCreate().
1701 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001702 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 synchronized (PhoneInterfaceManager.class) {
1704 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001705 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 } else {
1707 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1708 }
1709 return sInstance;
1710 }
1711 }
1712
1713 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001714 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001716 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001717 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001718 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1720 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001721 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001722 mTelephonySharedPreferences =
1723 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001724 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001725 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001726 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001727
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 publish();
1729 }
1730
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001731 private Phone getDefaultPhone() {
1732 Phone thePhone = getPhone(getDefaultSubscription());
1733 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1734 }
1735
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 private void publish() {
1737 if (DBG) log("publish: " + this);
1738
Peter Wangc035ce42020-01-08 21:00:22 -08001739 TelephonyFrameworkInitializer
1740 .getTelephonyServiceManager()
1741 .getTelephonyServiceRegisterer()
1742 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 }
1744
Stuart Scott584921c2015-01-15 17:10:34 -08001745 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001746 if (request.phone != null) {
1747 return request.phone;
1748 } else {
1749 return getPhoneFromSubId(request.subId);
1750 }
1751 }
1752
1753 private Phone getPhoneFromSubId(int subId) {
1754 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1755 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001756 }
1757
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001758 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1759 Phone phone = getPhoneFromRequest(request);
1760 return phone == null ? null :
1761 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1762 }
1763
Wink Saville36469e72014-06-11 15:17:00 -07001764 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001765 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001766 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768
Naina Nallurid63128d2019-09-17 14:10:30 -07001769 private void sendEraseModemConfig(Phone phone) {
1770 if (phone != null) {
1771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1772 mApp, phone.getSubId(), "eraseModemConfig");
1773 final long identity = Binder.clearCallingIdentity();
1774 try {
1775 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1776 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1777 } finally {
1778 Binder.restoreCallingIdentity(identity);
1779 }
1780 }
1781 }
1782
Peter Wang44b186e2020-01-13 23:33:09 -08001783 private boolean isImsAvailableOnDevice() {
1784 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1785 if (pm == null) {
1786 // For some reason package manger is not available.. This will fail internally anyway,
1787 // so do not throw error and allow.
1788 return true;
1789 }
1790 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1791 }
1792
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001794 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001795 }
1796
Wink Savilleb564aae2014-10-23 10:18:09 -07001797 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001798 if (DBG) log("dial: " + number);
1799 // No permission check needed here: This is just a wrapper around the
1800 // ACTION_DIAL intent, which is available to any app since it puts up
1801 // the UI before it does anything.
1802
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001803 final long identity = Binder.clearCallingIdentity();
1804 try {
1805 String url = createTelUrl(number);
1806 if (url == null) {
1807 return;
1808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001810 // PENDING: should we just silently fail if phone is offhook or ringing?
1811 PhoneConstants.State state = mCM.getState(subId);
1812 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1813 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1814 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1815 mApp.startActivity(intent);
1816 }
1817 } finally {
1818 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 }
1820 }
1821
1822 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001823 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001824 }
1825
Wink Savilleb564aae2014-10-23 10:18:09 -07001826 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 if (DBG) log("call: " + number);
1828
1829 // This is just a wrapper around the ACTION_CALL intent, but we still
1830 // need to do a permission check since we're calling startActivity()
1831 // from the context of the phone app.
1832 enforceCallPermission();
1833
Jordan Liu1617b712019-07-10 15:06:26 -07001834 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001835 != AppOpsManager.MODE_ALLOWED) {
1836 return;
1837 }
1838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001839 final long identity = Binder.clearCallingIdentity();
1840 try {
1841 String url = createTelUrl(number);
1842 if (url == null) {
1843 return;
1844 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001846 boolean isValid = false;
1847 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1848 if (slist != null) {
1849 for (SubscriptionInfo subInfoRecord : slist) {
1850 if (subInfoRecord.getSubscriptionId() == subId) {
1851 isValid = true;
1852 break;
1853 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001854 }
Wink Saville08874612014-08-31 19:19:58 -07001855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001856 if (!isValid) {
1857 return;
1858 }
Wink Saville08874612014-08-31 19:19:58 -07001859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001860 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1861 intent.putExtra(SUBSCRIPTION_KEY, subId);
1862 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1863 mApp.startActivity(intent);
1864 } finally {
1865 Binder.restoreCallingIdentity(identity);
1866 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 }
1868
Wink Savilleb564aae2014-10-23 10:18:09 -07001869 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001870 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001871 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1872 }
1873
Wink Savilleb564aae2014-10-23 10:18:09 -07001874 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001875 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001876 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1877 }
1878
Wink Savilleb564aae2014-10-23 10:18:09 -07001879 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001881
1882 final long identity = Binder.clearCallingIdentity();
1883 try {
1884 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1885 checkSimPin.start();
1886 return checkSimPin.unlockSim(null, pin);
1887 } finally {
1888 Binder.restoreCallingIdentity(identity);
1889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 }
1891
Wink Savilleb564aae2014-10-23 10:18:09 -07001892 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001894
1895 final long identity = Binder.clearCallingIdentity();
1896 try {
1897 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1898 checkSimPuk.start();
1899 return checkSimPuk.unlockSim(puk, pin);
1900 } finally {
1901 Binder.restoreCallingIdentity(identity);
1902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 }
1904
1905 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001906 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 * a synchronous one.
1908 */
1909 private static class UnlockSim extends Thread {
1910
1911 private final IccCard mSimCard;
1912
1913 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001914 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1915 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916
1917 // For replies from SimCard interface
1918 private Handler mHandler;
1919
1920 // For async handler to identify request type
1921 private static final int SUPPLY_PIN_COMPLETE = 100;
1922
1923 public UnlockSim(IccCard simCard) {
1924 mSimCard = simCard;
1925 }
1926
1927 @Override
1928 public void run() {
1929 Looper.prepare();
1930 synchronized (UnlockSim.this) {
1931 mHandler = new Handler() {
1932 @Override
1933 public void handleMessage(Message msg) {
1934 AsyncResult ar = (AsyncResult) msg.obj;
1935 switch (msg.what) {
1936 case SUPPLY_PIN_COMPLETE:
1937 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1938 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001939 mRetryCount = msg.arg1;
1940 if (ar.exception != null) {
1941 if (ar.exception instanceof CommandException &&
1942 ((CommandException)(ar.exception)).getCommandError()
1943 == CommandException.Error.PASSWORD_INCORRECT) {
1944 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001945 } //When UiccCardApp dispose,handle message and return exception
1946 else if (ar.exception instanceof CommandException &&
1947 ((CommandException) (ar.exception)).getCommandError()
1948 == CommandException.Error.ABORTED) {
1949 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001950 } else {
1951 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1952 }
1953 } else {
1954 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1955 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 mDone = true;
1957 UnlockSim.this.notifyAll();
1958 }
1959 break;
1960 }
1961 }
1962 };
1963 UnlockSim.this.notifyAll();
1964 }
1965 Looper.loop();
1966 }
1967
1968 /*
1969 * Use PIN or PUK to unlock SIM card
1970 *
1971 * If PUK is null, unlock SIM card with PIN
1972 *
1973 * If PUK is not null, unlock SIM card with PUK and set PIN code
1974 */
Wink Saville9de0f752013-10-22 19:04:03 -07001975 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976
1977 while (mHandler == null) {
1978 try {
1979 wait();
1980 } catch (InterruptedException e) {
1981 Thread.currentThread().interrupt();
1982 }
1983 }
1984 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1985
1986 if (puk == null) {
1987 mSimCard.supplyPin(pin, callback);
1988 } else {
1989 mSimCard.supplyPuk(puk, pin, callback);
1990 }
1991
1992 while (!mDone) {
1993 try {
1994 Log.d(LOG_TAG, "wait for done");
1995 wait();
1996 } catch (InterruptedException e) {
1997 // Restore the interrupted status
1998 Thread.currentThread().interrupt();
1999 }
2000 }
2001 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002002 int[] resultArray = new int[2];
2003 resultArray[0] = mResult;
2004 resultArray[1] = mRetryCount;
2005 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002006 }
2007 }
2008
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002009 /**
2010 * This method has been removed due to privacy and stability concerns.
2011 */
2012 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002014 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2015 return;
Wink Saville36469e72014-06-11 15:17:00 -07002016 }
2017
Nathan Harold1f889d82020-06-04 17:05:26 -07002018 @Override
2019 public void updateServiceLocationWithPackageName(String callingPackage) {
2020 mApp.getSystemService(AppOpsManager.class)
2021 .checkPackage(Binder.getCallingUid(), callingPackage);
2022
2023 final int targetSdk = getTargetSdk(callingPackage);
2024 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2025 // Callers targeting S have no business invoking this method.
2026 return;
2027 }
2028
2029 LocationAccessPolicy.LocationPermissionResult locationResult =
2030 LocationAccessPolicy.checkLocationPermission(mApp,
2031 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2032 .setCallingPackage(callingPackage)
2033 .setCallingFeatureId(null)
2034 .setCallingPid(Binder.getCallingPid())
2035 .setCallingUid(Binder.getCallingUid())
2036 .setMethod("updateServiceLocation")
2037 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2038 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2039 .build());
2040 // Apps that lack location permission have no business calling this method;
2041 // however, because no permission was declared in the public API, denials must
2042 // all be "soft".
2043 switch (locationResult) {
2044 case DENIED_HARD: /* fall through */
2045 case DENIED_SOFT:
2046 return;
2047 }
2048
2049 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002050 final long identity = Binder.clearCallingIdentity();
2051 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002052 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002053 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002054 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002055 }
2056 } finally {
2057 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002058 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002059 }
2060
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002061 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002062 @Override
2063 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002064 return isRadioOnWithFeature(callingPackage, null);
2065 }
2066
2067
2068 @Override
2069 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2070 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2071 callingFeatureId);
2072 }
2073
2074 @Deprecated
2075 @Override
2076 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2077 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002078 }
2079
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002080 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002081 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2082 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002084 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002085 return false;
2086 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002087
2088 final long identity = Binder.clearCallingIdentity();
2089 try {
2090 return isRadioOnForSubscriber(subId);
2091 } finally {
2092 Binder.restoreCallingIdentity(identity);
2093 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002094 }
2095
2096 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002097 final long identity = Binder.clearCallingIdentity();
2098 try {
2099 final Phone phone = getPhone(subId);
2100 if (phone != null) {
2101 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2102 } else {
2103 return false;
2104 }
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 }
2109
2110 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002111 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
Wink Saville36469e72014-06-11 15:17:00 -07002113
Wink Savilleb564aae2014-10-23 10:18:09 -07002114 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002116
2117 final long identity = Binder.clearCallingIdentity();
2118 try {
2119 final Phone phone = getPhone(subId);
2120 if (phone != null) {
2121 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2122 }
2123 } finally {
2124 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002125 }
Wink Saville36469e72014-06-11 15:17:00 -07002126 }
2127
2128 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002129 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002130 }
2131
Wink Savilleb564aae2014-10-23 10:18:09 -07002132 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002133 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002134
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 final Phone phone = getPhone(subId);
2138 if (phone == null) {
2139 return false;
2140 }
2141 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2142 toggleRadioOnOffForSubscriber(subId);
2143 }
2144 return true;
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002148 }
Wink Saville36469e72014-06-11 15:17:00 -07002149
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002150 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002151 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002152 /*
2153 * If any of the Radios are available, it will need to be
2154 * shutdown. So return true if any Radio is available.
2155 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002156 final long identity = Binder.clearCallingIdentity();
2157 try {
2158 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2159 Phone phone = PhoneFactory.getPhone(i);
2160 if (phone != null && phone.isRadioAvailable()) return true;
2161 }
2162 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2163 return false;
2164 } finally {
2165 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002166 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002167 }
2168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002169 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002170 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171 enforceModifyPermission();
2172
2173 final long identity = Binder.clearCallingIdentity();
2174 try {
2175 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2176 logv("Shutting down Phone " + i);
2177 shutdownRadioUsingPhoneId(i);
2178 }
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002181 }
2182 }
2183
2184 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002185 Phone phone = PhoneFactory.getPhone(phoneId);
2186 if (phone != null && phone.isRadioAvailable()) {
2187 phone.shutdownRadio();
2188 }
2189 }
2190
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002192 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002193
2194 final long identity = Binder.clearCallingIdentity();
2195 try {
2196 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2197 if (defaultPhone != null) {
2198 defaultPhone.setRadioPower(turnOn);
2199 return true;
2200 } else {
2201 loge("There's no default phone.");
2202 return false;
2203 }
2204 } finally {
2205 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002206 }
Wink Saville36469e72014-06-11 15:17:00 -07002207 }
2208
Wink Savilleb564aae2014-10-23 10:18:09 -07002209 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002211
2212 final long identity = Binder.clearCallingIdentity();
2213 try {
2214 final Phone phone = getPhone(subId);
2215 if (phone != null) {
2216 phone.setRadioPower(turnOn);
2217 return true;
2218 } else {
2219 return false;
2220 }
2221 } finally {
2222 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002224 }
2225
Wink Saville36469e72014-06-11 15:17:00 -07002226 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002227 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 public boolean enableDataConnectivity() {
2229 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002230
2231 final long identity = Binder.clearCallingIdentity();
2232 try {
2233 int subId = mSubscriptionController.getDefaultDataSubId();
2234 final Phone phone = getPhone(subId);
2235 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002236 phone.getDataEnabledSettings().setDataEnabled(
2237 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238 return true;
2239 } else {
2240 return false;
2241 }
2242 } finally {
2243 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 }
2246
Wink Saville36469e72014-06-11 15:17:00 -07002247 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002248 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 public boolean disableDataConnectivity() {
2250 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002251
2252 final long identity = Binder.clearCallingIdentity();
2253 try {
2254 int subId = mSubscriptionController.getDefaultDataSubId();
2255 final Phone phone = getPhone(subId);
2256 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002257 phone.getDataEnabledSettings().setDataEnabled(
2258 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002259 return true;
2260 } else {
2261 return false;
2262 }
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267
Sanket Padawe356d7632015-06-22 14:03:32 -07002268 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002269 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002270 final long identity = Binder.clearCallingIdentity();
2271 try {
2272 final Phone phone = getPhone(subId);
2273 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002274 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275 } else {
2276 return false;
2277 }
2278 } finally {
2279 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 }
2282
2283 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002284 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002285 }
2286
pkanwarae03a6b2016-11-06 20:37:09 -08002287 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002288 enforceCallPermission();
2289
2290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2293 return;
2294 }
2295 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2296 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2297 } finally {
2298 Binder.restoreCallingIdentity(identity);
2299 }
pkanwar32d516d2016-10-14 19:37:38 -07002300 };
2301
Wink Savilleb564aae2014-10-23 10:18:09 -07002302 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002304
2305 final long identity = Binder.clearCallingIdentity();
2306 try {
2307 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2308 return false;
2309 }
2310 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2311 } finally {
2312 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 }
2315
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002317 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002318 }
2319
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002320 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002321 final long identity = Binder.clearCallingIdentity();
2322 try {
2323 Phone phone = PhoneFactory.getPhone(slotIndex);
2324 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2325 PhoneConstantConversions.convertCallState(phone.getState());
2326 } finally {
2327 Binder.restoreCallingIdentity(identity);
2328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 }
2330
Sanket Padawe356d7632015-06-22 14:03:32 -07002331 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002332 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002333 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2334 }
2335
2336 @Override
2337 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002338 final long identity = Binder.clearCallingIdentity();
2339 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002340 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341 if (phone != null) {
2342 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2343 } else {
2344 return PhoneConstantConversions.convertDataState(
2345 PhoneConstants.DataState.DISCONNECTED);
2346 }
2347 } finally {
2348 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 }
2351
Sanket Padawe356d7632015-06-22 14:03:32 -07002352 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002353 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002354 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2355 }
2356
2357 @Override
2358 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002359 final long identity = Binder.clearCallingIdentity();
2360 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002361 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002362 if (phone != null) {
2363 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2364 } else {
2365 return TelephonyManager.DATA_ACTIVITY_NONE;
2366 }
2367 } finally {
2368 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002369 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 }
2371
2372 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002373 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002374 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002375 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002376
2377 LocationAccessPolicy.LocationPermissionResult locationResult =
2378 LocationAccessPolicy.checkLocationPermission(mApp,
2379 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2380 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002381 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002382 .setCallingPid(Binder.getCallingPid())
2383 .setCallingUid(Binder.getCallingUid())
2384 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002385 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002386 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2387 .build());
2388 switch (locationResult) {
2389 case DENIED_HARD:
2390 throw new SecurityException("Not allowed to access cell location");
2391 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002392 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2393 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 }
2395
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002396 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397 final long identity = Binder.clearCallingIdentity();
2398 try {
2399 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002400 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002401 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002402 } finally {
2403 Binder.restoreCallingIdentity(identity);
2404 }
Svetoslav64fad262015-04-14 14:35:21 -07002405 }
2406
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002408 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002409 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2410 // registered cell info, so return a NULL country instead.
2411 final long identity = Binder.clearCallingIdentity();
2412 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002413 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2414 // Get default phone in this case.
2415 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2416 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002417 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002418 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002419 if (phone == null) return "";
2420 ServiceStateTracker sst = phone.getServiceStateTracker();
2421 if (sst == null) return "";
2422 LocaleTracker lt = sst.getLocaleTracker();
2423 if (lt == null) return "";
2424 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2425 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2426 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002427 } finally {
2428 Binder.restoreCallingIdentity(identity);
2429 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002430 }
2431
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002432 /**
2433 * This method was removed due to potential issues caused by performing partial
2434 * updates of service state, and lack of a credible use case.
2435 *
2436 * This has the ability to break the telephony implementation by disabling notification of
2437 * changes in device connectivity. DO NOT USE THIS!
2438 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002439 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 public void enableLocationUpdates() {
2441 mApp.enforceCallingOrSelfPermission(
2442 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 }
2444
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002445 /**
2446 * This method was removed due to potential issues caused by performing partial
2447 * updates of service state, and lack of a credible use case.
2448 *
2449 * This has the ability to break the telephony implementation by disabling notification of
2450 * changes in device connectivity. DO NOT USE THIS!
2451 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 @Override
2453 public void disableLocationUpdates() {
2454 mApp.enforceCallingOrSelfPermission(
2455 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 }
2457
Nathan Harold31d7ff32018-10-15 20:20:30 -07002458 /**
2459 * Returns the target SDK version number for a given package name.
2460 *
Nathan Haroldec184742019-07-10 17:04:16 -07002461 * This call MUST be invoked before clearing the calling UID.
2462 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002463 * @return target SDK if the package is found or INT_MAX.
2464 */
2465 private int getTargetSdk(String packageName) {
2466 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002467 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002468 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002469 if (ai != null) return ai.targetSdkVersion;
2470 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002471 loge("Failed to get package info for pkg="
2472 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002473 }
2474 return Integer.MAX_VALUE;
2475 }
2476
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 @Override
2478 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002479 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2480 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002481 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002482 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2483 throw new SecurityException(
2484 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2485 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002486
Jordan Liu1617b712019-07-10 15:06:26 -07002487 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2489 return null;
2490 }
Svetoslav64fad262015-04-14 14:35:21 -07002491
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002492 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002494 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002495 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496
Nathan Haroldf180aac2018-06-01 18:43:55 -07002497 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2498 for (CellInfo ci : info) {
2499 if (ci instanceof CellInfoGsm) {
2500 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2501 } else if (ci instanceof CellInfoWcdma) {
2502 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002505 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506 }
2507
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002508 private List<CellInfo> getCachedCellInfo() {
2509 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2510 for (Phone phone : PhoneFactory.getPhones()) {
2511 List<CellInfo> info = phone.getAllCellInfo();
2512 if (info != null) cellInfos.addAll(info);
2513 }
2514 return cellInfos;
2515 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516
2517 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002518 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002519 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002520 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002521
2522 LocationAccessPolicy.LocationPermissionResult locationResult =
2523 LocationAccessPolicy.checkLocationPermission(mApp,
2524 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2525 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002526 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002527 .setCallingPid(Binder.getCallingPid())
2528 .setCallingUid(Binder.getCallingUid())
2529 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002530 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002531 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2532 .build());
2533 switch (locationResult) {
2534 case DENIED_HARD:
2535 throw new SecurityException("Not allowed to access cell info");
2536 case DENIED_SOFT:
2537 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002538 }
2539
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002540 final int targetSdk = getTargetSdk(callingPackage);
2541 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2542 return getCachedCellInfo();
2543 }
2544
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002545 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002546 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002547 final long identity = Binder.clearCallingIdentity();
2548 try {
2549 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2550 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002551 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002552 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002553 if (info != null) cellInfos.addAll(info);
2554 }
2555 return cellInfos;
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558 }
2559 }
2560
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002561 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002562 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2563 String callingFeatureId) {
2564 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2565 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002566 }
2567
2568 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002569 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2570 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002571 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002572 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002573 }
2574
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002575 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2576 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002577 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002578 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002579
2580 LocationAccessPolicy.LocationPermissionResult locationResult =
2581 LocationAccessPolicy.checkLocationPermission(mApp,
2582 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2583 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002584 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002585 .setCallingPid(Binder.getCallingPid())
2586 .setCallingUid(Binder.getCallingUid())
2587 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002588 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2589 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002590 .build());
2591 switch (locationResult) {
2592 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002593 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2594 // Safetynet logging for b/154934934
2595 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2596 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002597 throw new SecurityException("Not allowed to access cell info");
2598 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002599 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2600 // Safetynet logging for b/154934934
2601 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2602 }
Nathan Harold5320c422019-05-09 10:26:08 -07002603 try {
2604 cb.onCellInfo(new ArrayList<CellInfo>());
2605 } catch (RemoteException re) {
2606 // Drop without consequences
2607 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002608 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002609 }
2610
Nathan Harolda939a962019-05-09 10:13:47 -07002611
2612 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002613 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2614
2615 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2616 }
2617
2618 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002620 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002621 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622
2623 final long identity = Binder.clearCallingIdentity();
2624 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002625 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 } finally {
2627 Binder.restoreCallingIdentity(identity);
2628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002629 }
2630
Shishir Agrawala9f32182016-04-12 12:00:16 -07002631 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002632 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002633 Phone phone = PhoneFactory.getPhone(slotIndex);
2634 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002635 return null;
2636 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002637 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002638 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002639 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002640 return null;
2641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642
2643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 return phone.getImei();
2646 } finally {
2647 Binder.restoreCallingIdentity(identity);
2648 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002649 }
2650
2651 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002652 public String getTypeAllocationCodeForSlot(int slotIndex) {
2653 Phone phone = PhoneFactory.getPhone(slotIndex);
2654 String tac = null;
2655 if (phone != null) {
2656 String imei = phone.getImei();
2657 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2658 }
2659 return tac;
2660 }
2661
2662 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002663 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002664 Phone phone = PhoneFactory.getPhone(slotIndex);
2665 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002666 return null;
2667 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002668
Jeff Davidson913390f2018-02-23 17:11:49 -08002669 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002670 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002671 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002672 return null;
2673 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674
2675 final long identity = Binder.clearCallingIdentity();
2676 try {
2677 return phone.getMeid();
2678 } finally {
2679 Binder.restoreCallingIdentity(identity);
2680 }
Jack Yu2af8d712017-03-15 17:14:14 -07002681 }
2682
2683 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002684 public String getManufacturerCodeForSlot(int slotIndex) {
2685 Phone phone = PhoneFactory.getPhone(slotIndex);
2686 String manufacturerCode = null;
2687 if (phone != null) {
2688 String meid = phone.getMeid();
2689 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2690 }
2691 return manufacturerCode;
2692 }
2693
2694 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002695 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2696 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002697 Phone phone = PhoneFactory.getPhone(slotIndex);
2698 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002699 return null;
2700 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002701 int subId = phone.getSubId();
2702 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002703 mApp, subId, callingPackage, callingFeatureId,
2704 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002705 return null;
2706 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707
2708 final long identity = Binder.clearCallingIdentity();
2709 try {
2710 return phone.getDeviceSvn();
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
2713 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002714 }
2715
fionaxu43304da2017-11-27 22:51:16 -08002716 @Override
2717 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 final Phone phone = getPhone(subId);
2721 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2722 } finally {
2723 Binder.restoreCallingIdentity(identity);
2724 }
fionaxu43304da2017-11-27 22:51:16 -08002725 }
2726
2727 @Override
2728 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729 final long identity = Binder.clearCallingIdentity();
2730 try {
2731 final Phone phone = getPhone(subId);
2732 return phone == null ? null : phone.getCarrierName();
2733 } finally {
2734 Binder.restoreCallingIdentity(identity);
2735 }
fionaxu43304da2017-11-27 22:51:16 -08002736 }
2737
calvinpanffe225e2018-11-01 19:43:06 +08002738 @Override
chen xu0026ca62019-03-06 15:28:50 -08002739 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002740 final long identity = Binder.clearCallingIdentity();
2741 try {
2742 final Phone phone = getPhone(subId);
2743 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002744 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002745 } finally {
2746 Binder.restoreCallingIdentity(identity);
2747 }
2748 }
2749
2750 @Override
chen xu0026ca62019-03-06 15:28:50 -08002751 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002752 final long identity = Binder.clearCallingIdentity();
2753 try {
2754 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002755 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002756 } finally {
2757 Binder.restoreCallingIdentity(identity);
2758 }
2759 }
2760
chen xu651eec72018-11-11 19:03:44 -08002761 @Override
chen xu864e11c2018-12-06 22:10:03 -08002762 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2763 if (!isSubscriptionMccMnc) {
2764 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2765 }
chen xu651eec72018-11-11 19:03:44 -08002766 final Phone phone = PhoneFactory.getPhone(slotIndex);
2767 if (phone == null) {
2768 return TelephonyManager.UNKNOWN_CARRIER_ID;
2769 }
2770 final long identity = Binder.clearCallingIdentity();
2771 try {
2772 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
2775 }
2776 }
2777
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 //
2779 // Internal helper methods.
2780 //
2781
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002782 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2784 *
2785 * @throws SecurityException if the caller does not have the required permission
2786 */
2787 private void enforceModifyPermission() {
2788 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2789 }
2790
Shuo Qiancd19c462020-01-16 20:51:11 -08002791 /**
2792 * Make sure the caller is system.
2793 *
2794 * @throws SecurityException if the caller is not system.
2795 */
2796 private void enforceSystemCaller() {
2797 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2798 throw new SecurityException("Caller must be system");
2799 }
2800 }
2801
Shuo Qian3b6ee772019-11-13 17:43:31 -08002802 private void enforceActiveEmergencySessionPermission() {
2803 mApp.enforceCallingOrSelfPermission(
2804 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2805 }
2806
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002807 /**
2808 * Make sure the caller has the CALL_PHONE permission.
2809 *
2810 * @throws SecurityException if the caller does not have the required permission
2811 */
2812 private void enforceCallPermission() {
2813 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2814 }
2815
paulhu5a773602019-08-23 19:17:33 +08002816 private void enforceSettingsPermission() {
2817 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002818 }
2819
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 private String createTelUrl(String number) {
2821 if (TextUtils.isEmpty(number)) {
2822 return null;
2823 }
2824
Jake Hambye994d462014-02-03 13:10:13 -08002825 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002826 }
2827
Ihab Awadf9e92732013-12-05 18:02:52 -08002828 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002829 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2830 }
2831
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002832 private static void logv(String msg) {
2833 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2834 }
2835
Ihab Awadf9e92732013-12-05 18:02:52 -08002836 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002837 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2838 }
2839
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002840 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002842 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002843 }
2844
Sanket Padawe356d7632015-06-22 14:03:32 -07002845 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002846 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 final Phone phone = PhoneFactory.getPhone(slotIndex);
2850 if (phone == null) {
2851 return PhoneConstants.PHONE_TYPE_NONE;
2852 } else {
2853 return phone.getPhoneType();
2854 }
2855 } finally {
2856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002858 }
2859
2860 /**
2861 * Returns the CDMA ERI icon index to display
2862 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002863 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002864 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2865 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2866 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002867 }
2868
Sanket Padawe356d7632015-06-22 14:03:32 -07002869 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002870 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2871 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002872 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002873 mApp, subId, callingPackage, callingFeatureId,
2874 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002875 return -1;
2876 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002877
2878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 final Phone phone = getPhone(subId);
2881 if (phone != null) {
2882 return phone.getCdmaEriIconIndex();
2883 } else {
2884 return -1;
2885 }
2886 } finally {
2887 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002889 }
2890
2891 /**
2892 * Returns the CDMA ERI icon mode,
2893 * 0 - ON
2894 * 1 - FLASHING
2895 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002896 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002897 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2898 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2899 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002900 }
2901
Sanket Padawe356d7632015-06-22 14:03:32 -07002902 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002903 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2904 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002906 mApp, subId, callingPackage, callingFeatureId,
2907 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002908 return -1;
2909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910
2911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 final Phone phone = getPhone(subId);
2914 if (phone != null) {
2915 return phone.getCdmaEriIconMode();
2916 } else {
2917 return -1;
2918 }
2919 } finally {
2920 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002921 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002922 }
2923
2924 /**
2925 * Returns the CDMA ERI text,
2926 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002927 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002928 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2929 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2930 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002931 }
2932
Sanket Padawe356d7632015-06-22 14:03:32 -07002933 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002934 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2935 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002936 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002937 mApp, subId, callingPackage, callingFeatureId,
2938 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002939 return null;
2940 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941
2942 final long identity = Binder.clearCallingIdentity();
2943 try {
2944 final Phone phone = getPhone(subId);
2945 if (phone != null) {
2946 return phone.getCdmaEriText();
2947 } else {
2948 return null;
2949 }
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 }
2954
2955 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002956 * Returns the CDMA MDN.
2957 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002958 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002959 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2961 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962
2963 final long identity = Binder.clearCallingIdentity();
2964 try {
2965 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002966 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002967 return phone.getLine1Number();
2968 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002969 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002970 return null;
2971 }
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002974 }
2975 }
2976
2977 /**
2978 * Returns the CDMA MIN.
2979 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002980 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002981 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2983 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002984
2985 final long identity = Binder.clearCallingIdentity();
2986 try {
2987 final Phone phone = getPhone(subId);
2988 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2989 return phone.getCdmaMin();
2990 } else {
2991 return null;
2992 }
2993 } finally {
2994 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002995 }
2996 }
2997
Hall Liud892bec2018-11-30 14:51:45 -08002998 @Override
2999 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3000 INumberVerificationCallback callback, String callingPackage) {
3001 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3002 != PERMISSION_GRANTED) {
3003 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3004 }
3005 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3006
3007 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3008 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3009 throw new SecurityException("Calling package must be configured in the device config");
3010 }
3011
3012 if (range == null) {
3013 throw new NullPointerException("Range must be non-null");
3014 }
3015
3016 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003017 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003018
3019 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3020 }
3021
Junda Liuca05d5d2014-08-14 22:36:34 -07003022 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003023 * Returns true if CDMA provisioning needs to run.
3024 */
3025 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 final long identity = Binder.clearCallingIdentity();
3027 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003028 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029 } finally {
3030 Binder.restoreCallingIdentity(identity);
3031 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003032 }
3033
3034 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003035 * Sets the voice mail number of a given subId.
3036 */
3037 @Override
3038 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003039 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3040 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041
3042 final long identity = Binder.clearCallingIdentity();
3043 try {
3044 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3045 new Pair<String, String>(alphaTag, number), new Integer(subId));
3046 return success;
3047 } finally {
3048 Binder.restoreCallingIdentity(identity);
3049 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003050 }
3051
Ta-wei Yen87c49842016-05-13 21:19:52 -07003052 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003053 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3054 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003055 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3056 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003057 if (!TextUtils.equals(callingPackage, systemDialer)) {
3058 throw new SecurityException("caller must be system dialer");
3059 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3064 if (phoneAccountHandle == null) {
3065 return null;
3066 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003067 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003068 } finally {
3069 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003070 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003071 }
3072
3073 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003074 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3075 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003076 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003077 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003078 mApp, subId, callingPackage, callingFeatureId,
3079 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003080 return null;
3081 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003083 final long identity = Binder.clearCallingIdentity();
3084 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003085 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003086 } finally {
3087 Binder.restoreCallingIdentity(identity);
3088 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003089 }
3090
3091 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003092 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3093 VisualVoicemailSmsFilterSettings settings) {
3094 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003095
3096 final long identity = Binder.clearCallingIdentity();
3097 try {
3098 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003099 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003100 } finally {
3101 Binder.restoreCallingIdentity(identity);
3102 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003103 }
3104
3105 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003106 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3107 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003108
3109 final long identity = Binder.clearCallingIdentity();
3110 try {
3111 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003112 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113 } finally {
3114 Binder.restoreCallingIdentity(identity);
3115 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003116 }
3117
3118 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003119 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3120 String callingPackage, int subId) {
3121 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003122
3123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003126 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003127 } finally {
3128 Binder.restoreCallingIdentity(identity);
3129 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003130 }
3131
3132 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003133 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003134 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003135
3136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003139 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003140 } finally {
3141 Binder.restoreCallingIdentity(identity);
3142 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003143 }
3144
3145 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003146 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3147 String callingAttributionTag, int subId, String number, int port, String text,
3148 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003149 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003150 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003151 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003152 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003153 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3154 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003155 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003156
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003157 /**
fionaxu0152e512016-11-14 13:36:14 -08003158 * Sets the voice activation state of a given subId.
3159 */
3160 @Override
3161 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3163 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164
3165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 final Phone phone = getPhone(subId);
3168 if (phone != null) {
3169 phone.setVoiceActivationState(activationState);
3170 } else {
3171 loge("setVoiceActivationState fails with invalid subId: " + subId);
3172 }
3173 } finally {
3174 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003175 }
3176 }
3177
3178 /**
3179 * Sets the data activation state of a given subId.
3180 */
3181 @Override
3182 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3184 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185
3186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 final Phone phone = getPhone(subId);
3189 if (phone != null) {
3190 phone.setDataActivationState(activationState);
3191 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003192 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193 }
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003196 }
3197 }
3198
3199 /**
3200 * Returns the voice activation state of a given subId.
3201 */
3202 @Override
3203 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003204 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205
fionaxu0152e512016-11-14 13:36:14 -08003206 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 final long identity = Binder.clearCallingIdentity();
3208 try {
3209 if (phone != null) {
3210 return phone.getVoiceActivationState();
3211 } else {
3212 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3213 }
3214 } finally {
3215 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003216 }
3217 }
3218
3219 /**
3220 * Returns the data activation state of a given subId.
3221 */
3222 @Override
3223 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003224 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003225
fionaxu0152e512016-11-14 13:36:14 -08003226 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 if (phone != null) {
3230 return phone.getDataActivationState();
3231 } else {
3232 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3233 }
3234 } finally {
3235 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003236 }
3237 }
3238
3239 /**
Wink Saville36469e72014-06-11 15:17:00 -07003240 * Returns the unread count of voicemails for a subId
3241 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003242 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003243 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3244 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003245 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003246 mApp, subId, callingPackage, callingFeatureId,
3247 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003248 return 0;
3249 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003250 final long identity = Binder.clearCallingIdentity();
3251 try {
3252 final Phone phone = getPhone(subId);
3253 if (phone != null) {
3254 return phone.getVoiceMessageCount();
3255 } else {
3256 return 0;
3257 }
3258 } finally {
3259 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003261 }
3262
3263 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003264 * returns true, if the device is in a state where both voice and data
3265 * are supported simultaneously. This can change based on location or network condition.
3266 */
3267 @Override
3268 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269 final long identity = Binder.clearCallingIdentity();
3270 try {
3271 final Phone phone = getPhone(subId);
3272 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3273 } finally {
3274 Binder.restoreCallingIdentity(identity);
3275 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003276 }
3277
3278 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003279 * Send the dialer code if called from the current default dialer or the caller has
3280 * carrier privilege.
3281 * @param inputCode The dialer code to send
3282 */
3283 @Override
3284 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003285 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003286 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003287 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3288 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003289 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003290 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003291 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003293
3294 final long identity = Binder.clearCallingIdentity();
3295 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003296 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003297 } finally {
3298 Binder.restoreCallingIdentity(identity);
3299 }
fionaxu235cc5e2017-03-06 22:25:57 -08003300 }
3301
Pengquan Menga1bb6272018-09-06 09:59:22 -07003302 @Override
3303 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003304 TelephonyPermissions
3305 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3306 mApp, subId, "getNetworkSelectionMode");
3307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 if (!isActiveSubscription(subId)) {
3310 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3311 }
3312 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003315 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003316 }
3317
Brad Ebinger35c841c2018-10-01 10:40:55 -07003318 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003319 public boolean isInEmergencySmsMode() {
3320 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3321 final long identity = Binder.clearCallingIdentity();
3322 try {
3323 for (Phone phone : PhoneFactory.getPhones()) {
3324 if (phone.isInEmergencySmsMode()) {
3325 return true;
3326 }
3327 }
3328 } finally {
3329 Binder.restoreCallingIdentity(identity);
3330 }
3331 return false;
3332 }
3333
shilu366312e2019-12-17 09:28:10 -08003334 /**
3335 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3336 * @param subId The subscription to use to check the configuration.
3337 * @param c The callback that will be used to send the result.
3338 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003339 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003340 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3341 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003342 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3343 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003344
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003345 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3346 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3347 "IMS not available on device.");
3348 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 final long token = Binder.clearCallingIdentity();
3350 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003351 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003352 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003353 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003354 } catch (ImsException e) {
3355 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003356 } finally {
3357 Binder.restoreCallingIdentity(token);
3358 }
3359 }
3360
shilu366312e2019-12-17 09:28:10 -08003361 /**
3362 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3363 * @param subId The subscription to use to check the configuration.
3364 * @param c The callback that will be used to send the result.
3365 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003367 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003368 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3369 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003370 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3371 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3372 }
Meng Wangafbc5852019-09-19 17:37:13 -07003373 final long token = Binder.clearCallingIdentity();
3374 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003375 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003376 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3377 .removeRegistrationCallbackForSubscription(c, subId);
3378 } catch (ImsException e) {
3379 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3380 + "is inactive, ignoring unregister.");
3381 // If the subscription is no longer active, just return, since the callback
3382 // will already have been removed internally.
3383 } finally {
3384 Binder.restoreCallingIdentity(token);
3385 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003386 }
3387
Brad Ebingera34a6c22019-10-22 17:36:18 -07003388 /**
3389 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3390 */
3391 @Override
3392 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3393 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3394 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3395 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3396 "IMS not available on device.");
3397 }
3398 final long token = Binder.clearCallingIdentity();
3399 try {
3400 Phone phone = getPhone(subId);
3401 if (phone == null) {
3402 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3403 + subId + "'");
3404 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3405 }
3406 phone.getImsRegistrationState(regState -> {
3407 try {
3408 consumer.accept((regState == null)
3409 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3410 } catch (RemoteException e) {
3411 // Ignore if the remote process is no longer available to call back.
3412 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3413 }
3414 });
3415 } finally {
3416 Binder.restoreCallingIdentity(token);
3417 }
3418 }
3419
3420 /**
3421 * Get the transport type for the IMS service registration state.
3422 */
3423 @Override
3424 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003425 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3426 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003427 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3428 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3429 "IMS not available on device.");
3430 }
3431 final long token = Binder.clearCallingIdentity();
3432 try {
3433 Phone phone = getPhone(subId);
3434 if (phone == null) {
3435 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3436 + subId + "'");
3437 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3438 }
3439 phone.getImsRegistrationTech(regTech -> {
3440 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3441 int regTechConverted = (regTech == null)
3442 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3443 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3444 regTechConverted);
3445 try {
3446 consumer.accept(regTechConverted);
3447 } catch (RemoteException e) {
3448 // Ignore if the remote process is no longer available to call back.
3449 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3450 }
3451 });
3452 } finally {
3453 Binder.restoreCallingIdentity(token);
3454 }
3455 }
3456
shilu366312e2019-12-17 09:28:10 -08003457 /**
3458 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3459 * @param subId The subscription to use to check the configuration.
3460 * @param c The callback that will be used to send the result.
3461 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003462 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003463 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3464 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003465 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3466 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003467 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3468 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3469 "IMS not available on device.");
3470 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003471 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3472 final long token = Binder.clearCallingIdentity();
3473 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003474 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003475 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003476 } catch (ImsException e) {
3477 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003478 } finally {
3479 Binder.restoreCallingIdentity(token);
3480 }
3481 }
3482
shilu366312e2019-12-17 09:28:10 -08003483 /**
3484 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3485 * @param subId The subscription to use to check the configuration.
3486 * @param c The callback that will be used to send the result.
3487 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003488 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003489 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003490 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3491 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003492 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3493 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3494 }
Meng Wangafbc5852019-09-19 17:37:13 -07003495
3496 final long token = Binder.clearCallingIdentity();
3497 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003498 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003499 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003500 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003501 } catch (ImsException e) {
3502 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3503 + "is inactive, ignoring unregister.");
3504 // If the subscription is no longer active, just return, since the callback
3505 // will already have been removed internally.
3506 } finally {
3507 Binder.restoreCallingIdentity(token);
3508 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003509 }
3510
3511 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003512 public boolean isCapable(int subId, int capability, int regTech) {
3513 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003514 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3515 final long token = Binder.clearCallingIdentity();
3516 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003517 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003518 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003519 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003520 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3521 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003522 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003523 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3524 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003525 } finally {
3526 Binder.restoreCallingIdentity(token);
3527 }
3528 }
3529
3530 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003531 public boolean isAvailable(int subId, int capability, int regTech) {
3532 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003533 final long token = Binder.clearCallingIdentity();
3534 try {
3535 Phone phone = getPhone(subId);
3536 if (phone == null) return false;
3537 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003538 } catch (com.android.ims.ImsException e) {
3539 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3540 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003541 } finally {
3542 Binder.restoreCallingIdentity(token);
3543 }
3544 }
3545
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003546 /**
3547 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3548 * subscription.
3549 * @param subId The subscription to use to check the configuration.
3550 * @param callback The callback that will be used to send the result.
3551 * @param capability The MmTelFeature capability that will be used to send the result.
3552 * @param transportType The transport type of the MmTelFeature capability.
3553 */
3554 @Override
3555 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3556 int transportType) {
3557 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3558 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3559 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3560 "IMS not available on device.");
3561 }
3562 final long token = Binder.clearCallingIdentity();
3563 try {
3564 int slotId = getSlotIndex(subId);
3565 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3566 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3567 + subId + "'");
3568 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3569 }
3570 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3571 transportType, aBoolean -> {
3572 try {
3573 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3574 } catch (RemoteException e) {
3575 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3576 + "running. Ignore");
3577 }
3578 });
3579 } finally {
3580 Binder.restoreCallingIdentity(token);
3581 }
3582 }
3583
shilu366312e2019-12-17 09:28:10 -08003584 /**
3585 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3586 * @param subId The subscription to use to check the configuration.
3587 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003588 @Override
3589 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003590 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3591 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003592
Brad Ebinger35c841c2018-10-01 10:40:55 -07003593 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3594 final long token = Binder.clearCallingIdentity();
3595 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003596 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003597 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003598 } catch (ImsException e) {
3599 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003600 } finally {
3601 Binder.restoreCallingIdentity(token);
3602 }
3603 }
3604
3605 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003606 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003608 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003612 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003613 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003614 } catch (ImsException e) {
3615 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003616 } finally {
3617 Binder.restoreCallingIdentity(identity);
3618 }
3619 }
3620
shilu366312e2019-12-17 09:28:10 -08003621 /**
3622 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3623 * @param subId The subscription to use to check the configuration.
3624 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003625 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003626 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003627 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3628 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003629 final long identity = Binder.clearCallingIdentity();
3630 try {
3631 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003632 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3633 } catch (ImsException e) {
3634 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003635 } finally {
3636 Binder.restoreCallingIdentity(identity);
3637 }
3638 }
3639
3640 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003641 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003643 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003644 final long identity = Binder.clearCallingIdentity();
3645 try {
3646 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003647 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003648 } catch (ImsException e) {
3649 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
3653 }
3654
shilu366312e2019-12-17 09:28:10 -08003655 /**
3656 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3657 * @param subId The subscription to use to check the configuration.
3658 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003659 @Override
3660 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003661 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3662 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003666 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003667 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003668 } catch (ImsException e) {
3669 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003670 } finally {
3671 Binder.restoreCallingIdentity(identity);
3672 }
3673 }
3674
3675 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003676 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003678 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003679 final long identity = Binder.clearCallingIdentity();
3680 try {
3681 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003682 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003683 } catch (ImsException e) {
3684 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003685 } finally {
3686 Binder.restoreCallingIdentity(identity);
3687 }
3688 }
3689
shilu366312e2019-12-17 09:28:10 -08003690 /**
3691 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3692 * @param subId The subscription to use to check the configuration.
3693 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003694 @Override
3695 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003696 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3697 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003701 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003702 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003703 } catch (ImsException e) {
3704 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003705 } finally {
3706 Binder.restoreCallingIdentity(identity);
3707 }
3708 }
3709
3710 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003711 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003713 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 final long identity = Binder.clearCallingIdentity();
3715 try {
3716 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003717 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003718 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003719 } catch (ImsException e) {
3720 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003721 } finally {
3722 Binder.restoreCallingIdentity(identity);
3723 }
3724 }
3725
3726 @Override
3727 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3728 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3729 "setVoWiFiNonPersistent");
3730 final long identity = Binder.clearCallingIdentity();
3731 try {
3732 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003733 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003734 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003735 } catch (ImsException e) {
3736 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
3740 }
3741
shilu366312e2019-12-17 09:28:10 -08003742 /**
3743 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3744 * @param subId The subscription to use to check the configuration.
3745 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003746 @Override
3747 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003748 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3749 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003753 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003754 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003755 } catch (ImsException e) {
3756 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 } finally {
3758 Binder.restoreCallingIdentity(identity);
3759 }
3760 }
3761
3762 @Override
3763 public void setVoWiFiModeSetting(int subId, int mode) {
3764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3765 "setVoWiFiModeSetting");
3766 final long identity = Binder.clearCallingIdentity();
3767 try {
3768 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003769 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003770 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003771 } catch (ImsException e) {
3772 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003773 } finally {
3774 Binder.restoreCallingIdentity(identity);
3775 }
3776 }
3777
3778 @Override
3779 public int getVoWiFiRoamingModeSetting(int subId) {
3780 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3781 final long identity = Binder.clearCallingIdentity();
3782 try {
3783 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003784 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003785 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003786 } catch (ImsException e) {
3787 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003788 } finally {
3789 Binder.restoreCallingIdentity(identity);
3790 }
3791 }
3792
3793 @Override
3794 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3796 "setVoWiFiRoamingModeSetting");
3797 final long identity = Binder.clearCallingIdentity();
3798 try {
3799 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003800 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003801 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003802 } catch (ImsException e) {
3803 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003804 } finally {
3805 Binder.restoreCallingIdentity(identity);
3806 }
3807 }
3808
3809 @Override
3810 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3812 "setRttCapabilityEnabled");
3813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003816 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3817 } catch (ImsException e) {
3818 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003819 } finally {
3820 Binder.restoreCallingIdentity(identity);
3821 }
3822 }
3823
shilu366312e2019-12-17 09:28:10 -08003824 /**
3825 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3826 * @param subId The subscription to use to check the configuration.
3827 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003828 @Override
3829 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003830 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3831 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003832 final long identity = Binder.clearCallingIdentity();
3833 try {
3834 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003835 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003836 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003837 } catch (ImsException e) {
3838 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003839 } finally {
3840 Binder.restoreCallingIdentity(identity);
3841 }
3842 }
3843
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003844 @Override
3845 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3846 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3847 final long identity = Binder.clearCallingIdentity();
3848 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003849 if (!isImsAvailableOnDevice()) {
3850 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3851 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003852 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003854 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003855 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003856 } catch (ImsException e) {
3857 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003858 } finally {
3859 Binder.restoreCallingIdentity(identity);
3860 }
3861 }
3862
3863 @Override
3864 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3865 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3866 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003867 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3868 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3869 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003870 try {
3871 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003872 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003873 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003874 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003875 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3876 + "is inactive, ignoring unregister.");
3877 // If the subscription is no longer active, just return, since the callback will already
3878 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003879 } finally {
3880 Binder.restoreCallingIdentity(identity);
3881 }
3882 }
3883
allenwtsu99c623b2020-01-03 18:24:23 +08003884
3885 private void checkModifyPhoneStatePermission(int subId, String message) {
3886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3887 message);
3888 }
3889
3890 private boolean isImsProvisioningRequired(int subId, int capability,
3891 boolean isMmtelCapability) {
3892 Phone phone = getPhone(subId);
3893 if (phone == null) {
3894 loge("phone instance null for subid " + subId);
3895 return false;
3896 }
3897 if (isMmtelCapability) {
3898 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3899 return false;
3900 }
3901 } else {
3902 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3903 return false;
3904 }
3905 }
3906 return true;
3907 }
3908
3909 @Override
3910 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3911 boolean isProvisioned) {
3912 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3913
3914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3917 if (!isImsProvisioningRequired(subId, capability, false)) {
3918 return;
3919 }
3920
3921 // this capability requires provisioning, route to the correct API.
3922 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3923 switch (capability) {
3924 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3925 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3926 ims.setEabProvisioned(isProvisioned);
3927 break;
3928 default: {
3929 throw new IllegalArgumentException("Tried to set provisioning for "
3930 + "rcs capability '" + capability + "', which does not require "
3931 + "provisioning.");
3932 }
3933 }
3934 } finally {
3935 Binder.restoreCallingIdentity(identity);
3936 }
3937
3938 }
3939
3940
3941 @Override
3942 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3943 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3944 final long identity = Binder.clearCallingIdentity();
3945 try {
3946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3947 if (!isImsProvisioningRequired(subId, capability, false)) {
3948 return true;
3949 }
3950
3951 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3952 switch (capability) {
3953 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3954 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3955 return ims.isEabProvisionedOnDevice();
3956
3957 default: {
3958 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3959 + "capability '" + capability + "', which does not require "
3960 + "provisioning.");
3961 }
3962 }
3963
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
3966 }
3967 }
3968
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003969 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003970 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3971 boolean isProvisioned) {
3972 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3973 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3974 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3975 }
allenwtsu99c623b2020-01-03 18:24:23 +08003976 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003977 final long identity = Binder.clearCallingIdentity();
3978 try {
3979 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003980 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003981 return;
3982 }
3983
3984 // this capability requires provisioning, route to the correct API.
3985 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3986 switch (capability) {
3987 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3988 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3989 ims.setVolteProvisioned(isProvisioned);
3990 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3991 ims.setWfcProvisioned(isProvisioned);
3992 }
3993 break;
3994 }
3995 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3996 // There is currently no difference in VT provisioning type.
3997 ims.setVtProvisioned(isProvisioned);
3998 break;
3999 }
4000 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4001 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4002 // change the capability of the feature instead if needed.
4003 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4004 == isProvisioned) {
4005 // No change in provisioning.
4006 return;
4007 }
4008 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4009 try {
4010 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004011 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004012 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4013 + ", Exception" + e.getMessage());
4014 }
4015 break;
4016 }
4017 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004018 throw new IllegalArgumentException("Tried to set provisioning for "
4019 + "MmTel capability '" + capability + "', which does not require "
4020 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004021 }
4022 }
4023
4024 } finally {
4025 Binder.restoreCallingIdentity(identity);
4026 }
4027 }
4028
4029 @Override
4030 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4031 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4032 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4033 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4034 }
4035 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4036 final long identity = Binder.clearCallingIdentity();
4037 try {
4038 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004039 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004040 return true;
4041 }
4042
4043 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4044 switch (capability) {
4045 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4046 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4047 return ims.isVolteProvisionedOnDevice();
4048 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4049 return ims.isWfcProvisionedOnDevice();
4050 }
4051 // This should never happen, since we are checking tech above to make sure it
4052 // is either LTE or IWLAN.
4053 throw new IllegalArgumentException("Invalid radio technology for voice "
4054 + "capability.");
4055 }
4056 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4057 // There is currently no difference in VT provisioning type.
4058 return ims.isVtProvisionedOnDevice();
4059 }
4060 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4061 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4062 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4063 }
4064 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004065 throw new IllegalArgumentException(
4066 "Tried to get provisioning for MmTel capability '" + capability
4067 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004068 }
4069 }
4070
4071 } finally {
4072 Binder.restoreCallingIdentity(identity);
4073 }
4074 }
4075
4076 @Override
4077 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4078 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4079 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4080 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4081 }
4082 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4083 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4084 return (provisionedBits & capability) > 0;
4085 }
4086
4087 @Override
4088 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4089 boolean isProvisioned) {
4090 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4091 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4092 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4093 }
4094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4095 "setProvisioningStatusForCapability");
4096 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4097 // If the current provisioning status for capability already matches isProvisioned,
4098 // do nothing.
4099 if (((provisionedBits & capability) > 0) == isProvisioned) {
4100 return;
4101 }
4102 if (isProvisioned) {
4103 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4104 } else {
4105 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4106 }
4107 }
4108
4109 /**
4110 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4111 * technology. The bitfield should mirror the bitfield defined by
4112 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4113 */
4114 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4115 String key = getMmTelProvisioningKey(subId, tech);
4116 // Default is no capabilities are provisioned.
4117 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4118 }
4119
4120 /**
4121 * Sets the MmTel capability provisioning bitfield (defined by
4122 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4123 * technology specified.
4124 *
4125 * Note: This is a synchronous command and should not be called on UI thread.
4126 */
4127 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4128 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4129 String key = getMmTelProvisioningKey(subId, tech);
4130 editor.putInt(key, newField);
4131 editor.commit();
4132 }
4133
4134 private static String getMmTelProvisioningKey(int subId, int tech) {
4135 // resulting key is provision_ims_mmtel_{subId}_{tech}
4136 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4137 }
4138
4139 /**
4140 * Query CarrierConfig to see if the specified capability requires provisioning for the
4141 * carrier associated with the subscription id.
4142 */
4143 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4144 int capability) {
4145 CarrierConfigManager configManager = new CarrierConfigManager(context);
4146 PersistableBundle c = configManager.getConfigForSubId(subId);
4147 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004148 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004149 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4150 false);
4151 boolean requireVoiceVtProvisioning = c.getBoolean(
4152 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4153
4154 // First check to make sure that the capability requires provisioning.
4155 switch (capability) {
4156 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4157 // intentional fallthrough
4158 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4159 if (requireVoiceVtProvisioning) {
4160 // Voice and Video requires provisioning
4161 return true;
4162 }
4163 break;
4164 }
4165 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4166 if (requireUtProvisioning) {
4167 // UT requires provisioning
4168 return true;
4169 }
4170 break;
4171 }
4172 }
4173 return false;
4174 }
4175
allenwtsu99c623b2020-01-03 18:24:23 +08004176 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4177 int capability) {
4178 CarrierConfigManager configManager = new CarrierConfigManager(context);
4179 PersistableBundle c = configManager.getConfigForSubId(subId);
4180
4181 boolean requireRcsProvisioning = c.getBoolean(
4182 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4183
4184 // First check to make sure that the capability requires provisioning.
4185 switch (capability) {
4186 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4187 // intentional fallthrough
4188 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4189 if (requireRcsProvisioning) {
4190 // OPTION or PRESENCE requires provisioning
4191 return true;
4192 }
4193 break;
4194 }
4195 }
4196 return false;
4197 }
4198
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004199 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004200 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004201 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4202 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4203 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004204 enforceReadPrivilegedPermission("getImsProvisioningInt");
4205 final long identity = Binder.clearCallingIdentity();
4206 try {
4207 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004208 int slotId = getSlotIndex(subId);
4209 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4210 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4211 + subId + "' for key:" + key);
4212 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4213 }
4214 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004215 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004216 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4217 + subId + "' for key:" + key);
4218 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004219 } finally {
4220 Binder.restoreCallingIdentity(identity);
4221 }
4222 }
4223
4224 @Override
4225 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004226 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4227 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4228 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004229 enforceReadPrivilegedPermission("getImsProvisioningString");
4230 final long identity = Binder.clearCallingIdentity();
4231 try {
4232 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004233 int slotId = getSlotIndex(subId);
4234 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4235 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4236 + subId + "' for key:" + key);
4237 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4238 }
4239 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004240 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004241 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4242 + subId + "' for key:" + key);
4243 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004244 } finally {
4245 Binder.restoreCallingIdentity(identity);
4246 }
4247 }
4248
4249 @Override
4250 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004251 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4252 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4253 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4255 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004256 final long identity = Binder.clearCallingIdentity();
4257 try {
4258 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004259 int slotId = getSlotIndex(subId);
4260 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4261 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4262 + subId + "' for key:" + key);
4263 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4264 }
4265 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004266 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004267 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4268 + "' for key:" + key);
4269 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004270 } finally {
4271 Binder.restoreCallingIdentity(identity);
4272 }
4273 }
4274
4275 @Override
4276 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004277 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4278 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4279 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4281 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004282 final long identity = Binder.clearCallingIdentity();
4283 try {
4284 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004285 int slotId = getSlotIndex(subId);
4286 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4287 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4288 + subId + "' for key:" + key);
4289 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4290 }
4291 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004292 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004293 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4294 + "' for key:" + key);
4295 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004296 } finally {
4297 Binder.restoreCallingIdentity(identity);
4298 }
4299 }
4300
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004301 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004302 int slotId = SubscriptionManager.getSlotIndex(subId);
4303 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004304 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4305 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004306 }
4307 return slotId;
4308 }
4309
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004310 private int getSlotIndex(int subId) {
4311 int slotId = SubscriptionManager.getSlotIndex(subId);
4312 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4313 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4314 }
4315 return slotId;
4316 }
4317
Wink Saville36469e72014-06-11 15:17:00 -07004318 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004319 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004320 */
4321 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004322 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4323 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004324 final int targetSdk = getTargetSdk(callingPackage);
4325 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004326 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004327 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004328 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004329 mApp, subId, callingPackage, callingFeatureId,
4330 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004331 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4332 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334 final long identity = Binder.clearCallingIdentity();
4335 try {
4336 final Phone phone = getPhone(subId);
4337 if (phone != null) {
4338 return phone.getServiceState().getDataNetworkType();
4339 } else {
4340 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4341 }
4342 } finally {
4343 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004345 }
4346
4347 /**
4348 * Returns the data network type
4349 */
4350 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004351 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4352 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4353 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004354 }
4355
4356 /**
4357 * Returns the data network type for a subId
4358 */
4359 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004360 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4361 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004362 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004363 mApp, subId, callingPackage, callingFeatureId,
4364 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004365 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4366 }
4367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368 final long identity = Binder.clearCallingIdentity();
4369 try {
4370 final Phone phone = getPhone(subId);
4371 if (phone != null) {
4372 return phone.getServiceState().getDataNetworkType();
4373 } else {
4374 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4375 }
4376 } finally {
4377 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004378 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004379 }
4380
4381 /**
Wink Saville36469e72014-06-11 15:17:00 -07004382 * Returns the Voice network type for a subId
4383 */
4384 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004385 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4386 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004388 mApp, subId, callingPackage, callingFeatureId,
4389 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004390 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4391 }
4392
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393 final long identity = Binder.clearCallingIdentity();
4394 try {
4395 final Phone phone = getPhone(subId);
4396 if (phone != null) {
4397 return phone.getServiceState().getVoiceNetworkType();
4398 } else {
4399 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4400 }
4401 } finally {
4402 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004404 }
4405
4406 /**
4407 * @return true if a ICC card is present
4408 */
4409 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004410 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004411 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4412 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004413 }
4414
4415 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004416 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004417 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004418 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004419 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420 final long identity = Binder.clearCallingIdentity();
4421 try {
4422 final Phone phone = PhoneFactory.getPhone(slotIndex);
4423 if (phone != null) {
4424 return phone.getIccCard().hasIccCard();
4425 } else {
4426 return false;
4427 }
4428 } finally {
4429 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004431 }
4432
4433 /**
4434 * Return if the current radio is LTE on CDMA. This
4435 * is a tri-state return value as for a period of time
4436 * the mode may be unknown.
4437 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004438 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004439 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004440 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004441 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004442 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004443 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4444 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4445 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004446 }
4447
Sanket Padawe356d7632015-06-22 14:03:32 -07004448 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004449 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4450 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004451 try {
4452 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4453 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004454 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4455 }
4456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457 final long identity = Binder.clearCallingIdentity();
4458 try {
4459 final Phone phone = getPhone(subId);
4460 if (phone == null) {
4461 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4462 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004463 return TelephonyProperties.lte_on_cdma_device()
4464 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004465 }
4466 } finally {
4467 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004468 }
Wink Saville36469e72014-06-11 15:17:00 -07004469 }
4470
Wink Saville36469e72014-06-11 15:17:00 -07004471 /**
4472 * {@hide}
4473 * Returns Default subId, 0 in the case of single standby.
4474 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004475 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004476 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004477 }
4478
Shishir Agrawala9f32182016-04-12 12:00:16 -07004479 private int getSlotForDefaultSubscription() {
4480 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4481 }
4482
Wink Savilleb564aae2014-10-23 10:18:09 -07004483 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004484 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004485 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004486
Pengquan Menge92a50d2018-09-21 15:54:48 -07004487 private boolean isActiveSubscription(int subId) {
4488 return mSubscriptionController.isActiveSubId(subId);
4489 }
4490
Ihab Awadf2177b72013-11-25 13:33:23 -08004491 /**
4492 * @see android.telephony.TelephonyManager.WifiCallingChoices
4493 */
4494 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 final long identity = Binder.clearCallingIdentity();
4496 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004497 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4499 getWhenToMakeWifiCallsDefaultPreference());
4500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004503 }
4504
4505 /**
4506 * @see android.telephony.TelephonyManager.WifiCallingChoices
4507 */
4508 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004509 final long identity = Binder.clearCallingIdentity();
4510 try {
4511 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004512 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004513 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4514 } finally {
4515 Binder.restoreCallingIdentity(identity);
4516 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004517 }
4518
Sailesh Nepald1e68152013-12-12 19:08:02 -08004519 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004520 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004521 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004522 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004523
Jordan Liu4c733742019-02-28 12:03:40 -08004524 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4525 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4526 if (phoneId == -1) {
4527 throw new IllegalArgumentException("Given slot index: " + slotIndex
4528 + " does not correspond to an active phone");
4529 }
4530 return PhoneFactory.getPhone(phoneId);
4531 }
4532
Shishir Agrawal566b7612013-10-28 14:41:00 -07004533 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004534 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4535 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4537 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004538 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004539 if (DBG) {
4540 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4541 }
4542 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4543 p2);
4544 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004545
Jordan Liu4c733742019-02-28 12:03:40 -08004546
4547 @Override
4548 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4549 int slotIndex, String callingPackage, String aid, int p2) {
4550 enforceModifyPermission();
4551 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4552 if (DBG) {
4553 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4554 }
4555 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4556 callingPackage, aid, p2);
4557 }
4558
4559 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4560 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561 final long identity = Binder.clearCallingIdentity();
4562 try {
4563 if (TextUtils.equals(ISDR_AID, aid)) {
4564 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004565 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4566 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004567 if (bestComponent == null
4568 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4569 loge("The calling package is not allowed to access ISD-R.");
4570 throw new SecurityException(
4571 "The calling package is not allowed to access ISD-R.");
4572 }
Derek Tan740e1672017-06-27 14:56:27 -07004573 }
Derek Tan740e1672017-06-27 14:56:27 -07004574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004576 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4577 null /* workSource */);
4578 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004579 return response;
4580 } finally {
4581 Binder.restoreCallingIdentity(identity);
4582 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004583 }
4584
4585 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004586 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4588 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004589 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4590 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4591 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004592
Jordan Liu4c733742019-02-28 12:03:40 -08004593 @Override
4594 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4595 enforceModifyPermission();
4596 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4597 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4598 channel);
4599 }
4600
4601 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004602 final long identity = Binder.clearCallingIdentity();
4603 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004604 if (channel < 0) {
4605 return false;
4606 }
Jordan Liu4c733742019-02-28 12:03:40 -08004607 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4608 null /* workSource */);
4609 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004610 return success;
4611 } finally {
4612 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004613 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004614 }
4615
4616 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004617 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004618 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4620 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004621 if (DBG) {
4622 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4623 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4624 + p3 + " data=" + data);
4625 }
4626 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4627 command, p1, p2, p3, data);
4628 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004629
Jordan Liu4c733742019-02-28 12:03:40 -08004630 @Override
4631 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4632 int command, int p1, int p2, int p3, String data) {
4633 enforceModifyPermission();
4634 if (DBG) {
4635 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4636 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4637 + p3 + " data=" + data);
4638 }
4639 return iccTransmitApduLogicalChannelWithPermission(
4640 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4641 data);
4642 }
4643
4644 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4645 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646 final long identity = Binder.clearCallingIdentity();
4647 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004648 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004649 return "";
4650 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004652 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004653 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4654 null /* workSource */);
4655 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004657 // Append the returned status code to the end of the response payload.
4658 String s = Integer.toHexString(
4659 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4660 if (response.payload != null) {
4661 s = IccUtils.bytesToHexString(response.payload) + s;
4662 }
4663 return s;
4664 } finally {
4665 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004666 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004667 }
Jake Hambye994d462014-02-03 13:10:13 -08004668
Evan Charltonc66da362014-05-16 14:06:40 -07004669 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004670 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4671 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4673 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004674 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004675 if (DBG) {
4676 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4677 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4678 }
4679 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4680 cla, command, p1, p2, p3, data);
4681 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004682
Jordan Liu4c733742019-02-28 12:03:40 -08004683 @Override
4684 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4685 int command, int p1, int p2, int p3, String data) {
4686 enforceModifyPermission();
4687 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4688 if (DBG) {
4689 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4690 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4691 + " data=" + data);
4692 }
4693
4694 return iccTransmitApduBasicChannelWithPermission(
4695 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4696 p2, p3, data);
4697 }
4698
4699 // open APDU basic channel assuming the caller has sufficient permissions
4700 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4701 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004702 final long identity = Binder.clearCallingIdentity();
4703 try {
4704 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4705 && TextUtils.equals(ISDR_AID, data)) {
4706 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004707 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4708 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004709 if (bestComponent == null
4710 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4711 loge("The calling package is not allowed to select ISD-R.");
4712 throw new SecurityException(
4713 "The calling package is not allowed to select ISD-R.");
4714 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004715 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004717 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004718 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4719 null /* workSource */);
4720 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004721
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004722 // Append the returned status code to the end of the response payload.
4723 String s = Integer.toHexString(
4724 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4725 if (response.payload != null) {
4726 s = IccUtils.bytesToHexString(response.payload) + s;
4727 }
4728 return s;
4729 } finally {
4730 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004731 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004732 }
4733
4734 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004735 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004736 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4738 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004740 final long identity = Binder.clearCallingIdentity();
4741 try {
4742 if (DBG) {
4743 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4744 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4745 }
4746
4747 IccIoResult response =
4748 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4749 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4750 subId);
4751
4752 if (DBG) {
4753 log("Exchange SIM_IO [R]" + response);
4754 }
4755
4756 byte[] result = null;
4757 int length = 2;
4758 if (response.payload != null) {
4759 length = 2 + response.payload.length;
4760 result = new byte[length];
4761 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4762 } else {
4763 result = new byte[length];
4764 }
4765
4766 result[length - 1] = (byte) response.sw2;
4767 result[length - 2] = (byte) response.sw1;
4768 return result;
4769 } finally {
4770 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004771 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004772 }
4773
Nathan Haroldb3014052017-01-25 15:57:32 -08004774 /**
4775 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4776 * on a particular subscription
4777 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004778 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4779 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004781 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004782 return null;
4783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784
4785 final long identity = Binder.clearCallingIdentity();
4786 try {
4787 if (appType != TelephonyManager.APPTYPE_USIM
4788 && appType != TelephonyManager.APPTYPE_SIM) {
4789 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4790 return null;
4791 }
4792 Object response = sendRequest(
4793 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4794 if (response instanceof String[]) {
4795 return (String[]) response;
4796 }
yincheng zhao2737e882019-09-06 17:06:54 -07004797 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004799 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004800 } finally {
4801 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004802 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004803 }
4804
yincheng zhao2737e882019-09-06 17:06:54 -07004805 /**
4806 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4807 * subscription.
4808 *
4809 * @param subId the id of the subscription.
4810 * @param appType the uicc app type, must be USIM or SIM.
4811 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4812 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004813 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004814 * @return number of fplmns that is successfully written to the SIM.
4815 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004816 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4817 String callingFeatureId) {
4818 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4819 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004820 if (DBG) logv("no permissions for setForbiddenplmns");
4821 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4822 }
4823 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4824 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4825 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4826 }
4827 if (fplmns == null) {
4828 throw new IllegalArgumentException("Fplmn List provided is null");
4829 }
4830 for (String fplmn : fplmns) {
4831 if (!CellIdentity.isValidPlmn(fplmn)) {
4832 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4833 }
4834 }
4835 final long identity = Binder.clearCallingIdentity();
4836 try {
4837 Object response = sendRequest(
4838 CMD_SET_FORBIDDEN_PLMNS,
4839 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4840 subId);
4841 return (int) response;
4842 } finally {
4843 Binder.restoreCallingIdentity(identity);
4844 }
4845 }
4846
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004847 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004848 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4850 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004851
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004852 final long identity = Binder.clearCallingIdentity();
4853 try {
4854 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4855 if (response.payload == null) {
4856 return "";
4857 }
Evan Charltonc66da362014-05-16 14:06:40 -07004858
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859 // Append the returned status code to the end of the response payload.
4860 String s = Integer.toHexString(
4861 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4862 s = IccUtils.bytesToHexString(response.payload) + s;
4863 return s;
4864 } finally {
4865 Binder.restoreCallingIdentity(identity);
4866 }
Evan Charltonc66da362014-05-16 14:06:40 -07004867 }
4868
Jake Hambye994d462014-02-03 13:10:13 -08004869 /**
4870 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4871 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4872 *
4873 * @param itemID the ID of the item to read
4874 * @return the NV item as a String, or null on error.
4875 */
4876 @Override
4877 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004878 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4880 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004881
4882 final long identity = Binder.clearCallingIdentity();
4883 try {
4884 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004885 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004886 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4887 return value;
4888 } finally {
4889 Binder.restoreCallingIdentity(identity);
4890 }
Jake Hambye994d462014-02-03 13:10:13 -08004891 }
4892
4893 /**
4894 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4895 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4896 *
4897 * @param itemID the ID of the item to read
4898 * @param itemValue the value to write, as a String
4899 * @return true on success; false on any failure
4900 */
4901 @Override
4902 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004903 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4905 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906
4907 final long identity = Binder.clearCallingIdentity();
4908 try {
4909 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4910 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004911 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4913 return success;
4914 } finally {
4915 Binder.restoreCallingIdentity(identity);
4916 }
Jake Hambye994d462014-02-03 13:10:13 -08004917 }
4918
4919 /**
4920 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4921 * Used for device configuration by some CDMA operators.
4922 *
4923 * @param preferredRoamingList byte array containing the new PRL
4924 * @return true on success; false on any failure
4925 */
4926 @Override
4927 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4929 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004930
4931 final long identity = Binder.clearCallingIdentity();
4932 try {
4933 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4934 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4935 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4936 return success;
4937 } finally {
4938 Binder.restoreCallingIdentity(identity);
4939 }
Jake Hambye994d462014-02-03 13:10:13 -08004940 }
4941
4942 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004943 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004944 * Used for device configuration by some CDMA operators.
4945 *
chen xu6dac5ab2018-10-26 17:39:23 -07004946 * @param slotIndex - device slot.
4947 *
Jake Hambye994d462014-02-03 13:10:13 -08004948 * @return true on success; false on any failure
4949 */
4950 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004951 public boolean resetModemConfig(int slotIndex) {
4952 Phone phone = PhoneFactory.getPhone(slotIndex);
4953 if (phone != null) {
4954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4955 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004956
chen xu6dac5ab2018-10-26 17:39:23 -07004957 final long identity = Binder.clearCallingIdentity();
4958 try {
4959 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4960 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4961 return success;
4962 } finally {
4963 Binder.restoreCallingIdentity(identity);
4964 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965 }
chen xu6dac5ab2018-10-26 17:39:23 -07004966 return false;
4967 }
4968
4969 /**
4970 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4971 *
4972 * @param slotIndex - device slot.
4973 *
4974 * @return true on success; false on any failure
4975 */
4976 @Override
4977 public boolean rebootModem(int slotIndex) {
4978 Phone phone = PhoneFactory.getPhone(slotIndex);
4979 if (phone != null) {
4980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4981 mApp, phone.getSubId(), "rebootModem");
4982
4983 final long identity = Binder.clearCallingIdentity();
4984 try {
4985 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4986 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4987 return success;
4988 } finally {
4989 Binder.restoreCallingIdentity(identity);
4990 }
4991 }
4992 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004993 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004994
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004995 public String[] getPcscfAddress(String apnType, String callingPackage,
4996 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004997 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004998 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4999 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005000 return new String[0];
5001 }
5002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003 final long identity = Binder.clearCallingIdentity();
5004 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005005 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006 } finally {
5007 Binder.restoreCallingIdentity(identity);
5008 }
Wink Saville36469e72014-06-11 15:17:00 -07005009 }
5010
Brad Ebinger51f743a2017-01-23 13:50:20 -08005011 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005012 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5013 * {@link #disableIms(int)}.
5014 * @param slotIndex device slot.
5015 */
5016 public void resetIms(int slotIndex) {
5017 enforceModifyPermission();
5018
5019 final long identity = Binder.clearCallingIdentity();
5020 try {
5021 if (mImsResolver == null) {
5022 // may happen if the does not support IMS.
5023 return;
5024 }
5025 mImsResolver.disableIms(slotIndex);
5026 mImsResolver.enableIms(slotIndex);
5027 } finally {
5028 Binder.restoreCallingIdentity(identity);
5029 }
5030 }
5031
5032 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005033 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5034 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005035 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005036 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005037 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038
5039 final long identity = Binder.clearCallingIdentity();
5040 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005041 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005042 // may happen if the device does not support IMS.
5043 return;
5044 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005045 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 } finally {
5047 Binder.restoreCallingIdentity(identity);
5048 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005049 }
5050
5051 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005052 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5053 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005054 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005055 public void disableIms(int slotId) {
5056 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057
5058 final long identity = Binder.clearCallingIdentity();
5059 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005060 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005061 // may happen if the device does not support IMS.
5062 return;
5063 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005064 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005065 } finally {
5066 Binder.restoreCallingIdentity(identity);
5067 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005068 }
5069
5070 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005071 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5072 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005073 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005074 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005075 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005076 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077
5078 final long identity = Binder.clearCallingIdentity();
5079 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005080 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005081 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5082 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005083 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005084 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 } finally {
5086 Binder.restoreCallingIdentity(identity);
5087 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005088 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005089 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005090 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5091 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005092 @Override
5093 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005094 enforceModifyPermission();
5095
5096 final long identity = Binder.clearCallingIdentity();
5097 try {
5098 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005099 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
5103 }
5104
5105 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005106 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005107 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005108 */
5109 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5110 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111
5112 final long identity = Binder.clearCallingIdentity();
5113 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005114 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005115 // may happen if the device does not support IMS.
5116 return null;
5117 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005118 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119 } finally {
5120 Binder.restoreCallingIdentity(identity);
5121 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005122 }
5123
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005124 /**
5125 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005126 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005127 */
5128 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5129 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005130
5131 final long identity = Binder.clearCallingIdentity();
5132 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005133 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005134 // may happen if the device does not support IMS.
5135 return null;
5136 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005137 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138 } finally {
5139 Binder.restoreCallingIdentity(identity);
5140 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005141 }
5142
Brad Ebinger884c07b2018-02-15 16:17:40 -08005143 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005144 * Sets the ImsService Package Name that Telephony will bind to.
5145 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005146 * @param slotIndex the slot ID that the ImsService should bind for.
5147 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005148 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005149 * @param featureTypes An integer array of feature types associated with a packageName.
5150 * @param packageName The name of the package that the current configuration will be replaced
5151 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005152 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005153 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005154 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5155 int[] featureTypes, String packageName) {
5156 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5157 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005158 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5159 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005160 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 final long identity = Binder.clearCallingIdentity();
5163 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005164 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005165 // may happen if the device does not support IMS.
5166 return false;
5167 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005168 Map<Integer, String> featureConfig = new HashMap<>();
5169 for (int featureType : featureTypes) {
5170 featureConfig.put(featureType, packageName);
5171 }
5172 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5173 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005177 }
5178
5179 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005180 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005181 *
5182 * @param slotId The slot that the ImsService is associated with.
5183 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5184 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005185 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005186 * @return the package name of the ImsService configuration.
5187 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005188 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5189 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005190 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005191 TelephonyPermissions
5192 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5193 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5194 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196 final long identity = Binder.clearCallingIdentity();
5197 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005198 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005199 // may happen if the device does not support IMS.
5200 return "";
5201 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005202 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005203 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5204 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005208 }
5209
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005210 /**
5211 * Get the MmTelFeature state associated with the requested subscription id.
5212 * @param subId The subscription that the MmTelFeature is associated with.
5213 * @param callback A callback with an integer containing the
5214 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5215 */
5216 @Override
5217 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5218 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5219 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5220 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5221 "IMS not available on device.");
5222 }
5223 final long token = Binder.clearCallingIdentity();
5224 try {
5225 int slotId = getSlotIndex(subId);
5226 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5227 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5228 + subId + "'");
5229 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5230 }
5231 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5232 try {
5233 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5234 } catch (RemoteException e) {
5235 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5236 + "Ignore");
5237 }
5238 });
5239 } finally {
5240 Binder.restoreCallingIdentity(token);
5241 }
5242 }
5243
Wink Saville36469e72014-06-11 15:17:00 -07005244 public void setImsRegistrationState(boolean registered) {
5245 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246
5247 final long identity = Binder.clearCallingIdentity();
5248 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005249 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 } finally {
5251 Binder.restoreCallingIdentity(identity);
5252 }
Wink Saville36469e72014-06-11 15:17:00 -07005253 }
5254
5255 /**
Stuart Scott54788802015-03-30 13:18:01 -07005256 * Set the network selection mode to automatic.
5257 *
5258 */
5259 @Override
5260 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5262 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263
5264 final long identity = Binder.clearCallingIdentity();
5265 try {
shilufc958392020-01-20 11:36:01 -08005266 if (!isActiveSubscription(subId)) {
5267 return;
5268 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5270 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5271 } finally {
5272 Binder.restoreCallingIdentity(identity);
5273 }
Stuart Scott54788802015-03-30 13:18:01 -07005274 }
5275
Jack Yud10cdd42020-09-28 20:28:01 -07005276 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005277 * Ask the radio to connect to the input network and change selection mode to manual.
5278 *
5279 * @param subId the id of the subscription.
5280 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5281 * the operator to attach to.
5282 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5283 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5284 * normal network selection next time.
5285 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005286 */
5287 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005288 public boolean setNetworkSelectionModeManual(
5289 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5291 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005292
5293 if (!isActiveSubscription(subId)) {
5294 return false;
5295 }
5296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297 final long identity = Binder.clearCallingIdentity();
5298 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005299 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005301 if (DBG) {
5302 log("setNetworkSelectionModeManual: subId: " + subId
5303 + " operator: " + operatorInfo);
5304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5306 } finally {
5307 Binder.restoreCallingIdentity(identity);
5308 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005309 }
shilu84f6e8b2019-12-19 13:58:01 -08005310 /**
5311 * Get the manual network selection
5312 *
5313 * @param subId the id of the subscription.
5314 *
5315 * @return the previously saved user selected PLMN
5316 */
5317 @Override
5318 public String getManualNetworkSelectionPlmn(int subId) {
5319 TelephonyPermissions
5320 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5321 mApp, subId, "getManualNetworkSelectionPlmn");
5322
5323 final long identity = Binder.clearCallingIdentity();
5324 try {
5325 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005326 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005327 }
5328
5329 final Phone phone = getPhone(subId);
5330 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005331 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005332 }
5333 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5334 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5335 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5336 } finally {
5337 Binder.restoreCallingIdentity(identity);
5338 }
5339 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005340
5341 /**
5342 * Scans for available networks.
5343 */
5344 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005345 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5346 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5348 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005349 LocationAccessPolicy.LocationPermissionResult locationResult =
5350 LocationAccessPolicy.checkLocationPermission(mApp,
5351 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5352 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005353 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005354 .setCallingPid(Binder.getCallingPid())
5355 .setCallingUid(Binder.getCallingUid())
5356 .setMethod("getCellNetworkScanResults")
5357 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005358 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5359 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005360 .build());
5361 switch (locationResult) {
5362 case DENIED_HARD:
5363 throw new SecurityException("Not allowed to access scan results -- location");
5364 case DENIED_SOFT:
5365 return null;
5366 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005367
Pengquan Menga1bb6272018-09-06 09:59:22 -07005368 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 try {
5370 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005371 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373 } finally {
5374 Binder.restoreCallingIdentity(identity);
5375 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005376 }
5377
5378 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005379 * Get the call forwarding info, given the call forwarding reason.
5380 */
5381 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005382 public void getCallForwarding(int subId, int callForwardingReason,
5383 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005384 enforceReadPrivilegedPermission("getCallForwarding");
5385 long identity = Binder.clearCallingIdentity();
5386 try {
5387 if (DBG) {
5388 log("getCallForwarding: subId " + subId
5389 + " callForwardingReason" + callForwardingReason);
5390 }
Hall Liu27d24262020-09-18 19:04:59 -07005391
5392 Phone phone = getPhone(subId);
5393 if (phone == null) {
5394 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005395 callback.onError(
5396 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005397 } catch (RemoteException e) {
5398 // ignore
5399 }
5400 return;
5401 }
5402
5403 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5404 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5405 @Override
5406 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5407 try {
5408 callback.onCallForwardingInfoAvailable(info);
5409 } catch (RemoteException e) {
5410 // ignore
5411 }
5412 }
5413
5414 @Override
5415 public void onError(int error) {
5416 try {
5417 callback.onError(error);
5418 } catch (RemoteException e) {
5419 // ignore
5420 }
5421 }
5422 });
5423 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005424 } finally {
5425 Binder.restoreCallingIdentity(identity);
5426 }
5427 }
5428
5429 /**
5430 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5431 * reason, the number to forward, and the timeout before the forwarding is attempted.
5432 */
5433 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005434 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5435 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005436 enforceModifyPermission();
5437 long identity = Binder.clearCallingIdentity();
5438 try {
5439 if (DBG) {
5440 log("setCallForwarding: subId " + subId
5441 + " callForwardingInfo" + callForwardingInfo);
5442 }
Hall Liu27d24262020-09-18 19:04:59 -07005443
5444 Phone phone = getPhone(subId);
5445 if (phone == null) {
5446 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005447 callback.accept(
5448 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005449 } catch (RemoteException e) {
5450 // ignore
5451 }
5452 return;
5453 }
5454
5455 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5456 FunctionalUtils.ignoreRemoteException(callback::accept));
5457
5458 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005459 } finally {
5460 Binder.restoreCallingIdentity(identity);
5461 }
5462 }
5463
5464 /**
Hall Liu27d24262020-09-18 19:04:59 -07005465 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005466 */
5467 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005468 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005469 enforceReadPrivilegedPermission("getCallForwarding");
5470 long identity = Binder.clearCallingIdentity();
5471 try {
Hall Liu27d24262020-09-18 19:04:59 -07005472
5473 Phone phone = getPhone(subId);
5474 if (phone == null) {
5475 try {
5476 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5477 } catch (RemoteException e) {
5478 // ignore
5479 }
5480 return;
5481 }
5482
5483 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5484
Shuo Qian4a594052020-01-23 11:59:30 -08005485 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005486 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005487 } finally {
5488 Binder.restoreCallingIdentity(identity);
5489 }
5490 }
5491
5492 /**
Hall Liu27d24262020-09-18 19:04:59 -07005493 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005494 */
5495 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005496 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005497 enforceModifyPermission();
5498 long identity = Binder.clearCallingIdentity();
5499 try {
Hall Liu27d24262020-09-18 19:04:59 -07005500 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5501
5502 Phone phone = getPhone(subId);
5503 if (phone == null) {
5504 try {
5505 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5506 } catch (RemoteException e) {
5507 // ignore
5508 }
5509 return;
5510 }
5511
5512 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5513 FunctionalUtils.ignoreRemoteException(callback::accept));
5514
5515 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005516 } finally {
5517 Binder.restoreCallingIdentity(identity);
5518 }
5519 }
5520
5521 /**
yinxub1bed742017-04-17 11:45:04 -07005522 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005523 *
yinxub1bed742017-04-17 11:45:04 -07005524 * @param subId id of the subscription
5525 * @param request contains the radio access networks with bands/channels to scan
5526 * @param messenger callback messenger for scan results or errors
5527 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005528 * @return the id of the requested scan which can be used to stop the scan.
5529 */
5530 @Override
5531 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005532 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5534 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005535 LocationAccessPolicy.LocationPermissionResult locationResult =
5536 LocationAccessPolicy.checkLocationPermission(mApp,
5537 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5538 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005539 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005540 .setCallingPid(Binder.getCallingPid())
5541 .setCallingUid(Binder.getCallingUid())
5542 .setMethod("requestNetworkScan")
5543 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005544 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5545 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005546 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005547 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005548 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5549 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005550 if (e != null) {
5551 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5552 throw e;
5553 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005554 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005555 return TelephonyScanManager.INVALID_SCAN_ID;
5556 }
5557 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 }
Hall Liu912dfd32019-04-25 14:02:26 -07005559 int callingUid = Binder.getCallingUid();
5560 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005561 final long identity = Binder.clearCallingIdentity();
5562 try {
5563 return mNetworkScanRequestTracker.startNetworkScan(
5564 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005565 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005566 } finally {
5567 Binder.restoreCallingIdentity(identity);
5568 }
yinxu504e1392017-04-12 16:03:22 -07005569 }
5570
Hall Liub2ac8ef2019-02-28 15:56:23 -08005571 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005572 NetworkScanRequest request, int subId, String callingPackage) {
5573 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005574 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5575 boolean hasNetworkScanPermission =
5576 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5577 == PERMISSION_GRANTED;
5578
5579 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5580 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5581 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005582 }
5583
5584 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5585 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005586 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5587 return new SecurityException("Specific channels must not be"
5588 + " scanned without location access.");
5589 }
5590 }
5591 }
5592
Hall Liub2ac8ef2019-02-28 15:56:23 -08005593 return null;
5594 }
5595
yinxu504e1392017-04-12 16:03:22 -07005596 /**
5597 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005598 *
5599 * @param subId id of the subscription
5600 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005601 */
5602 @Override
5603 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5605 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606
Hall Liu912dfd32019-04-25 14:02:26 -07005607 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 final long identity = Binder.clearCallingIdentity();
5609 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005610 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 } finally {
5612 Binder.restoreCallingIdentity(identity);
5613 }
yinxu504e1392017-04-12 16:03:22 -07005614 }
5615
5616 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005617 * Get the calculated preferred network type.
5618 * Used for debugging incorrect network type.
5619 *
5620 * @return the preferred network type, defined in RILConstants.java.
5621 */
5622 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005623 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005624 final Phone defaultPhone = getDefaultPhone();
5625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005626 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005627 return RILConstants.PREFERRED_NETWORK_MODE;
5628 }
5629
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630 final long identity = Binder.clearCallingIdentity();
5631 try {
5632 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005633 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005634 } finally {
5635 Binder.restoreCallingIdentity(identity);
5636 }
Junda Liu84d15a22014-07-02 11:21:04 -07005637 }
5638
5639 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005640 * Get the preferred network type.
5641 * Used for device configuration by some CDMA operators.
5642 *
5643 * @return the preferred network type, defined in RILConstants.java.
5644 */
5645 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005646 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005647 TelephonyPermissions
5648 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5649 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005650
5651 final long identity = Binder.clearCallingIdentity();
5652 try {
5653 if (DBG) log("getPreferredNetworkType");
5654 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5655 int networkType = (result != null ? result[0] : -1);
5656 if (DBG) log("getPreferredNetworkType: " + networkType);
5657 return networkType;
5658 } finally {
5659 Binder.restoreCallingIdentity(identity);
5660 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005661 }
5662
5663 /**
5664 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005665 *
5666 * @param networkType the preferred network type, defined in RILConstants.java.
5667 * @return true on success; false on any failure.
5668 */
5669 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005670 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5672 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673
5674 final long identity = Binder.clearCallingIdentity();
5675 try {
calvinpan8ed33732020-03-12 14:17:55 +08005676 Boolean success = (Boolean) sendRequest(
5677 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005678
5679 if (success) {
5680 Settings.Global.putInt(mApp.getContentResolver(),
5681 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5682 }
calvinpan8ed33732020-03-12 14:17:55 +08005683 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5684 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005685 } finally {
5686 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005687 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005688 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005689
5690 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005691 * Get the allowed network types that store in the telephony provider.
5692 *
5693 * @param subId the id of the subscription.
5694 * @return allowedNetworkTypes the allowed network types.
5695 */
5696 @Override
5697 public long getAllowedNetworkTypes(int subId) {
5698 TelephonyPermissions
5699 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5700 mApp, subId, "getAllowedNetworkTypes");
5701
5702 final long identity = Binder.clearCallingIdentity();
5703 try {
5704 return SubscriptionManager.getLongSubscriptionProperty(
5705 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5706 } finally {
5707 Binder.restoreCallingIdentity(identity);
5708 }
5709 }
5710
5711 /**
5712 * Set the allowed network types.
5713 *
5714 * @param subId the id of the subscription.
5715 * @param allowedNetworkTypes the allowed network types.
5716 * @return true on success; false on any failure.
5717 */
5718 @Override
5719 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5721 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005722
calvinpan8ed33732020-03-12 14:17:55 +08005723 SubscriptionManager.setSubscriptionProperty(subId,
5724 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5725 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005726
calvinpan8ed33732020-03-12 14:17:55 +08005727 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5728 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5729 RILConstants.PREFERRED_NETWORK_MODE);
5730 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005731 }
5732
5733 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005734 * Get the allowed network types for certain reason.
5735 *
5736 * @param subId the id of the subscription.
5737 * @param reason the reason the allowed network type change is taking place
5738 * @return the allowed network types.
5739 */
5740 @Override
5741 public long getAllowedNetworkTypesForReason(int subId,
5742 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5743 TelephonyPermissions
5744 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5745 mApp, subId, "getAllowedNetworkTypesForReason");
5746 final long identity = Binder.clearCallingIdentity();
5747 try {
5748 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
5752 }
5753
5754 /**
5755 * Get the effective allowed network types on the device.
5756 * This API will return an intersection of allowed network types for all reasons,
5757 * including the configuration done through setAllowedNetworkTypes
5758 *
5759 * @param subId the id of the subscription.
5760 * @return the allowed network types
5761 */
5762 @Override
5763 public long getEffectiveAllowedNetworkTypes(int subId) {
5764 TelephonyPermissions
5765 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5766 mApp, subId, "getEffectiveAllowedNetworkTypes");
5767 final long identity = Binder.clearCallingIdentity();
5768 try {
5769 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
5773 }
5774
5775 /**
5776 * Set the allowed network types of the device and
5777 * provide the reason triggering the allowed network change.
5778 *
5779 * @param subId the id of the subscription.
5780 * @param reason the reason the allowed network type change is taking place
5781 * @param allowedNetworkTypes the allowed network types.
5782 * @return true on success; false on any failure.
5783 */
5784 @Override
5785 public boolean setAllowedNetworkTypesForReason(int subId,
5786 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5788 mApp, subId, "setAllowedNetworkTypesForReason");
5789 final long identity = Binder.clearCallingIdentity();
5790 try {
5791 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5792 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5793 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5794 RILConstants.PREFERRED_NETWORK_MODE);
5795 return setPreferredNetworkType(subId, preferredNetworkMode);
5796 } finally {
5797 Binder.restoreCallingIdentity(identity);
5798 }
5799 }
5800
5801 /**
Miaoa84611c2019-03-15 09:21:10 +08005802 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005803 *
Miaoa84611c2019-03-15 09:21:10 +08005804 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005805 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005806 * @hide
5807 */
5808 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005809 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005810 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005811 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005812 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813 try {
Miaoa84611c2019-03-15 09:21:10 +08005814 if (phone != null) {
5815 return phone.hasMatchedTetherApnSetting();
5816 } else {
5817 return false;
5818 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819 } finally {
5820 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005821 }
Junda Liu475951f2014-11-07 16:45:03 -08005822 }
5823
5824 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005825 * Enable or disable always reporting signal strength changes from radio.
5826 *
5827 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5828 */
5829 @Override
5830 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5831 enforceModifyPermission();
5832 enforceSystemCaller();
5833
5834 final long identity = Binder.clearCallingIdentity();
5835 final Phone phone = getPhone(subId);
5836 try {
5837 if (phone != null) {
5838 if (DBG) {
5839 log("setAlwaysReportSignalStrength: subId=" + subId
5840 + " isEnable=" + isEnable);
5841 }
5842 phone.setAlwaysReportSignalStrength(isEnable);
5843 } else {
5844 loge("setAlwaysReportSignalStrength: no phone found for subId="
5845 + subId);
5846 }
5847 } finally {
5848 Binder.restoreCallingIdentity(identity);
5849 }
5850 }
5851
5852 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005853 * Get the user enabled state of Mobile Data.
5854 *
5855 * TODO: remove and use isUserDataEnabled.
5856 * This can't be removed now because some vendor codes
5857 * calls through ITelephony directly while they should
5858 * use TelephonyManager.
5859 *
5860 * @return true on enabled
5861 */
5862 @Override
5863 public boolean getDataEnabled(int subId) {
5864 return isUserDataEnabled(subId);
5865 }
5866
5867 /**
5868 * Get whether mobile data is enabled per user setting.
5869 *
5870 * There are other factors deciding whether mobile data is actually enabled, but they are
5871 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005872 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005873 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005874 *
5875 * @return {@code true} if data is enabled else {@code false}
5876 */
5877 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005878 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005879 try {
5880 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5881 null);
5882 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5884 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005885 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005886
5887 final long identity = Binder.clearCallingIdentity();
5888 try {
5889 int phoneId = mSubscriptionController.getPhoneId(subId);
5890 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5891 Phone phone = PhoneFactory.getPhone(phoneId);
5892 if (phone != null) {
5893 boolean retVal = phone.isUserDataEnabled();
5894 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5895 return retVal;
5896 } else {
5897 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5898 return false;
5899 }
5900 } finally {
5901 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005902 }
5903 }
5904
5905 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005906 * Checks if the device is capable of mobile data by considering whether whether the
5907 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5908 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005909 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005910 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005911 */
5912 @Override
5913 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005914 try {
5915 try {
5916 mApp.enforceCallingOrSelfPermission(
5917 android.Manifest.permission.ACCESS_NETWORK_STATE,
5918 null);
5919 } catch (Exception e) {
5920 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
5921 "isDataEnabled");
5922 }
5923 } catch (Exception e) {
5924 enforceReadPrivilegedPermission("isDataEnabled");
5925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926
5927 final long identity = Binder.clearCallingIdentity();
5928 try {
5929 int phoneId = mSubscriptionController.getPhoneId(subId);
5930 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5931 Phone phone = PhoneFactory.getPhone(phoneId);
5932 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005933 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5935 return retVal;
5936 } else {
5937 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5938 return false;
5939 }
5940 } finally {
5941 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005942 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005943 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005944
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005945 /**
5946 * Check if data is enabled for a specific reason
5947 * @param subId Subscription index
5948 * @param reason the reason the data enable change is taking place
5949 * @return {@code true} if the overall data is enabled; {@code false} if not.
5950 */
5951 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005952 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005953 @TelephonyManager.DataEnabledReason int reason) {
5954 try {
5955 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5956 null);
5957 } catch (Exception e) {
5958 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005959 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005960 }
5961
5962
5963 final long identity = Binder.clearCallingIdentity();
5964 try {
5965 int phoneId = mSubscriptionController.getPhoneId(subId);
5966 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005967 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005968 + " reason=" + reason);
5969 }
5970 Phone phone = PhoneFactory.getPhone(phoneId);
5971 if (phone != null) {
5972 boolean retVal;
5973 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
5974 retVal = phone.isUserDataEnabled();
5975 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005976 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005977 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005978 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005979 return retVal;
5980 } else {
5981 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005982 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005983 + subId + " retVal=false");
5984 }
5985 return false;
5986 }
5987 } finally {
5988 Binder.restoreCallingIdentity(identity);
5989 }
5990 }
5991
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005992 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005993 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07005994 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5995 // Skip the check if it's one of these special uids
5996 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5997 }
5998
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005999 //load access rules from carrier configs, and check those as well: b/139133814
6000 SubscriptionController subController = SubscriptionController.getInstance();
6001 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6002 || subController == null) return privilegeFromSim;
6003
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006004 PackageManager pkgMgr = phone.getContext().getPackageManager();
6005 String[] packages = pkgMgr.getPackagesForUid(uid);
6006
6007 final long identity = Binder.clearCallingIdentity();
6008 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006009 int subId = phone.getSubId();
6010 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6011 // A test override is in place for the privileges for this subId, so don't try to
6012 // read the subscription privileges.
6013 return privilegeFromSim;
6014 }
6015 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006016 SubscriptionManager subManager = (SubscriptionManager)
6017 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6018 for (String pkg : packages) {
6019 if (subManager.canManageSubscription(subInfo, pkg)) {
6020 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6021 }
6022 }
6023 return privilegeFromSim;
6024 } finally {
6025 Binder.restoreCallingIdentity(identity);
6026 }
6027 }
6028
6029 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6030 String pkgName) {
6031 //load access rules from carrier configs, and check those as well: b/139133814
6032 SubscriptionController subController = SubscriptionController.getInstance();
6033 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6034 || subController == null) return privilegeFromSim;
6035
6036 final long identity = Binder.clearCallingIdentity();
6037 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006038 int subId = phone.getSubId();
6039 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6040 // A test override is in place for the privileges for this subId, so don't try to
6041 // read the subscription privileges.
6042 return privilegeFromSim;
6043 }
6044 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006045 SubscriptionManager subManager = (SubscriptionManager)
6046 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6047 return subManager.canManageSubscription(subInfo, pkgName)
6048 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6049 } finally {
6050 Binder.restoreCallingIdentity(identity);
6051 }
6052 }
6053
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006054 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006055 public int getCarrierPrivilegeStatus(int subId) {
6056 final Phone phone = getPhone(subId);
6057 if (phone == null) {
6058 loge("getCarrierPrivilegeStatus: Invalid subId");
6059 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6060 }
6061 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006062 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006063 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006064 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6065 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006066
6067 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6068 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006069 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006070 }
Junda Liu29340342014-07-10 15:23:27 -07006071
6072 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006073 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006074 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006075 final Phone phone = getPhone(subId);
6076 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006077 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006078 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6079 }
6080 UiccProfile profile =
6081 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6082 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006083 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006084 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6085 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006086 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006087 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006088 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006089 }
6090
6091 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006092 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6093 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006094 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006095 }
6096
6097 int phoneId = SubscriptionManager.getPhoneId(subId);
6098 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006099 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006100 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006101 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6102 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006103 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6104 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6105 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006106 }
6107
6108 @Override
6109 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006110 if (TextUtils.isEmpty(pkgName))
6111 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006112 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6113 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6114 UiccCard card = UiccController.getInstance().getUiccCard(i);
6115 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006116 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006117 continue;
6118 }
6119
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006120 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6121 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6122 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006123 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6124 break;
6125 }
6126 }
6127
6128 return result;
Junda Liu29340342014-07-10 15:23:27 -07006129 }
Derek Tan89e89d42014-07-08 17:00:10 -07006130
6131 @Override
Junda Liue64de782015-04-16 17:19:16 -07006132 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6133 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6134 loge("phoneId " + phoneId + " is not valid.");
6135 return null;
6136 }
6137 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006138 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006139 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006140 return null ;
6141 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006142 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006143 }
6144
Amith Yamasani6e118872016-02-19 12:53:51 -08006145 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006146 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006147 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006148 List<String> privilegedPackages = new ArrayList<>();
6149 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006150 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6151 // has UICC in that slot.
6152 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006153 if (card.hasCarrierPrivilegeRules()) {
6154 if (packages == null) {
6155 // Only check packages in user 0 for now
6156 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006157 PackageManager.MATCH_DISABLED_COMPONENTS
6158 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006159 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006160 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006161 }
6162 for (int p = packages.size() - 1; p >= 0; p--) {
6163 PackageInfo pkgInfo = packages.get(p);
6164 if (pkgInfo != null && pkgInfo.packageName != null
6165 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006166 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006167 privilegedPackages.add(pkgInfo.packageName);
6168 }
6169 }
6170 }
6171 }
6172 return privilegedPackages;
6173 }
6174
chen xuf7e9fe82019-05-09 19:31:02 -07006175 @Override
6176 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006177 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6178
6179 final long identity = Binder.clearCallingIdentity();
6180
chen xuf7e9fe82019-05-09 19:31:02 -07006181 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006182 try {
6183 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6184 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6185 }
6186 } finally {
6187 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006188 }
6189 return privilegedPackages;
6190 }
6191
Wink Savilleb564aae2014-10-23 10:18:09 -07006192 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006193 final Phone phone = getPhone(subId);
6194 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006195 if (card == null) {
6196 loge("getIccId: No UICC");
6197 return null;
6198 }
6199 String iccId = card.getIccId();
6200 if (TextUtils.isEmpty(iccId)) {
6201 loge("getIccId: ICC ID is null or empty.");
6202 return null;
6203 }
6204 return iccId;
6205 }
6206
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006207 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006208 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6209 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006210 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006211 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006213 final long identity = Binder.clearCallingIdentity();
6214 try {
6215 final String iccId = getIccId(subId);
6216 final Phone phone = getPhone(subId);
6217 if (phone == null) {
6218 return false;
6219 }
6220 final String subscriberId = phone.getSubscriberId();
6221
6222 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006223 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 + subscriberId + " to " + number);
6225 }
6226
6227 if (TextUtils.isEmpty(iccId)) {
6228 return false;
6229 }
6230
6231 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6232
6233 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6234 if (alphaTag == null) {
6235 editor.remove(alphaTagPrefKey);
6236 } else {
6237 editor.putString(alphaTagPrefKey, alphaTag);
6238 }
6239
6240 // Record both the line number and IMSI for this ICCID, since we need to
6241 // track all merged IMSIs based on line number
6242 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6243 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6244 if (number == null) {
6245 editor.remove(numberPrefKey);
6246 editor.remove(subscriberPrefKey);
6247 } else {
6248 editor.putString(numberPrefKey, number);
6249 editor.putString(subscriberPrefKey, subscriberId);
6250 }
6251
6252 editor.commit();
6253 return true;
6254 } finally {
6255 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006256 }
Derek Tan7226c842014-07-02 17:42:23 -07006257 }
6258
6259 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006260 public String getLine1NumberForDisplay(int subId, String callingPackage,
6261 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006262 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006264 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006265 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006266 return null;
6267 }
Derek Tan97ebb422014-09-05 16:55:38 -07006268
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006269 final long identity = Binder.clearCallingIdentity();
6270 try {
6271 String iccId = getIccId(subId);
6272 if (iccId != null) {
6273 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6274 if (DBG_MERGE) {
6275 log("getLine1NumberForDisplay returning "
6276 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6277 }
6278 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6281 return null;
6282 } finally {
6283 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006284 }
Derek Tan7226c842014-07-02 17:42:23 -07006285 }
6286
6287 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006288 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6289 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006291 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006292 return null;
6293 }
Derek Tan97ebb422014-09-05 16:55:38 -07006294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006295 final long identity = Binder.clearCallingIdentity();
6296 try {
6297 String iccId = getIccId(subId);
6298 if (iccId != null) {
6299 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6300 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6301 }
6302 return null;
6303 } finally {
6304 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006305 }
Derek Tan7226c842014-07-02 17:42:23 -07006306 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006307
6308 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006309 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6310 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006311 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6312 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006314 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006315 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006316 return null;
6317 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006318
Jordan Liub49b04b2019-05-06 14:45:15 -07006319 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6320 // the process, where TelephonyManager was instantiated.
6321 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006322 final long identity = Binder.clearCallingIdentity();
6323 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006324 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006325 final TelephonyManager tele = TelephonyManager.from(context);
6326 final SubscriptionManager sub = SubscriptionManager.from(context);
6327
6328 // Figure out what subscribers are currently active
6329 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006330
Jordan Liub49b04b2019-05-06 14:45:15 -07006331 // Only consider subs which match the current subId
6332 // This logic can be simplified. See b/131189269 for progress.
6333 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006334 activeSubscriberIds.add(tele.getSubscriberId(subId));
6335 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006336
6337 // First pass, find a number override for an active subscriber
6338 String mergeNumber = null;
6339 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6340 for (String key : prefs.keySet()) {
6341 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6342 final String subscriberId = (String) prefs.get(key);
6343 if (activeSubscriberIds.contains(subscriberId)) {
6344 final String iccId = key.substring(
6345 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6346 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6347 mergeNumber = (String) prefs.get(numberKey);
6348 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006349 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006350 + " for active subscriber " + subscriberId);
6351 }
6352 if (!TextUtils.isEmpty(mergeNumber)) {
6353 break;
6354 }
6355 }
6356 }
6357 }
6358
6359 // Shortcut when no active merged subscribers
6360 if (TextUtils.isEmpty(mergeNumber)) {
6361 return null;
6362 }
6363
6364 // Second pass, find all subscribers under that line override
6365 final ArraySet<String> result = new ArraySet<>();
6366 for (String key : prefs.keySet()) {
6367 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6368 final String number = (String) prefs.get(key);
6369 if (mergeNumber.equals(number)) {
6370 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6371 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6372 final String subscriberId = (String) prefs.get(subscriberKey);
6373 if (!TextUtils.isEmpty(subscriberId)) {
6374 result.add(subscriberId);
6375 }
6376 }
6377 }
6378 }
6379
6380 final String[] resultArray = result.toArray(new String[result.size()]);
6381 Arrays.sort(resultArray);
6382 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006383 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6385 }
6386 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006387 } finally {
6388 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006389 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006390 }
6391
6392 @Override
zoey chen38003472019-12-13 17:16:31 +08006393 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6394 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006395
6396 final long identity = Binder.clearCallingIdentity();
6397 try {
6398 final TelephonyManager telephonyManager = mApp.getSystemService(
6399 TelephonyManager.class);
6400 String subscriberId = telephonyManager.getSubscriberId(subId);
6401 if (subscriberId == null) {
6402 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006403 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006404 + subId);
6405 }
6406 return null;
6407 }
6408
6409 final SubscriptionInfo info = SubscriptionController.getInstance()
6410 .getSubscriptionInfo(subId);
6411 final ParcelUuid groupUuid = info.getGroupUuid();
6412 // If it doesn't belong to any group, return just subscriberId of itself.
6413 if (groupUuid == null) {
6414 return new String[]{subscriberId};
6415 }
6416
6417 // Get all subscriberIds from the group.
6418 final List<String> mergedSubscriberIds = new ArrayList<>();
6419 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006420 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006421 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006422 for (SubscriptionInfo subInfo : groupInfos) {
6423 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6424 if (subscriberId != null) {
6425 mergedSubscriberIds.add(subscriberId);
6426 }
6427 }
6428
6429 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6430 } finally {
6431 Binder.restoreCallingIdentity(identity);
6432
6433 }
6434 }
6435
6436 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006437 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006438 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006439 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440
6441 final long identity = Binder.clearCallingIdentity();
6442 try {
6443 final Phone phone = getPhone(subId);
6444 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6445 } finally {
6446 Binder.restoreCallingIdentity(identity);
6447 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006448 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006449
6450 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006451 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006452 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6453 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006454 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6455 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006456
6457 final long identity = Binder.clearCallingIdentity();
6458 try {
6459 final Phone phone = getPhone(subId);
6460 if (phone == null) {
6461 return false;
6462 }
6463 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6464 cdmaNonRoamingList);
6465 } finally {
6466 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006467 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006468 }
6469
6470 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006471 @Deprecated
6472 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6473 enforceModifyPermission();
6474
6475 int returnValue = 0;
6476 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006477 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006478 if(result.exception == null) {
6479 if (result.result != null) {
6480 byte[] responseData = (byte[])(result.result);
6481 if(responseData.length > oemResp.length) {
6482 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6483 responseData.length + "bytes. Buffer Size is " +
6484 oemResp.length + "bytes.");
6485 }
6486 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6487 returnValue = responseData.length;
6488 }
6489 } else {
6490 CommandException ex = (CommandException) result.exception;
6491 returnValue = ex.getCommandError().ordinal();
6492 if(returnValue > 0) returnValue *= -1;
6493 }
6494 } catch (RuntimeException e) {
6495 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6496 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6497 if(returnValue > 0) returnValue *= -1;
6498 }
6499
6500 return returnValue;
6501 }
6502
6503 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006504 public void setRadioCapability(RadioAccessFamily[] rafs) {
6505 try {
6506 ProxyController.getInstance().setRadioCapability(rafs);
6507 } catch (RuntimeException e) {
6508 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6509 }
6510 }
6511
6512 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006513 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006514 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006515 try {
6516 TelephonyPermissions
6517 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6518 mApp, phone.getSubId(), "getRadioAccessFamily");
6519 } catch (SecurityException e) {
6520 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6521 throw e;
6522 }
chen xub97461a2018-10-26 14:17:57 -07006523 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006524 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006525 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006526 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006527 final long identity = Binder.clearCallingIdentity();
6528 try {
chen xub97461a2018-10-26 14:17:57 -07006529 TelephonyPermissions
6530 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6531 mApp, phone.getSubId(), "getRadioAccessFamily");
6532 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006533 } finally {
6534 Binder.restoreCallingIdentity(identity);
6535 }
chen xub97461a2018-10-26 14:17:57 -07006536 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006537 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006538
6539 @Override
6540 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006541 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006542 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006543
6544 final long identity = Binder.clearCallingIdentity();
6545 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006546 ImsManager.getInstance(defaultPhone.getContext(),
6547 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006548 } finally {
6549 Binder.restoreCallingIdentity(identity);
6550 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006551 }
6552
6553 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006554 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006555 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6557 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006558 return false;
6559 }
Svet Ganovb320e182015-04-16 12:30:10 -07006560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006561 final long identity = Binder.clearCallingIdentity();
6562 try {
6563 // Check the user preference and the system-level IMS setting. Even if the user has
6564 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6565 // In the long run, we may instead need to check if there exists a connection service
6566 // which can support video calling.
6567 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006568 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006569 return imsManager.isVtEnabledByPlatform()
6570 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6571 && imsManager.isVtEnabledByUser();
6572 } finally {
6573 Binder.restoreCallingIdentity(identity);
6574 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006575 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006576
Andrew Leea1239f22015-03-02 17:44:07 -08006577 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006578 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6579 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006581 mApp, subId, callingPackage, callingFeatureId,
6582 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583 return false;
6584 }
6585
6586 final long identity = Binder.clearCallingIdentity();
6587 try {
6588 CarrierConfigManager configManager =
6589 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006590 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006591 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6592 } finally {
6593 Binder.restoreCallingIdentity(identity);
6594 }
Andrew Leea1239f22015-03-02 17:44:07 -08006595 }
6596
6597 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006598 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006600 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601 return false;
6602 }
6603
6604 final long identity = Binder.clearCallingIdentity();
6605 try {
6606 CarrierConfigManager configManager =
6607 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006608 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6610 } finally {
6611 Binder.restoreCallingIdentity(identity);
6612 }
Andrew Leea1239f22015-03-02 17:44:07 -08006613 }
6614
Andrew Lee9431b832015-03-09 18:46:45 -07006615 @Override
6616 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006617 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006618 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006619 }
6620
6621 @Override
6622 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006623 final long identity = Binder.clearCallingIdentity();
6624 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006625 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006626 } finally {
6627 Binder.restoreCallingIdentity(identity);
6628 }
Andrew Lee9431b832015-03-09 18:46:45 -07006629 }
6630
Hall Liuf6668912018-10-31 17:05:23 -07006631 /**
6632 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6633 * support for the feature and device firmware support.
6634 *
6635 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6636 */
6637 @Override
6638 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006640 final Phone phone = getPhone(subscriptionId);
6641 if (phone == null) {
6642 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6643 return false;
6644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006646 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006647 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6648 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006649 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650 return isCarrierSupported && isDeviceSupported;
6651 } finally {
6652 Binder.restoreCallingIdentity(identity);
6653 }
Hall Liu98187582018-01-22 19:15:32 -08006654 }
6655
Hall Liuf6668912018-10-31 17:05:23 -07006656 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006657 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6658 * RTT setting, will return true if the device and carrier both support RTT.
6659 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006660 */
6661 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006662 final long identity = Binder.clearCallingIdentity();
6663 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006664 boolean isRttSupported = isRttSupported(subscriptionId);
6665 boolean isUserRttSettingOn = Settings.Secure.getInt(
6666 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6667 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6668 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6669 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006670 } finally {
6671 Binder.restoreCallingIdentity(identity);
6672 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006673 }
6674
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006675 @Deprecated
6676 @Override
6677 public String getDeviceId(String callingPackage) {
6678 return getDeviceIdWithFeature(callingPackage, null);
6679 }
6680
Sanket Padawe7310cc72015-01-14 09:53:20 -08006681 /**
6682 * Returns the unique device ID of phone, for example, the IMEI for
6683 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6684 *
6685 * <p>Requires Permission:
6686 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6687 */
6688 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006689 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006690 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006691 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006692 return null;
6693 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006694 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006695 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006696 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006697 return null;
6698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699
6700 final long identity = Binder.clearCallingIdentity();
6701 try {
6702 return phone.getDeviceId();
6703 } finally {
6704 Binder.restoreCallingIdentity(identity);
6705 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006706 }
6707
Ping Sunc67b7c22016-03-02 19:16:45 +08006708 /**
6709 * {@hide}
6710 * Returns the IMS Registration Status on a particular subid
6711 *
6712 * @param subId
6713 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006714 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006715 Phone phone = getPhone(subId);
6716 if (phone != null) {
6717 return phone.isImsRegistered();
6718 } else {
6719 return false;
6720 }
6721 }
6722
Santos Cordon7a1885b2015-02-03 11:15:19 -08006723 @Override
6724 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725 final long identity = Binder.clearCallingIdentity();
6726 try {
6727 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6728 } finally {
6729 Binder.restoreCallingIdentity(identity);
6730 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006731 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006732
Tyler Gunnf70ed162019-04-03 15:28:53 -07006733 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006734 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006735 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006737 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006738 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6739 }
6740 final long identity = Binder.clearCallingIdentity();
6741 try {
6742 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6743 } finally {
6744 Binder.restoreCallingIdentity(identity);
6745 }
6746 }
6747
6748 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006749 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006750 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6751 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006752 final long identity = Binder.clearCallingIdentity();
6753 try {
6754 Phone phone = getPhone(subscriptionId);
6755 if (phone == null) {
6756 return null;
6757 }
6758 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6759 } finally {
6760 Binder.restoreCallingIdentity(identity);
6761 }
6762 }
6763
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006764 /**
6765 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006766 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006767 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006768 final long identity = Binder.clearCallingIdentity();
6769 try {
6770 Phone phone = getPhone(subId);
6771 if (phone != null) {
6772 return phone.isWifiCallingEnabled();
6773 } else {
6774 return false;
6775 }
6776 } finally {
6777 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006778 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006779 }
6780
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006781 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006782 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006783 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006784 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006785 final long identity = Binder.clearCallingIdentity();
6786 try {
6787 Phone phone = getPhone(subId);
6788 if (phone != null) {
6789 return phone.isVideoEnabled();
6790 } else {
6791 return false;
6792 }
6793 } finally {
6794 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006795 }
6796 }
6797
6798 /**
6799 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6800 * defined in {@link ImsRegistrationImplBase}.
6801 */
6802 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803 final long identity = Binder.clearCallingIdentity();
6804 try {
6805 Phone phone = getPhone(subId);
6806 if (phone != null) {
6807 return phone.getImsRegistrationTech();
6808 } else {
6809 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6810 }
6811 } finally {
6812 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006813 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006814 }
6815
Stuart Scott8eef64f2015-04-08 15:13:54 -07006816 @Override
6817 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006818 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006819 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6820 return;
6821 }
6822
Svet Ganovcc087f82015-05-12 20:35:54 -07006823 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006824
Svet Ganovcc087f82015-05-12 20:35:54 -07006825 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006826 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6827 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006828 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006829 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006830 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006831 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006832 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6833 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006834 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006835 // There has been issues when Sms raw table somehow stores orphan
6836 // fragments. They lead to garbled message when new fragments come
6837 // in and combined with those stale ones. In case this happens again,
6838 // user can reset all network settings which will clean up this table.
6839 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006840 // Clean up IMS settings as well here.
6841 int slotId = getSlotIndex(subId);
6842 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6843 ImsManager.getInstance(mApp, slotId).factoryReset();
6844 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006845
6846 // Erase modem config if erase modem on network setting is enabled.
6847 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6848 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6849 if (configValue != null && Boolean.parseBoolean(configValue)) {
6850 sendEraseModemConfig(getDefaultPhone());
6851 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006852 } finally {
6853 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006854 }
6855 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006856
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006857 private void cleanUpSmsRawTable(Context context) {
6858 ContentResolver resolver = context.getContentResolver();
6859 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6860 resolver.delete(uri, null, null);
6861 }
6862
Narayan Kamath1c496c22015-04-16 14:40:19 +01006863 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006864 public String getSimLocaleForSubscriber(int subId) {
6865 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6866 final Phone phone = getPhone(subId);
6867 if (phone == null) {
6868 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006869 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871 final long identity = Binder.clearCallingIdentity();
6872 try {
chen xu5d3637b2019-01-21 23:31:38 -08006873 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006874 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006875 if (info == null) {
6876 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6877 return null;
6878 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006879 // Try and fetch the locale from the carrier properties or from the SIM language
6880 // preferences (EF-PL and EF-LI)...
6881 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006882 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006883 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6884 if (localeFromDefaultSim != null) {
6885 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6886 if (DBG) log("Using locale from subId: " + subId + " locale: "
6887 + localeFromDefaultSim);
6888 return localeFromDefaultSim.toLanguageTag();
6889 } else {
6890 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891 }
6892 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006894 // The SIM language preferences only store a language (e.g. fr = French), not an
6895 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6896 // the SIM and carrier preferences does not include a country we add the country
6897 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006898 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006899 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006900 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006901 return mccLocale.toLanguageTag();
6902 }
6903
6904 if (DBG) log("No locale found - returning null");
6905 return null;
6906 } finally {
6907 Binder.restoreCallingIdentity(identity);
6908 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006909 }
6910
6911 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006912 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006913 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006914 }
6915
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006916 /**
6917 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6918 */
6919 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006920 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006921 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006922 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006923
Chenjie Yu1ba97252018-01-11 18:16:20 -08006924 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07006925 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006926
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006927 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006928 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6929 * representing the state of the modem.
6930 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006931 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6932 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006933 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006934 */
6935 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006936 public void requestModemActivityInfo(ResultReceiver result) {
6937 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006938 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939
6940 final long identity = Binder.clearCallingIdentity();
6941 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08006942 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006943 } finally {
6944 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006945 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006946 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006947
Siddharth Rayb8114062018-06-17 15:02:38 -07006948 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6949 // less than total activity duration.
6950 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6951 if (info == null) {
6952 return false;
6953 }
6954 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07006955 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
6956 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
6957
Siddharth Rayb8114062018-06-17 15:02:38 -07006958 return (info.isValid()
6959 && (info.getSleepTimeMillis() <= activityDurationMs)
6960 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006961 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006962 && (totalTxTimeMs <= activityDurationMs));
6963 }
6964
Jack Yu85bd38a2015-11-09 11:34:32 -08006965 /**
6966 * {@hide}
6967 * Returns the service state information on specified subscription.
6968 */
6969 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006970 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6971 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006973 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006974 return null;
6975 }
6976
Hall Liuf19c44f2018-11-27 14:38:17 -08006977 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6978 LocationAccessPolicy.checkLocationPermission(mApp,
6979 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6980 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006981 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006982 .setCallingPid(Binder.getCallingPid())
6983 .setCallingUid(Binder.getCallingUid())
6984 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006985 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006986 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006987 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6988 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006989 .build());
6990
6991 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6992 LocationAccessPolicy.checkLocationPermission(mApp,
6993 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6994 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006995 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006996 .setCallingPid(Binder.getCallingPid())
6997 .setCallingUid(Binder.getCallingUid())
6998 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006999 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007000 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007001 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7002 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007003 .build());
7004 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7005 boolean hasFinePermission =
7006 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7007 boolean hasCoarsePermission =
7008 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007010 final long identity = Binder.clearCallingIdentity();
7011 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007012 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7013 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7014 Rlog.d(LOG_TAG,
7015 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7016 return null;
7017 }
7018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019 final Phone phone = getPhone(subId);
7020 if (phone == null) {
7021 return null;
7022 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007023
Hall Liuf19c44f2018-11-27 14:38:17 -08007024 ServiceState ss = phone.getServiceState();
7025
7026 // Scrub out the location info in ServiceState depending on what level of access
7027 // the caller has.
7028 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007029 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7030 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 } finally {
7032 Binder.restoreCallingIdentity(identity);
7033 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007034 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007035
7036 /**
7037 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7038 *
7039 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7040 * voicemail ringtone.
7041 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7042 * PhoneAccount.
7043 */
7044 @Override
7045 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046 final long identity = Binder.clearCallingIdentity();
7047 try {
7048 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7049 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007050 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7054 } finally {
7055 Binder.restoreCallingIdentity(identity);
7056 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007057 }
7058
7059 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007060 * Sets the per-account voicemail ringtone.
7061 *
7062 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7063 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7064 *
7065 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7066 * voicemail ringtone.
7067 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7068 * PhoneAccount.
7069 */
7070 @Override
7071 public void setVoicemailRingtoneUri(String callingPackage,
7072 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007073 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007074 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007075 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7076 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7078 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7079 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007080 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081
7082 final long identity = Binder.clearCallingIdentity();
7083 try {
7084 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7085 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007086 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007087 }
7088 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7089 } finally {
7090 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007091 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007092 }
7093
7094 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007095 * Returns whether vibration is set for voicemail notification in Phone settings.
7096 *
7097 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7098 * voicemail vibration setting.
7099 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7100 */
7101 @Override
7102 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007103 final long identity = Binder.clearCallingIdentity();
7104 try {
7105 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7106 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007107 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7111 } finally {
7112 Binder.restoreCallingIdentity(identity);
7113 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007114 }
7115
Youhan Wange64578a2016-05-02 15:32:42 -07007116 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007117 * Sets the per-account voicemail vibration.
7118 *
7119 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7120 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7121 *
7122 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7123 * voicemail vibration setting.
7124 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7125 * specific PhoneAccount.
7126 */
7127 @Override
7128 public void setVoicemailVibrationEnabled(String callingPackage,
7129 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007130 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007131 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007132 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7133 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7135 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7136 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007137 }
7138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139 final long identity = Binder.clearCallingIdentity();
7140 try {
7141 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7142 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007143 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007144 }
7145 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7146 } finally {
7147 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007148 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007149 }
7150
7151 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007152 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7153 *
7154 * @throws SecurityException if the caller does not have the required permission
7155 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007156 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007157 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007158 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007159 }
7160
7161 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007162 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7163 * permission.
7164 *
7165 * @throws SecurityException if the caller does not have the required permission
7166 */
7167 private void enforceSendSmsPermission() {
7168 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7169 }
7170
7171 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007172 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007173 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007174 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007175 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007176 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007177 final long identity = Binder.clearCallingIdentity();
7178 try {
7179 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007180 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 if (componentName == null) {
7182 throw new SecurityException(
7183 "Caller not current active visual voicemail package[null]");
7184 }
7185 String vvmPackage = componentName.getPackageName();
7186 if (!callingPackage.equals(vvmPackage)) {
7187 throw new SecurityException("Caller not current active visual voicemail package["
7188 + vvmPackage + "]");
7189 }
7190 } finally {
7191 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007192 }
7193 }
7194
7195 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007196 * Return the application ID for the app type.
7197 *
7198 * @param subId the subscription ID that this request applies to.
7199 * @param appType the uicc app type.
7200 * @return Application ID for specificied app type, or null if no uicc.
7201 */
7202 @Override
7203 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007204 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007205 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007206
7207 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007208 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209 if (phone == null) {
7210 return null;
7211 }
7212 String aid = null;
7213 try {
7214 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7215 .getApplicationByType(appType).getAid();
7216 } catch (Exception e) {
7217 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7218 }
7219 return aid;
7220 } finally {
7221 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007222 }
Youhan Wange64578a2016-05-02 15:32:42 -07007223 }
7224
Youhan Wang4001d252016-05-11 10:29:41 -07007225 /**
7226 * Return the Electronic Serial Number.
7227 *
7228 * @param subId the subscription ID that this request applies to.
7229 * @return ESN or null if error.
7230 */
7231 @Override
7232 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007233 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007234 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235
7236 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007237 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007238 if (phone == null) {
7239 return null;
7240 }
7241 String esn = null;
7242 try {
7243 esn = phone.getEsn();
7244 } catch (Exception e) {
7245 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7246 }
7247 return esn;
7248 } finally {
7249 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007250 }
Youhan Wang4001d252016-05-11 10:29:41 -07007251 }
7252
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007253 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007254 * Return the Preferred Roaming List Version.
7255 *
7256 * @param subId the subscription ID that this request applies to.
7257 * @return PRLVersion or null if error.
7258 */
7259 @Override
7260 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007261 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007262 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007263
7264 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007265 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266 if (phone == null) {
7267 return null;
7268 }
7269 String cdmaPrlVersion = null;
7270 try {
7271 cdmaPrlVersion = phone.getCdmaPrlVersion();
7272 } catch (Exception e) {
7273 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7274 }
7275 return cdmaPrlVersion;
7276 } finally {
7277 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007278 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007279 }
7280
7281 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007282 * Get snapshot of Telephony histograms
7283 * @return List of Telephony histograms
7284 * @hide
7285 */
7286 @Override
7287 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7289 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007290
7291 final long identity = Binder.clearCallingIdentity();
7292 try {
7293 return RIL.getTelephonyRILTimingHistograms();
7294 } finally {
7295 Binder.restoreCallingIdentity(identity);
7296 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007297 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007298
7299 /**
7300 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007301 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7302 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007303 * Require system privileges. In the future we may add this to carrier APIs.
7304 *
Michele Berionne482f8202018-11-27 18:57:59 -08007305 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007306 */
7307 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007308 @TelephonyManager.SetCarrierRestrictionResult
7309 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007310 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007311 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007312
Michele Berionne482f8202018-11-27 18:57:59 -08007313 if (carrierRestrictionRules == null) {
7314 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007315 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007316
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007317 final long identity = Binder.clearCallingIdentity();
7318 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007319 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007320 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007321 } finally {
7322 Binder.restoreCallingIdentity(identity);
7323 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007324 }
7325
7326 /**
7327 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007328 * Get the allowed carrier list and the excluded carrier list, including the priority between
7329 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007330 * Require system privileges. In the future we may add this to carrier APIs.
7331 *
Michele Berionne482f8202018-11-27 18:57:59 -08007332 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007333 */
7334 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007335 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007336 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007337 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007338
7339 final long identity = Binder.clearCallingIdentity();
7340 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007341 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7342 if (response instanceof CarrierRestrictionRules) {
7343 return (CarrierRestrictionRules) response;
7344 }
7345 // Response is an Exception of some kind,
7346 // which is signalled to the user as a NULL retval
7347 return null;
7348 } catch (Exception e) {
7349 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7350 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007351 } finally {
7352 Binder.restoreCallingIdentity(identity);
7353 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007354 }
7355
fionaxu59545b42016-05-25 15:53:37 -07007356 /**
fionaxu59545b42016-05-25 15:53:37 -07007357 * Action set from carrier signalling broadcast receivers to enable/disable radio
7358 * @param subId the subscription ID that this action applies to.
7359 * @param enabled control enable or disable radio.
7360 * {@hide}
7361 */
7362 @Override
7363 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7364 enforceModifyPermission();
7365 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366
7367 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007368 if (phone == null) {
7369 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7370 return;
7371 }
7372 try {
7373 phone.carrierActionSetRadioEnabled(enabled);
7374 } catch (Exception e) {
7375 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376 } finally {
7377 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007378 }
7379 }
7380
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007381 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007382 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7383 * network status based on which carrier apps could apply actions accordingly,
7384 * enable/disable default url handler for example.
7385 *
7386 * @param subId the subscription ID that this action applies to.
7387 * @param report control start/stop reporting the default network status.
7388 * {@hide}
7389 */
7390 @Override
7391 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7392 enforceModifyPermission();
7393 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007394
7395 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007396 if (phone == null) {
7397 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7398 return;
7399 }
7400 try {
7401 phone.carrierActionReportDefaultNetworkStatus(report);
7402 } catch (Exception e) {
7403 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007404 } finally {
7405 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007406 }
7407 }
7408
7409 /**
fionaxud9622282017-07-17 17:51:30 -07007410 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7411 * @param subId the subscription ID that this action applies to.
7412 * {@hide}
7413 */
7414 @Override
7415 public void carrierActionResetAll(int subId) {
7416 enforceModifyPermission();
7417 final Phone phone = getPhone(subId);
7418 if (phone == null) {
7419 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7420 return;
7421 }
7422 try {
7423 phone.carrierActionResetAll();
7424 } catch (Exception e) {
7425 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7426 }
7427 }
7428
7429 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007430 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7431 * bug report is being generated.
7432 */
7433 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007434 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007435 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7436 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007437 writer.println("Permission Denial: can't dump Phone from pid="
7438 + Binder.getCallingPid()
7439 + ", uid=" + Binder.getCallingUid()
7440 + "without permission "
7441 + android.Manifest.permission.DUMP);
7442 return;
7443 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007444 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007445 }
Jack Yueb89b242016-06-22 13:27:47 -07007446
Brad Ebingerdac2f002018-04-03 15:17:52 -07007447 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007448 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7449 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7450 @NonNull String[] args) {
7451 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7452 this, in.getFileDescriptor(), out.getFileDescriptor(),
7453 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007454 }
7455
Jack Yueb89b242016-06-22 13:27:47 -07007456 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007457 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007458 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007459 * @param reason the reason the data enable change is taking place
7460 * @param enabled True if enabling the data, otherwise disabling.
7461 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007462 */
7463 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007464 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007465 boolean enabled) {
7466 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7467 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7468 try {
7469 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007470 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007471 } catch (SecurityException se) {
7472 enforceModifyPermission();
7473 }
7474 } else {
7475 enforceModifyPermission();
7476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477
7478 final long identity = Binder.clearCallingIdentity();
7479 try {
7480 Phone phone = getPhone(subId);
7481 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007482 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7483 phone.carrierActionSetMeteredApnsEnabled(enabled);
7484 } else {
7485 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7486 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 }
7488 } finally {
7489 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007490 }
7491 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007492
7493 /**
7494 * Get Client request stats
7495 * @return List of Client Request Stats
7496 * @hide
7497 */
7498 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007499 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7500 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007501 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007502 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007503 return null;
7504 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007505 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507 final long identity = Binder.clearCallingIdentity();
7508 try {
7509 if (phone != null) {
7510 return phone.getClientRequestStats();
7511 }
7512
7513 return null;
7514 } finally {
7515 Binder.restoreCallingIdentity(identity);
7516 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007517 }
7518
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007519 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007520 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007521 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007522 }
Jack Yueb4124c2017-02-16 15:32:43 -08007523
7524 /**
Grace Chen70990072017-03-24 17:21:30 -07007525 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007526 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007527 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007528 * @param state State of SIM (power down, power up, pass through)
7529 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7530 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7531 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007532 *
7533 **/
7534 @Override
Grace Chen70990072017-03-24 17:21:30 -07007535 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007536 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007537 Phone phone = PhoneFactory.getPhone(slotIndex);
7538
vagdeviaf9a5b92018-08-15 16:01:53 -07007539 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7540
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 final long identity = Binder.clearCallingIdentity();
7542 try {
7543 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007544 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 }
7546 } finally {
7547 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007548 }
7549 }
Shuo Qiandd210312017-04-12 22:11:33 +00007550
Tyler Gunn65d45c22017-06-05 11:22:26 -07007551 private boolean isUssdApiAllowed(int subId) {
7552 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007553 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007554 if (configManager == null) {
7555 return false;
7556 }
7557 PersistableBundle pb = configManager.getConfigForSubId(subId);
7558 if (pb == null) {
7559 return false;
7560 }
7561 return pb.getBoolean(
7562 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7563 }
7564
Shuo Qiandd210312017-04-12 22:11:33 +00007565 /**
7566 * Check if phone is in emergency callback mode
7567 * @return true if phone is in emergency callback mode
7568 * @param subId sub id
7569 */
goneil9c5f4872017-12-05 14:07:56 -08007570 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007571 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007572 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007573 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007574
7575 final long identity = Binder.clearCallingIdentity();
7576 try {
7577 if (phone != null) {
7578 return phone.isInEcm();
7579 } else {
7580 return false;
7581 }
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007584 }
7585 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007586
7587 /**
7588 * Get the current signal strength information for the given subscription.
7589 * Because this information is not updated when the device is in a low power state
7590 * it should not be relied-upon to be current.
7591 * @param subId Subscription index
7592 * @return the most recent cached signal strength info from the modem
7593 */
7594 @Override
7595 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007596 final long identity = Binder.clearCallingIdentity();
7597 try {
7598 Phone p = getPhone(subId);
7599 if (p == null) {
7600 return null;
7601 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007603 return p.getSignalStrength();
7604 } finally {
7605 Binder.restoreCallingIdentity(identity);
7606 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007607 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007608
Pengquan Meng77b7f132018-08-22 14:49:57 -07007609 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007610 * Get the current modem radio state for the given slot.
7611 * @param slotIndex slot index.
7612 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007613 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007614 * @return the current radio power state from the modem
7615 */
7616 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007617 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007618 Phone phone = PhoneFactory.getPhone(slotIndex);
7619 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007620 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7621 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007622 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7623 }
7624
7625 final long identity = Binder.clearCallingIdentity();
7626 try {
7627 return phone.getRadioPowerState();
7628 } finally {
7629 Binder.restoreCallingIdentity(identity);
7630 }
7631 }
7632 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7633 }
7634
7635 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007636 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7637 *
7638 * <p>Requires one of the following permissions:
7639 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7640 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7641 * privileges.
7642 *
7643 * @param subId subscription id
7644 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7645 * {@code false}.
7646 */
7647 @Override
7648 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07007649 try {
7650 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7651 null);
7652 } catch (Exception e) {
7653 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7654 mApp, subId, "isDataRoamingEnabled");
7655 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007656
Pengquan Menga1bb6272018-09-06 09:59:22 -07007657 boolean isEnabled = false;
7658 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007659 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007660 Phone phone = getPhone(subId);
7661 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007662 } finally {
7663 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007664 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007665 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007666 }
7667
7668
7669 /**
7670 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7671 *
7672 * <p> Requires permission:
7673 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7674 * privileges.
7675 *
7676 * @param subId subscription id
7677 * @param isEnabled {@code true} means enable, {@code false} means disable.
7678 */
7679 @Override
7680 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7682 mApp, subId, "setDataRoamingEnabled");
7683
Pengquan Menga1bb6272018-09-06 09:59:22 -07007684 final long identity = Binder.clearCallingIdentity();
7685 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007686 Phone phone = getPhone(subId);
7687 if (phone != null) {
7688 phone.setDataRoamingEnabled(isEnabled);
7689 }
7690 } finally {
7691 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007692 }
7693 }
7694
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007695 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007696 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007697 TelephonyPermissions
7698 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007699 mApp, subId, "isManualNetworkSelectionAllowed");
7700
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007701 boolean isAllowed = true;
7702 final long identity = Binder.clearCallingIdentity();
7703 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007704 Phone phone = getPhone(subId);
7705 if (phone != null) {
7706 isAllowed = phone.isCspPlmnEnabled();
7707 }
7708 } finally {
7709 Binder.restoreCallingIdentity(identity);
7710 }
7711 return isAllowed;
7712 }
7713
7714 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007715 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007716 // Verify that tha callingPackage belongs to the calling UID
7717 mApp.getSystemService(AppOpsManager.class)
7718 .checkPackage(Binder.getCallingUid(), callingPackage);
7719
Jordan Liu1e142fc2019-04-22 15:10:43 -07007720 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007721 try {
7722 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007723 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007724 } catch (SecurityException e) {
7725 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7726 // has carrier privileges on an active UICC
7727 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7728 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007729 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007730 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007731 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007732
7733 final long identity = Binder.clearCallingIdentity();
7734 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007735 UiccController uiccController = UiccController.getInstance();
7736 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007737 if (hasReadPermission) {
7738 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007739 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007740
7741 // Remove private info if the caller doesn't have access
7742 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7743 for (UiccCardInfo cardInfo : cardInfos) {
7744 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7745 // is available
7746 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7747 if (card == null || card.getUiccProfile() == null) {
7748 // assume no access if the card or profile is unavailable
7749 filteredInfos.add(cardInfo.getUnprivileged());
7750 continue;
7751 }
7752 UiccProfile profile = card.getUiccProfile();
7753 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7754 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7755 filteredInfos.add(cardInfo);
7756 } else {
7757 filteredInfos.add(cardInfo.getUnprivileged());
7758 }
7759 }
7760 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007761 } finally {
7762 Binder.restoreCallingIdentity(identity);
7763 }
7764 }
7765
7766 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007767 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007768 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007770 final long identity = Binder.clearCallingIdentity();
7771 try {
7772 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7773 if (slots == null) {
7774 Rlog.i(LOG_TAG, "slots is null.");
7775 return null;
7776 }
7777
7778 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7779 for (int i = 0; i < slots.length; i++) {
7780 UiccSlot slot = slots[i];
7781 if (slot == null) {
7782 continue;
7783 }
7784
Jordan Liu7be7e652019-05-06 18:55:02 +00007785 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786 UiccCard card = slot.getUiccCard();
7787 if (card != null) {
7788 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007789 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007790 cardId = slot.getEid();
7791 if (TextUtils.isEmpty(cardId)) {
7792 cardId = slot.getIccId();
7793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794 }
7795
Jordan Liu857451f2019-05-09 16:35:35 -07007796 if (cardId != null) {
7797 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7798 // if cardId is an EID, it's all digits so this is fine
7799 cardId = IccUtils.stripTrailingFs(cardId);
7800 }
7801
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802 int cardState = 0;
7803 switch (slot.getCardState()) {
7804 case CARDSTATE_ABSENT:
7805 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7806 break;
7807 case CARDSTATE_PRESENT:
7808 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7809 break;
7810 case CARDSTATE_ERROR:
7811 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7812 break;
7813 case CARDSTATE_RESTRICTED:
7814 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7815 break;
7816 default:
7817 break;
7818
7819 }
7820
7821 infos[i] = new UiccSlotInfo(
7822 slot.isActive(),
7823 slot.isEuicc(),
7824 cardId,
7825 cardState,
7826 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007827 slot.isExtendedApduSupported(),
7828 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007829 }
7830 return infos;
7831 } finally {
7832 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007833 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007834 }
7835
7836 @Override
7837 public boolean switchSlots(int[] physicalSlots) {
7838 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007839
7840 final long identity = Binder.clearCallingIdentity();
7841 try {
7842 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7843 } finally {
7844 Binder.restoreCallingIdentity(identity);
7845 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007846 }
Jack Yu4c988042018-02-27 15:30:01 -08007847
7848 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007849 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007850 final long identity = Binder.clearCallingIdentity();
7851 try {
7852 return UiccController.getInstance().getCardIdForDefaultEuicc();
7853 } finally {
7854 Binder.restoreCallingIdentity(identity);
7855 }
7856 }
7857
Pengquan Meng85728fb2018-03-12 16:31:21 -07007858 /**
goneil47ffb6e2018-04-06 15:40:58 -07007859 * A test API to reload the UICC profile.
7860 *
7861 * <p>Requires that the calling app has permission
7862 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7863 * @hide
7864 */
7865 @Override
7866 public void refreshUiccProfile(int subId) {
7867 enforceModifyPermission();
7868
7869 final long identity = Binder.clearCallingIdentity();
7870 try {
7871 Phone phone = getPhone(subId);
7872 if (phone == null) {
7873 return;
7874 }
7875 UiccCard uiccCard = phone.getUiccCard();
7876 if (uiccCard == null) {
7877 return;
7878 }
7879 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7880 if (uiccProfile == null) {
7881 return;
7882 }
7883 uiccProfile.refresh();
7884 } finally {
7885 Binder.restoreCallingIdentity(identity);
7886 }
7887 }
7888
7889 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007890 * Returns false if the mobile data is disabled by default, otherwise return true.
7891 */
7892 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007893 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007894 }
7895
7896 /**
7897 * Returns true if the data roaming is enabled by default, i.e the system property
7898 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7899 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7900 */
7901 private boolean getDefaultDataRoamingEnabled(int subId) {
7902 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007903 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07007904 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007905 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7906 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7907 return isDataRoamingEnabled;
7908 }
7909
7910 /**
7911 * Returns the default network type for the given {@code subId}, if the default network type is
7912 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7913 */
7914 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007915 List<Integer> list = TelephonyProperties.default_network();
7916 int phoneId = mSubscriptionController.getPhoneId(subId);
7917 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7918 return list.get(phoneId);
7919 }
7920 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007921 }
fionaxua13278b2018-03-21 00:08:13 -07007922
7923 @Override
7924 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007925 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007926 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007927
7928 final long identity = Binder.clearCallingIdentity();
7929 try {
7930 final Phone phone = getPhone(subId);
7931 if (phone == null) {
7932 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7933 return;
7934 }
chen xueaba88a2019-03-15 13:15:10 -07007935 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7936 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07007937 if (carrierPrivilegeRules == null) {
7938 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
7939 } else {
7940 mCarrierPrivilegeTestOverrideSubIds.add(subId);
7941 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007942 } finally {
7943 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007944 }
fionaxua13278b2018-03-21 00:08:13 -07007945 }
7946
7947 @Override
7948 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007949 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007950
7951 final long identity = Binder.clearCallingIdentity();
7952 try {
7953 final Phone phone = getPhone(subId);
7954 if (phone == null) {
7955 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7956 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7957 }
7958 return phone.getCarrierIdListVersion();
7959 } finally {
7960 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007961 }
fionaxua13278b2018-03-21 00:08:13 -07007962 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007963
7964 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007965 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7966 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007968 mApp, subId, callingPackage, callingFeatureId,
7969 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007970 return -1;
7971 }
7972
7973 final long identity = Binder.clearCallingIdentity();
7974 try {
7975 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7976 } finally {
7977 Binder.restoreCallingIdentity(identity);
7978 }
7979 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007980
7981 @Override
7982 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007983 TelephonyPermissions
7984 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007985 mApp, subId, "getCdmaRoamingMode");
7986
7987 final long identity = Binder.clearCallingIdentity();
7988 try {
7989 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7990 } finally {
7991 Binder.restoreCallingIdentity(identity);
7992 }
7993 }
7994
7995 @Override
7996 public boolean setCdmaRoamingMode(int subId, int mode) {
7997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7998 mApp, subId, "setCdmaRoamingMode");
7999
8000 final long identity = Binder.clearCallingIdentity();
8001 try {
8002 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8003 } finally {
8004 Binder.restoreCallingIdentity(identity);
8005 }
8006 }
8007
8008 @Override
8009 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8011 mApp, subId, "setCdmaSubscriptionMode");
8012
8013 final long identity = Binder.clearCallingIdentity();
8014 try {
8015 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8016 } finally {
8017 Binder.restoreCallingIdentity(identity);
8018 }
8019 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008020
sqianc5eccab2018-10-19 18:46:41 -07008021 @Override
sqian8c685422019-02-22 15:55:18 -08008022 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008023 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008024 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008025 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8026 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008027 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8028 }
8029 final long identity = Binder.clearCallingIdentity();
8030 try {
sqian854d44b2018-12-12 16:48:18 -08008031 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8032 for (Phone phone: PhoneFactory.getPhones()) {
8033 if (phone.getEmergencyNumberTracker() != null
8034 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8035 emergencyNumberListInternal.put(
8036 phone.getSubId(),
8037 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8038 }
sqian11b7a0e2018-12-05 18:48:28 -08008039 }
sqian854d44b2018-12-12 16:48:18 -08008040 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008041 } finally {
8042 Binder.restoreCallingIdentity(identity);
8043 }
sqianc5eccab2018-10-19 18:46:41 -07008044 }
8045
8046 @Override
sqian8c685422019-02-22 15:55:18 -08008047 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008048 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008049 if (!exactMatch) {
8050 TelephonyPermissions
8051 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008052 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008053 }
8054 final long identity = Binder.clearCallingIdentity();
8055 try {
sqian854d44b2018-12-12 16:48:18 -08008056 for (Phone phone: PhoneFactory.getPhones()) {
8057 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008058 && phone.getEmergencyNumberTracker()
8059 .isEmergencyNumber(number, exactMatch)) {
8060 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008061 }
sqian11b7a0e2018-12-05 18:48:28 -08008062 }
8063 return false;
8064 } finally {
8065 Binder.restoreCallingIdentity(identity);
8066 }
8067 }
8068
sqianf4ca7ed2019-01-15 18:32:07 -08008069 /**
8070 * Update emergency number list for test mode.
8071 */
8072 @Override
8073 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8074 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8075 "updateEmergencyNumberListTestMode");
8076
8077 final long identity = Binder.clearCallingIdentity();
8078 try {
8079 for (Phone phone: PhoneFactory.getPhones()) {
8080 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8081 if (tracker != null) {
8082 tracker.executeEmergencyNumberTestModeCommand(action, num);
8083 }
8084 }
8085 } finally {
8086 Binder.restoreCallingIdentity(identity);
8087 }
8088 }
8089
8090 /**
8091 * Get the full emergency number list for test mode.
8092 */
8093 @Override
8094 public List<String> getEmergencyNumberListTestMode() {
8095 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8096 "getEmergencyNumberListTestMode");
8097
8098 final long identity = Binder.clearCallingIdentity();
8099 try {
8100 Set<String> emergencyNumbers = new HashSet<>();
8101 for (Phone phone: PhoneFactory.getPhones()) {
8102 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8103 if (tracker != null) {
8104 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8105 emergencyNumbers.add(num.getNumber());
8106 }
8107 }
8108 }
8109 return new ArrayList<>(emergencyNumbers);
8110 } finally {
8111 Binder.restoreCallingIdentity(identity);
8112 }
8113 }
8114
chen xud6b45bd2018-10-30 22:27:10 -07008115 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008116 public int getEmergencyNumberDbVersion(int subId) {
8117 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8118
8119 final long identity = Binder.clearCallingIdentity();
8120 try {
8121 final Phone phone = getPhone(subId);
8122 if (phone == null) {
8123 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8124 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8125 }
8126 return phone.getEmergencyNumberDbVersion();
8127 } finally {
8128 Binder.restoreCallingIdentity(identity);
8129 }
8130 }
8131
8132 @Override
8133 public void notifyOtaEmergencyNumberDbInstalled() {
8134 enforceModifyPermission();
8135
8136 final long identity = Binder.clearCallingIdentity();
8137 try {
8138 for (Phone phone: PhoneFactory.getPhones()) {
8139 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8140 if (tracker != null) {
8141 tracker.updateOtaEmergencyNumberDatabase();
8142 }
8143 }
8144 } finally {
8145 Binder.restoreCallingIdentity(identity);
8146 }
8147 }
8148
8149 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008150 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008151 enforceActiveEmergencySessionPermission();
8152
8153 final long identity = Binder.clearCallingIdentity();
8154 try {
8155 for (Phone phone: PhoneFactory.getPhones()) {
8156 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8157 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008158 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8159 }
8160 }
8161 } finally {
8162 Binder.restoreCallingIdentity(identity);
8163 }
8164 }
8165
8166 @Override
8167 public void resetOtaEmergencyNumberDbFilePath() {
8168 enforceActiveEmergencySessionPermission();
8169
8170 final long identity = Binder.clearCallingIdentity();
8171 try {
8172 for (Phone phone: PhoneFactory.getPhones()) {
8173 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8174 if (tracker != null) {
8175 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008176 }
8177 }
8178 } finally {
8179 Binder.restoreCallingIdentity(identity);
8180 }
8181 }
8182
8183 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008184 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8185 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8186 Phone phone = getPhone(subId);
8187 if (phone == null) {
8188 return null;
8189 }
8190 final long identity = Binder.clearCallingIdentity();
8191 try {
8192 UiccProfile profile = UiccController.getInstance()
8193 .getUiccProfileForPhone(phone.getPhoneId());
8194 if (profile != null) {
8195 return profile.getCertsFromCarrierPrivilegeAccessRules();
8196 }
8197 } finally {
8198 Binder.restoreCallingIdentity(identity);
8199 }
8200 return null;
8201 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008202
8203 /**
8204 * Enable or disable a modem stack.
8205 */
8206 @Override
8207 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8208 enforceModifyPermission();
8209
8210 final long identity = Binder.clearCallingIdentity();
8211 try {
8212 Phone phone = PhoneFactory.getPhone(slotIndex);
8213 if (phone == null) {
8214 return false;
8215 } else {
8216 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8217 }
8218 } finally {
8219 Binder.restoreCallingIdentity(identity);
8220 }
8221 }
Michelecea4cf22018-12-21 15:00:11 -08008222
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008223 /**
8224 * Whether a modem stack is enabled or not.
8225 */
8226 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008227 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8228 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008229 Phone phone = PhoneFactory.getPhone(slotIndex);
8230 if (phone == null) return false;
8231
8232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008233 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8234 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008235 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8236 }
8237
8238 final long identity = Binder.clearCallingIdentity();
8239 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008240 try {
8241 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8242 } catch (NoSuchElementException ex) {
8243 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8244 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008245 } finally {
8246 Binder.restoreCallingIdentity(identity);
8247 }
8248 }
8249
Michelecea4cf22018-12-21 15:00:11 -08008250 @Override
Michele0ea7d782019-03-19 14:58:42 -07008251 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008252 enforceModifyPermission();
8253
8254 final long identity = Binder.clearCallingIdentity();
8255 try {
8256 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008257 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008258 .commit();
8259 } finally {
8260 Binder.restoreCallingIdentity(identity);
8261 }
8262 }
8263
8264 @Override
Michele0ea7d782019-03-19 14:58:42 -07008265 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008266 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008268 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8269 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008270 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008271 }
Michelecea4cf22018-12-21 15:00:11 -08008272
8273 final long identity = Binder.clearCallingIdentity();
8274 try {
Michele0ea7d782019-03-19 14:58:42 -07008275 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008276 } finally {
8277 Binder.restoreCallingIdentity(identity);
8278 }
8279 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008280
Michele0ea7d782019-03-19 14:58:42 -07008281 @TelephonyManager.IsMultiSimSupportedResult
8282 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008283 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8284 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8285 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008286 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8287 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008288 }
8289 // Check if the hardware supports multisim functionality. If usage of multisim is not
8290 // supported by the modem, indicate that it is restricted.
8291 PhoneCapability staticCapability =
8292 mPhoneConfigurationManager.getStaticPhoneCapability();
8293 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008294 loge("isMultiSimSupportedInternal: no static configuration available");
8295 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008296 }
Sarah Chin7caee492020-02-18 20:49:02 +00008297 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008298 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8299 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008300 }
8301 // Check if support of multiple SIMs is restricted by carrier
8302 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008303 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008304 }
8305
Michele0ea7d782019-03-19 14:58:42 -07008306 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008307 }
8308
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008309 /**
8310 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008311 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8312 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8313 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008314 * @param numOfSims number of active sims we want to switch to
8315 */
8316 @Override
8317 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008318 if (numOfSims == 1) {
8319 enforceModifyPermission();
8320 } else {
8321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8322 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8323 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008324 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008325
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008326 try {
Michele30b57b22019-03-01 12:01:14 -08008327 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008328 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008329 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8330 return;
8331 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008332 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8333 } finally {
8334 Binder.restoreCallingIdentity(identity);
8335 }
8336 }
8337
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008338 @Override
8339 public boolean isApplicationOnUicc(int subId, int appType) {
8340 enforceReadPrivilegedPermission("isApplicationOnUicc");
8341 Phone phone = getPhone(subId);
8342 if (phone == null) {
8343 return false;
8344 }
8345 final long identity = Binder.clearCallingIdentity();
8346 try {
8347 UiccCard uiccCard = phone.getUiccCard();
8348 if (uiccCard == null) {
8349 return false;
8350 }
8351 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8352 if (uiccProfile == null) {
8353 return false;
8354 }
8355 if (TelephonyManager.APPTYPE_SIM <= appType
8356 && appType <= TelephonyManager.APPTYPE_ISIM) {
8357 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8358 }
8359 return false;
8360 } finally {
8361 Binder.restoreCallingIdentity(identity);
8362 }
8363 }
8364
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008365 /**
chen xub4baa772019-04-03 10:23:41 -07008366 * Get whether making changes to modem configurations will trigger reboot.
8367 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008368 */
8369 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008370 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8371 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008373 mApp, subId, callingPackage, callingFeatureId,
8374 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008375 return false;
8376 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008377 final long identity = Binder.clearCallingIdentity();
8378 try {
8379 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8380 } finally {
8381 Binder.restoreCallingIdentity(identity);
8382 }
8383 }
8384
Nathan Harold29f5f052019-02-15 13:41:57 -08008385 private void updateModemStateMetrics() {
8386 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8387 // TODO: check the state for each modem if the api is ready.
8388 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8389 }
8390
Pengquan Meng3889a572019-01-23 11:16:29 -08008391 @Override
8392 public int[] getSlotsMapping() {
8393 enforceReadPrivilegedPermission("getSlotsMapping");
8394
8395 final long identity = Binder.clearCallingIdentity();
8396 try {
8397 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8398 // All logical slots should have a mapping to a physical slot.
8399 int[] logicalSlotsMapping = new int[phoneCount];
8400 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8401 for (int i = 0; i < slotInfos.length; i++) {
8402 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8403 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8404 }
8405 }
8406 return logicalSlotsMapping;
8407 } finally {
8408 Binder.restoreCallingIdentity(identity);
8409 }
8410 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008411
8412 /**
8413 * Get the IRadio HAL Version
8414 */
8415 @Override
8416 public int getRadioHalVersion() {
8417 Phone phone = getDefaultPhone();
8418 if (phone == null) return -1;
8419 HalVersion hv = phone.getHalVersion();
8420 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8421 return hv.major * 100 + hv.minor;
8422 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008423
8424 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008425 * Get the current calling package name.
8426 * @return the current calling package name
8427 */
8428 @Override
8429 public String getCurrentPackageName() {
8430 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8431 }
8432
8433 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008434 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8435 * corresponding network requests on a subId.
8436 *
8437 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008438 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008439 * 2) APN is un-metered for this subscription, or
8440 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008441 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008442 *
8443 * @return whether data is allowed for a apn type.
8444 *
8445 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008446 */
8447 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008448 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008449 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8450 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008451
8452 // Now that all security checks passes, perform the operation as ourselves.
8453 final long identity = Binder.clearCallingIdentity();
8454 try {
8455 Phone phone = getPhone(subId);
8456 if (phone == null) return false;
8457
Jack Yu41407ee2019-05-13 16:54:09 -07008458 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008459 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8460 } finally {
8461 Binder.restoreCallingIdentity(identity);
8462 }
8463 }
8464
8465 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008466 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008467 enforceReadPrivilegedPermission("isApnMetered");
8468
8469 // Now that all security checks passes, perform the operation as ourselves.
8470 final long identity = Binder.clearCallingIdentity();
8471 try {
8472 Phone phone = getPhone(subId);
8473 if (phone == null) return true; // By default return true.
8474
Jack Yu41407ee2019-05-13 16:54:09 -07008475 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008476 } finally {
8477 Binder.restoreCallingIdentity(identity);
8478 }
8479 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008480
8481 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008482 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8483 int subscriptionId, IBooleanConsumer resultCallback) {
8484 enforceModifyPermission();
8485 long token = Binder.clearCallingIdentity();
8486 try {
8487 Phone phone = getPhone(subscriptionId);
8488 if (phone == null) {
8489 try {
8490 if (resultCallback != null) {
8491 resultCallback.accept(false);
8492 }
8493 } catch (RemoteException e) {
8494 // ignore
8495 }
8496 return;
8497 }
8498 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8499 Pair.create(specifiers, (x) -> {
8500 try {
8501 if (resultCallback != null) {
8502 resultCallback.accept(x);
8503 }
8504 } catch (RemoteException e) {
8505 // ignore
8506 }
8507 });
8508 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8509 } finally {
8510 Binder.restoreCallingIdentity(token);
8511 }
8512 }
8513
8514 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008515 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008516 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008517 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8518 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8519 if (iccRecords == null) {
8520 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8521 return false;
8522 }
8523 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8524 }
8525
8526 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008527 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8528 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008529 if (callingPackage == null) {
8530 callingPackage = getCurrentPackageName();
8531 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008532 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8533 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008534 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8535 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008536 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8537 }
8538 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8539 Intent intent = new Intent();
8540 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8541 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8542 // Bring up choose default SMS subscription dialog right now
8543 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8544 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8545 mApp.startActivity(intent);
8546 }
chen xud5ca2d52019-05-28 15:20:57 -07008547
8548 @Override
8549 public String getMmsUAProfUrl(int subId) {
8550 //TODO investigate if this API should require proper permission check in R b/133791609
8551 final long identity = Binder.clearCallingIdentity();
8552 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008553 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8554 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8555 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8556 return carrierUAProfUrl;
8557 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008558 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8559 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008560 } finally {
8561 Binder.restoreCallingIdentity(identity);
8562 }
8563 }
8564
8565 @Override
8566 public String getMmsUserAgent(int subId) {
8567 //TODO investigate if this API should require proper permission check in R b/133791609
8568 final long identity = Binder.clearCallingIdentity();
8569 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008570 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8571 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8572 if (!TextUtils.isEmpty(carrierUserAgent)) {
8573 return carrierUserAgent;
8574 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008575 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8576 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008577 } finally {
8578 Binder.restoreCallingIdentity(identity);
8579 }
8580 }
Jack Yub07d4972019-05-28 16:12:25 -07008581
8582 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008583 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8584 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07008585
Jack Yub07d4972019-05-28 16:12:25 -07008586 final long identity = Binder.clearCallingIdentity();
8587 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008588 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07008589 if (phone == null) return false;
8590
Hall Liua62f5da2020-09-25 10:42:19 -07008591 switch (policy) {
8592 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8593 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8594 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8595 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8596 default:
8597 throw new IllegalArgumentException(policy + " is not a valid policy");
8598 }
Jack Yub07d4972019-05-28 16:12:25 -07008599 } finally {
8600 Binder.restoreCallingIdentity(identity);
8601 }
8602 }
8603
8604 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008605 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8606 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08008607 enforceModifyPermission();
8608
changbettyd5c246e2019-12-24 15:40:37 +08008609 final long identity = Binder.clearCallingIdentity();
8610 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008611 Phone phone = getPhone(subscriptionId);
8612 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08008613
Hall Liua62f5da2020-09-25 10:42:19 -07008614 switch (policy) {
8615 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8616 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8617 break;
8618 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8619 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8620 break;
8621 default:
8622 throw new IllegalArgumentException(policy + " is not a valid policy");
8623 }
changbettyd5c246e2019-12-24 15:40:37 +08008624 } finally {
8625 Binder.restoreCallingIdentity(identity);
8626 }
8627 }
8628
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008629 /**
Hall Liu746e03c2020-09-25 11:13:49 -07008630 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008631 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8632 * otherwise.
8633 */
8634 @Override
8635 public void setCepEnabled(boolean isCepEnabled) {
8636 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8637
8638 final long identity = Binder.clearCallingIdentity();
8639 try {
8640 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8641 for (Phone phone : PhoneFactory.getPhones()) {
8642 Phone defaultPhone = phone.getImsPhone();
8643 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8644 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8645 ImsPhoneCallTracker imsPhoneCallTracker =
8646 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8647 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8648 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8649 + imsPhone.getMsisdn());
8650 }
8651 }
8652 } finally {
8653 Binder.restoreCallingIdentity(identity);
8654 }
8655 }
allenwtsu46dcc572020-01-08 18:24:03 +08008656
8657 /**
8658 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8659 *
8660 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8661 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8662 * before being read.
8663 */
8664 @Override
8665 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8666 isCompressed) {
8667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8668 mApp, subId, "notifyRcsAutoConfigurationReceived");
8669 try {
8670 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8671 if (configBinder == null) {
8672 Rlog.e(LOG_TAG, "null result for getImsConfig");
8673 } else {
8674 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8675 }
8676 } catch (RemoteException e) {
8677 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8678 }
8679 }
zoey chene02881a2019-12-30 16:11:23 +08008680
8681 @Override
8682 public boolean isIccLockEnabled(int subId) {
8683 enforceReadPrivilegedPermission("isIccLockEnabled");
8684
8685 // Now that all security checks passes, perform the operation as ourselves.
8686 final long identity = Binder.clearCallingIdentity();
8687 try {
8688 Phone phone = getPhone(subId);
8689 if (phone != null && phone.getIccCard() != null) {
8690 return phone.getIccCard().getIccLockEnabled();
8691 } else {
8692 return false;
8693 }
8694 } finally {
8695 Binder.restoreCallingIdentity(identity);
8696 }
8697 }
8698
8699 /**
8700 * Set the ICC pin lock enabled or disabled.
8701 *
8702 * @return an integer representing the status of IccLock enabled or disabled in the following
8703 * three cases:
8704 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8705 * successfully.
8706 * - Positive number and zero for remaining password attempts.
8707 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8708 *
8709 */
8710 @Override
8711 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8712 enforceModifyPermission();
8713
8714 Phone phone = getPhone(subId);
8715 if (phone == null) {
8716 return 0;
8717 }
8718 // Now that all security checks passes, perform the operation as ourselves.
8719 final long identity = Binder.clearCallingIdentity();
8720 try {
8721 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8722 new Pair<Boolean, String>(enabled, password), phone, null);
8723 return attemptsRemaining;
8724
8725 } catch (Exception e) {
8726 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8727 } finally {
8728 Binder.restoreCallingIdentity(identity);
8729 }
8730 return 0;
8731 }
8732
8733 /**
8734 * Change the ICC password used in ICC pin lock.
8735 *
8736 * @return an integer representing the status of IccLock changed in the following three cases:
8737 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8738 * - Positive number and zero for remaining password attempts.
8739 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8740 *
8741 */
8742 @Override
8743 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8744 enforceModifyPermission();
8745
8746 Phone phone = getPhone(subId);
8747 if (phone == null) {
8748 return 0;
8749 }
8750 // Now that all security checks passes, perform the operation as ourselves.
8751 final long identity = Binder.clearCallingIdentity();
8752 try {
8753 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8754 new Pair<String, String>(oldPassword, newPassword), phone, null);
8755 return attemptsRemaining;
8756
8757 } catch (Exception e) {
8758 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8759 } finally {
8760 Binder.restoreCallingIdentity(identity);
8761 }
8762 return 0;
8763 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008764
8765 /**
8766 * Request for receiving user activity notification
8767 */
8768 @Override
8769 public void requestUserActivityNotification() {
8770 if (!mNotifyUserActivity.get()
8771 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8772 mNotifyUserActivity.set(true);
8773 }
8774 }
8775
8776 /**
8777 * Called when userActivity is signalled in the power manager.
8778 * This is safe to call from any thread, with any window manager locks held or not.
8779 */
8780 @Override
8781 public void userActivity() {
8782 // ***************************************
8783 // * Inherited from PhoneWindowManager *
8784 // ***************************************
8785 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8786 // WITH ITS LOCKS HELD.
8787 //
8788 // This code must be VERY careful about the locks
8789 // it acquires.
8790 // In fact, the current code acquires way too many,
8791 // and probably has lurking deadlocks.
8792
8793 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8794 throw new SecurityException("Only the OS may call notifyUserActivity()");
8795 }
8796
8797 if (mNotifyUserActivity.getAndSet(false)) {
8798 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8799 USER_ACTIVITY_NOTIFICATION_DELAY);
8800 }
8801 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008802
8803 @Override
8804 public boolean canConnectTo5GInDsdsMode() {
8805 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8806 }
Jack Yud10cdd42020-09-28 20:28:01 -07008807
8808 @Override
8809 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
8810 String callingFeatureId) {
8811 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
8812 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
8813 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8814 }
8815
8816 Phone phone = getPhone(subId);
8817 if (phone == null) {
8818 throw new RuntimeException("phone is not available");
8819 }
8820 // Now that all security checks passes, perform the operation as ourselves.
8821 final long identity = Binder.clearCallingIdentity();
8822 try {
8823 return phone.getEquivalentHomePlmns();
8824 } finally {
8825 Binder.restoreCallingIdentity(identity);
8826 }
8827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008828}