blob: 2cd2f05b167eab7495e1f625ca97992497d39ceb [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;
Jack Yu84291ec2017-05-26 16:07:50 -070038import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080049import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070050import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070051import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080052import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080053import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070054import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070055import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -080068import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070069import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080070import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070071import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080072import android.telephony.CellIdentityCdma;
73import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070075import android.telephony.CellInfoGsm;
76import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070077import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070078import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070079import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080080import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070081import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080082import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070083import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080084import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080085import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070086import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080089import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080090import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080092import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070093import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070094import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080095import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080096import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000097import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070098import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070099import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800100import android.telephony.data.ApnSetting;
101import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700102import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800103import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700104import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700105import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700107import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800108import android.telephony.ims.aidl.IImsMmTelFeature;
109import android.telephony.ims.aidl.IImsRcsFeature;
110import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700111import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700112import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800114import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800115import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800116import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800120import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800124import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700126import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700127import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800128import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700129import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700130import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800131import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800133import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800134import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700135import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800136import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800138import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700140import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700141import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700143import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800144import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700145import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700146import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700147import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700148import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700149import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700150import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700151import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800153import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800154import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700156import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800157import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700158import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800159import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700160import com.android.internal.telephony.imsphone.ImsPhone;
161import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800162import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700163import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800165import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800167import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700168import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800169import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800171import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000172import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800173import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700174import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
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
Derek Tan97ebb422014-09-05 16:55:38 -0700316 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
317 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800318 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800319 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700320
Michelecea4cf22018-12-21 15:00:11 -0800321 // String to store multi SIM allowed
322 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
323
Derek Tan740e1672017-06-27 14:56:27 -0700324 // The AID of ISD-R.
325 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
326
yinxub1bed742017-04-17 11:45:04 -0700327 private NetworkScanRequestTracker mNetworkScanRequestTracker;
328
David Kelly5e06a7f2018-03-12 14:10:59 +0000329 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
330 private static final int MANUFACTURER_CODE_LENGTH = 8;
331
Derek Tan89e89d42014-07-08 17:00:10 -0700332 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700333 * Experiment flag to enable erase modem config on reset network, default value is false
334 */
335 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
336 "reset_network_erase_modem_config_enabled";
337
338 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700339 * A request object to use for transmitting data to an ICC.
340 */
341 private static final class IccAPDUArgument {
342 public int channel, cla, command, p1, p2, p3;
343 public String data;
344
345 public IccAPDUArgument(int channel, int cla, int command,
346 int p1, int p2, int p3, String data) {
347 this.channel = channel;
348 this.cla = cla;
349 this.command = command;
350 this.p1 = p1;
351 this.p2 = p2;
352 this.p3 = p3;
353 this.data = data;
354 }
355 }
356
357 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700358 * A request object to use for transmitting data to an ICC.
359 */
360 private static final class ManualNetworkSelectionArgument {
361 public OperatorInfo operatorInfo;
362 public boolean persistSelection;
363
364 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
365 this.operatorInfo = operatorInfo;
366 this.persistSelection = persistSelection;
367 }
368 }
369
370 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
372 * request after sending. The main thread will notify the request when it is complete.
373 */
374 private static final class MainThreadRequest {
375 /** The argument to use for the request */
376 public Object argument;
377 /** The result of the request that is run on the main thread */
378 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800379 // The subscriber id that this request applies to. Defaults to
380 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
381 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382
Nathan Harold92bed182018-10-12 18:16:49 -0700383 // In cases where subId is unavailable, the caller needs to specify the phone.
384 public Phone phone;
385
vagdeviaf9a5b92018-08-15 16:01:53 -0700386 public WorkSource workSource;
387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 public MainThreadRequest(Object argument) {
389 this.argument = argument;
390 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800391
Nathan Harold92bed182018-10-12 18:16:49 -0700392 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
393 this.argument = argument;
394 if (phone != null) {
395 this.phone = phone;
396 }
397 this.workSource = workSource;
398 }
399
vagdeviaf9a5b92018-08-15 16:01:53 -0700400 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800401 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800402 if (subId != null) {
403 this.subId = subId;
404 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700405 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 }
408
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800409 private static final class IncomingThirdPartyCallArgs {
410 public final ComponentName component;
411 public final String callId;
412 public final String callerDisplayName;
413
414 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
415 String callerDisplayName) {
416 this.component = component;
417 this.callId = callId;
418 this.callerDisplayName = callerDisplayName;
419 }
420 }
421
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 /**
423 * A handler that processes messages on the main thread in the phone process. Since many
424 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
425 * inbound binder threads to the main thread in the phone process. The Binder thread
426 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
427 * on, which will be notified when the operation completes and will contain the result of the
428 * request.
429 *
430 * <p>If a MainThreadRequest object is provided in the msg.obj field,
431 * note that request.result must be set to something non-null for the calling thread to
432 * unblock.
433 */
434 private final class MainThreadHandler extends Handler {
435 @Override
436 public void handleMessage(Message msg) {
437 MainThreadRequest request;
438 Message onCompleted;
439 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800440 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800442 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443
444 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 case CMD_HANDLE_USSD_REQUEST: {
446 request = (MainThreadRequest) msg.obj;
447 final Phone phone = getPhoneFromRequest(request);
448 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
449 String ussdRequest = ussdObject.first;
450 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700451
Pengquan Menga1bb6272018-09-06 09:59:22 -0700452 if (!isUssdApiAllowed(request.subId)) {
453 // Carrier does not support use of this API, return failure.
454 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
455 UssdResponse response = new UssdResponse(ussdRequest, null);
456 Bundle returnData = new Bundle();
457 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
458 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700459
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 request.result = true;
461 notifyRequester(request);
462 return;
463 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700464
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 try {
466 request.result = phone != null
467 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
468 } catch (CallStateException cse) {
469 request.result = false;
470 }
471 // Wake up the requesting thread
472 notifyRequester(request);
473 break;
pkanwar32d516d2016-10-14 19:37:38 -0700474 }
475
Yorke Lee716f67e2015-06-17 15:39:16 -0700476 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700478 final Phone phone = getPhoneFromRequest(request);
479 request.result = phone != null ?
480 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
481 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700483 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800490 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700491 if (uiccCard == null) {
492 loge("iccTransmitApduLogicalChannel: No UICC");
493 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700495 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
497 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700498 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 iccArgument.channel, iccArgument.cla, iccArgument.command,
500 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700501 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700502 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 break;
504
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700506 ar = (AsyncResult) msg.obj;
507 request = (MainThreadRequest) ar.userObj;
508 if (ar.exception == null && ar.result != null) {
509 request.result = ar.result;
510 } else {
511 request.result = new IccIoResult(0x6F, 0, (byte[])null);
512 if (ar.result == null) {
513 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800514 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800516 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 } else {
518 loge("iccTransmitApduLogicalChannel: Unknown exception");
519 }
520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700522 break;
523
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
525 request = (MainThreadRequest) msg.obj;
526 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800527 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 if (uiccCard == null) {
529 loge("iccTransmitApduBasicChannel: No UICC");
530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 } else {
533 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
534 request);
535 uiccCard.iccTransmitApduBasicChannel(
536 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
537 iccArgument.p3, iccArgument.data, onCompleted);
538 }
539 break;
540
541 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
542 ar = (AsyncResult) msg.obj;
543 request = (MainThreadRequest) ar.userObj;
544 if (ar.exception == null && ar.result != null) {
545 request.result = ar.result;
546 } else {
547 request.result = new IccIoResult(0x6F, 0, (byte[])null);
548 if (ar.result == null) {
549 loge("iccTransmitApduBasicChannel: Empty response");
550 } else if (ar.exception instanceof CommandException) {
551 loge("iccTransmitApduBasicChannel: CommandException: " +
552 ar.exception);
553 } else {
554 loge("iccTransmitApduBasicChannel: Unknown exception");
555 }
556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 break;
559
560 case CMD_EXCHANGE_SIM_IO:
561 request = (MainThreadRequest) msg.obj;
562 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 if (uiccCard == null) {
565 loge("iccExchangeSimIO: No UICC");
566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 } else {
569 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
570 request);
571 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
572 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
573 iccArgument.data, onCompleted);
574 }
575 break;
576
577 case EVENT_EXCHANGE_SIM_IO_DONE:
578 ar = (AsyncResult) msg.obj;
579 request = (MainThreadRequest) ar.userObj;
580 if (ar.exception == null && ar.result != null) {
581 request.result = ar.result;
582 } else {
583 request.result = new IccIoResult(0x6f, 0, (byte[])null);
584 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 break;
587
Derek Tan4d5e5c12014-02-04 11:54:58 -0800588 case CMD_SEND_ENVELOPE:
589 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800590 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 if (uiccCard == null) {
592 loge("sendEnvelopeWithStatus: No UICC");
593 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 } else {
596 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
597 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
598 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800599 break;
600
601 case EVENT_SEND_ENVELOPE_DONE:
602 ar = (AsyncResult) msg.obj;
603 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700604 if (ar.exception == null && ar.result != null) {
605 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800606 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700607 request.result = new IccIoResult(0x6F, 0, (byte[])null);
608 if (ar.result == null) {
609 loge("sendEnvelopeWithStatus: Empty response");
610 } else if (ar.exception instanceof CommandException) {
611 loge("sendEnvelopeWithStatus: CommandException: " +
612 ar.exception);
613 } else {
614 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
615 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800616 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800618 break;
619
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 case CMD_OPEN_CHANNEL:
621 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800622 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800623 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 if (uiccCard == null) {
625 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800626 request.result = new IccOpenLogicalChannelResponse(-1,
627 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800631 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
632 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case EVENT_OPEN_CHANNEL_DONE:
637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 int[] result = (int[]) ar.result;
642 int channelId = result[0];
643 byte[] selectResponse = null;
644 if (result.length > 1) {
645 selectResponse = new byte[result.length - 1];
646 for (int i = 1; i < result.length; ++i) {
647 selectResponse[i - 1] = (byte) result[i];
648 }
649 }
650 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700651 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 if (ar.result == null) {
654 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 if (ar.exception != null) {
657 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
658 }
659
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700660 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700661 if (ar.exception instanceof CommandException) {
662 CommandException.Error error =
663 ((CommandException) (ar.exception)).getCommandError();
664 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700665 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700666 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700667 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 }
669 }
670 openChannelResp = new IccOpenLogicalChannelResponse(
671 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700673 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 break;
676
677 case CMD_CLOSE_CHANNEL:
678 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800679 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700680 if (uiccCard == null) {
681 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900682 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700684 } else {
685 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
686 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
687 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 break;
689
690 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800691 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
692 break;
693
694 case CMD_NV_READ_ITEM:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800697 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
698 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800699 break;
700
701 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 ar = (AsyncResult) msg.obj;
703 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800704 if (ar.exception == null && ar.result != null) {
705 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800707 request.result = "";
708 if (ar.result == null) {
709 loge("nvReadItem: Empty response");
710 } else if (ar.exception instanceof CommandException) {
711 loge("nvReadItem: CommandException: " +
712 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800714 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 }
716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 break;
719
Jake Hambye994d462014-02-03 13:10:13 -0800720 case CMD_NV_WRITE_ITEM:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
723 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800724 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700725 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800726 break;
727
728 case EVENT_NV_WRITE_ITEM_DONE:
729 handleNullReturnEvent(msg, "nvWriteItem");
730 break;
731
732 case CMD_NV_WRITE_CDMA_PRL:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800735 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800736 break;
737
738 case EVENT_NV_WRITE_CDMA_PRL_DONE:
739 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
740 break;
741
chen xu6dac5ab2018-10-26 17:39:23 -0700742 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800743 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700744 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800745 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800746 break;
747
chen xu6dac5ab2018-10-26 17:39:23 -0700748 case EVENT_RESET_MODEM_CONFIG_DONE:
749 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800750 break;
751
Jake Hamby7c27be32014-03-03 13:25:59 -0800752 case CMD_GET_PREFERRED_NETWORK_TYPE:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700755 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 break;
757
758 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
759 ar = (AsyncResult) msg.obj;
760 request = (MainThreadRequest) ar.userObj;
761 if (ar.exception == null && ar.result != null) {
762 request.result = ar.result; // Integer
763 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800764 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800765 if (ar.result == null) {
766 loge("getPreferredNetworkType: Empty response");
767 } else if (ar.exception instanceof CommandException) {
768 loge("getPreferredNetworkType: CommandException: " +
769 ar.exception);
770 } else {
771 loge("getPreferredNetworkType: Unknown exception");
772 }
773 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700774 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800775 break;
776
777 case CMD_SET_PREFERRED_NETWORK_TYPE:
778 request = (MainThreadRequest) msg.obj;
779 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
780 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700781 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800782 break;
783
784 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
785 handleNullReturnEvent(msg, "setPreferredNetworkType");
786 break;
787
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000788 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
789 request = (MainThreadRequest)msg.obj;
790 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800791 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000792 break;
793
794 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
795 ar = (AsyncResult)msg.obj;
796 request = (MainThreadRequest)ar.userObj;
797 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700798 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000799 break;
800
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800801 case CMD_SET_VOICEMAIL_NUMBER:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
804 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800805 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
806 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800807 break;
808
809 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
810 handleNullReturnEvent(msg, "setVoicemailNumber");
811 break;
812
Stuart Scott54788802015-03-30 13:18:01 -0700813 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
814 request = (MainThreadRequest) msg.obj;
815 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
816 request);
817 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
818 break;
819
820 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
821 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
822 break;
823
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 case CMD_PERFORM_NETWORK_SCAN:
825 request = (MainThreadRequest) msg.obj;
826 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
827 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
828 break;
829
Shuo Qian4a594052020-01-23 11:59:30 -0800830 case CMD_GET_CALL_FORWARDING:
831 request = (MainThreadRequest) msg.obj;
832 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
833 int callForwardingReason = (Integer) request.argument;
834 getPhoneFromRequest(request).getCallForwardingOption(
835 callForwardingReason, onCompleted);
836 break;
837
838 case EVENT_GET_CALL_FORWARDING_DONE:
839 ar = (AsyncResult) msg.obj;
840 request = (MainThreadRequest) ar.userObj;
841 CallForwardingInfo callForwardingInfo = null;
842 if (ar.exception == null && ar.result != null) {
843 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
844 for (CallForwardInfo callForwardInfo : callForwardInfos) {
845 // Service Class is a bit mask per 3gpp 27.007. Search for
846 // any service for voice call.
847 if ((callForwardInfo.serviceClass
848 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
849 callForwardingInfo = new CallForwardingInfo(
850 callForwardInfo.serviceClass, callForwardInfo.reason,
851 callForwardInfo.number,
852 callForwardInfo.timeSeconds);
853 break;
854 }
855 }
856 // Didn't find a call forward info for voice call.
857 if (callForwardingInfo == null) {
858 callForwardingInfo = new CallForwardingInfo(
859 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
860 0 /* reason */, null /* number */, 0 /* timeout */);
861 }
862 } else {
863 if (ar.result == null) {
864 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
865 }
866 if (ar.exception != null) {
867 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
868 }
869 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
870 if (ar.exception instanceof CommandException) {
871 CommandException.Error error =
872 ((CommandException) (ar.exception)).getCommandError();
873 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
874 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
875 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
876 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
877 }
878 }
879 callForwardingInfo = new CallForwardingInfo(
880 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
881 }
882 request.result = callForwardingInfo;
883 notifyRequester(request);
884 break;
885
886 case CMD_SET_CALL_FORWARDING:
887 request = (MainThreadRequest) msg.obj;
888 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
889 CallForwardingInfo callForwardingInfoToSet =
890 (CallForwardingInfo) request.argument;
891 getPhoneFromRequest(request).setCallForwardingOption(
892 callForwardingInfoToSet.getStatus(),
893 callForwardingInfoToSet.getReason(),
894 callForwardingInfoToSet.getNumber(),
895 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
896 break;
897
898 case EVENT_SET_CALL_FORWARDING_DONE:
899 ar = (AsyncResult) msg.obj;
900 request = (MainThreadRequest) ar.userObj;
901 if (ar.exception == null) {
902 request.result = true;
903 } else {
904 request.result = false;
905 loge("setCallForwarding exception: " + ar.exception);
906 }
907 notifyRequester(request);
908 break;
909
910 case CMD_GET_CALL_WAITING:
911 request = (MainThreadRequest) msg.obj;
912 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
913 getPhoneFromRequest(request).getCallWaiting(onCompleted);
914 break;
915
916 case EVENT_GET_CALL_WAITING_DONE:
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
920 if (ar.exception == null && ar.result != null) {
921 ArrayList<Integer> callForwardResults = (ArrayList<Integer>) ar.result;
922 // Service Class is a bit mask per 3gpp 27.007.
923 // Search for any service for voice call.
924 if ((callForwardResults.get(1)
925 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
926 callForwardingStatus = callForwardResults.get(0) == 0
927 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
928 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
929 } else {
930 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
931 }
932 } else {
933 if (ar.result == null) {
934 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
935 }
936 if (ar.exception != null) {
937 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
938 }
939 if (ar.exception instanceof CommandException) {
940 CommandException.Error error =
941 ((CommandException) (ar.exception)).getCommandError();
942 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
943 callForwardingStatus =
944 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
945 }
946 }
947 }
948 request.result = callForwardingStatus;
949 notifyRequester(request);
950 break;
951
952 case CMD_SET_CALL_WAITING:
953 request = (MainThreadRequest) msg.obj;
954 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
955 boolean isEnable = (Boolean) request.argument;
956 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
957 break;
958
959 case EVENT_SET_CALL_WAITING_DONE:
960 ar = (AsyncResult) msg.obj;
961 request = (MainThreadRequest) ar.userObj;
962 if (ar.exception == null) {
963 request.result = true;
964 } else {
965 request.result = false;
966 loge("setCallWaiting exception: " + ar.exception);
967 }
968 notifyRequester(request);
969 break;
970
Shishir Agrawal302c8692015-06-19 13:49:39 -0700971 case EVENT_PERFORM_NETWORK_SCAN_DONE:
972 ar = (AsyncResult) msg.obj;
973 request = (MainThreadRequest) ar.userObj;
974 CellNetworkScanResult cellScanResult;
975 if (ar.exception == null && ar.result != null) {
976 cellScanResult = new CellNetworkScanResult(
977 CellNetworkScanResult.STATUS_SUCCESS,
978 (List<OperatorInfo>) ar.result);
979 } else {
980 if (ar.result == null) {
981 loge("getCellNetworkScanResults: Empty response");
982 }
983 if (ar.exception != null) {
984 loge("getCellNetworkScanResults: Exception: " + ar.exception);
985 }
986 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
987 if (ar.exception instanceof CommandException) {
988 CommandException.Error error =
989 ((CommandException) (ar.exception)).getCommandError();
990 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
991 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
992 } else if (error == CommandException.Error.GENERIC_FAILURE) {
993 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
994 }
995 }
996 cellScanResult = new CellNetworkScanResult(errorCode, null);
997 }
998 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700999 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001000 break;
1001
1002 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1003 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001004 ManualNetworkSelectionArgument selArg =
1005 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001006 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1007 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001008 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1009 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001010 break;
1011
1012 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 if (ar.exception == null) {
1016 request.result = true;
1017 } else {
1018 request.result = false;
1019 loge("setNetworkSelectionModeManual " + ar.exception);
1020 }
1021 notifyRequester(request);
1022 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001023 break;
1024
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001025 case CMD_GET_MODEM_ACTIVITY_INFO:
1026 request = (MainThreadRequest) msg.obj;
1027 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001028 if (defaultPhone != null) {
1029 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
1030 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001031 break;
1032
1033 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1034 ar = (AsyncResult) msg.obj;
1035 request = (MainThreadRequest) ar.userObj;
1036 if (ar.exception == null && ar.result != null) {
1037 request.result = ar.result;
1038 } else {
1039 if (ar.result == null) {
1040 loge("queryModemActivityInfo: Empty response");
1041 } else if (ar.exception instanceof CommandException) {
1042 loge("queryModemActivityInfo: CommandException: " +
1043 ar.exception);
1044 } else {
1045 loge("queryModemActivityInfo: Unknown exception");
1046 }
1047 }
Amit Mahajand4766222016-01-28 15:28:28 -08001048 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
1049 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -08001050 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -08001051 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001052 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001053 break;
1054
Meng Wang1a7c35a2016-05-05 20:56:15 -07001055 case CMD_SET_ALLOWED_CARRIERS:
1056 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001057 CarrierRestrictionRules argument =
1058 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001059 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001060 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001061 break;
1062
1063 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
1066 if (ar.exception == null && ar.result != null) {
1067 request.result = ar.result;
1068 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001069 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1070 if (ar.exception instanceof CommandException) {
1071 loge("setAllowedCarriers: CommandException: " + ar.exception);
1072 CommandException.Error error =
1073 ((CommandException) (ar.exception)).getCommandError();
1074 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1075 request.result =
1076 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1077 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001078 } else {
1079 loge("setAllowedCarriers: Unknown exception");
1080 }
1081 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001082 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001083 break;
1084
1085 case CMD_GET_ALLOWED_CARRIERS:
1086 request = (MainThreadRequest) msg.obj;
1087 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001088 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001089 break;
1090
1091 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1092 ar = (AsyncResult) msg.obj;
1093 request = (MainThreadRequest) ar.userObj;
1094 if (ar.exception == null && ar.result != null) {
1095 request.result = ar.result;
1096 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001097 request.result = new IllegalStateException(
1098 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001099 if (ar.result == null) {
1100 loge("getAllowedCarriers: Empty response");
1101 } else if (ar.exception instanceof CommandException) {
1102 loge("getAllowedCarriers: CommandException: " +
1103 ar.exception);
1104 } else {
1105 loge("getAllowedCarriers: Unknown exception");
1106 }
1107 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001108 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001109 break;
1110
Nathan Haroldb3014052017-01-25 15:57:32 -08001111 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1112 ar = (AsyncResult) msg.obj;
1113 request = (MainThreadRequest) ar.userObj;
1114 if (ar.exception == null && ar.result != null) {
1115 request.result = ar.result;
1116 } else {
1117 request.result = new IllegalArgumentException(
1118 "Failed to retrieve Forbidden Plmns");
1119 if (ar.result == null) {
1120 loge("getForbiddenPlmns: Empty response");
1121 } else {
1122 loge("getForbiddenPlmns: Unknown exception");
1123 }
1124 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001125 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001126 break;
1127
1128 case CMD_GET_FORBIDDEN_PLMNS:
1129 request = (MainThreadRequest) msg.obj;
1130 uiccCard = getUiccCardFromRequest(request);
1131 if (uiccCard == null) {
1132 loge("getForbiddenPlmns() UiccCard is null");
1133 request.result = new IllegalArgumentException(
1134 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001135 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001136 break;
1137 }
1138 Integer appType = (Integer) request.argument;
1139 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1140 if (uiccApp == null) {
1141 loge("getForbiddenPlmns() no app with specified type -- "
1142 + appType);
1143 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001144 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001145 break;
1146 } else {
1147 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1148 + " specified type -- " + appType);
1149 }
1150 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1151 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1152 onCompleted);
1153 break;
1154
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001155 case CMD_SWITCH_SLOTS:
1156 request = (MainThreadRequest) msg.obj;
1157 int[] physicalSlots = (int[]) request.argument;
1158 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1159 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1160 break;
1161
1162 case EVENT_SWITCH_SLOTS_DONE:
1163 ar = (AsyncResult) msg.obj;
1164 request = (MainThreadRequest) ar.userObj;
1165 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001166 notifyRequester(request);
1167 break;
1168 case CMD_GET_NETWORK_SELECTION_MODE:
1169 request = (MainThreadRequest) msg.obj;
1170 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1171 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1172 break;
1173
1174 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1175 ar = (AsyncResult) msg.obj;
1176 request = (MainThreadRequest) ar.userObj;
1177 if (ar.exception != null) {
1178 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1179 } else {
1180 int mode = ((int[]) ar.result)[0];
1181 if (mode == 0) {
1182 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1183 } else {
1184 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1185 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001186 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001187 notifyRequester(request);
1188 break;
1189 case CMD_GET_CDMA_ROAMING_MODE:
1190 request = (MainThreadRequest) msg.obj;
1191 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1192 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1193 break;
1194 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1195 ar = (AsyncResult) msg.obj;
1196 request = (MainThreadRequest) ar.userObj;
1197 if (ar.exception != null) {
1198 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1199 } else {
1200 request.result = ((int[]) ar.result)[0];
1201 }
1202 notifyRequester(request);
1203 break;
1204 case CMD_SET_CDMA_ROAMING_MODE:
1205 request = (MainThreadRequest) msg.obj;
1206 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1207 int mode = (int) request.argument;
1208 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1209 break;
1210 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1211 ar = (AsyncResult) msg.obj;
1212 request = (MainThreadRequest) ar.userObj;
1213 request.result = ar.exception == null;
1214 notifyRequester(request);
1215 break;
1216 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1217 request = (MainThreadRequest) msg.obj;
1218 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1219 int subscriptionMode = (int) request.argument;
1220 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1221 break;
1222 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1223 ar = (AsyncResult) msg.obj;
1224 request = (MainThreadRequest) ar.userObj;
1225 request.result = ar.exception == null;
1226 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001227 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001228 case CMD_GET_ALL_CELL_INFO:
1229 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001230 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001231 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001232 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001233 case EVENT_GET_ALL_CELL_INFO_DONE:
1234 ar = (AsyncResult) msg.obj;
1235 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001236 // If a timeout occurs, the response will be null
1237 request.result = (ar.exception == null && ar.result != null)
1238 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001239 synchronized (request) {
1240 request.notifyAll();
1241 }
1242 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001243 case CMD_REQUEST_CELL_INFO_UPDATE:
1244 request = (MainThreadRequest) msg.obj;
1245 request.phone.requestCellInfoUpdate(request.workSource,
1246 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1247 break;
1248 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1249 ar = (AsyncResult) msg.obj;
1250 request = (MainThreadRequest) ar.userObj;
1251 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1252 try {
1253 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001254 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001255 cb.onError(
1256 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1257 ar.exception.getClass().getName(),
1258 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001259 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001260 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001261 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001262 } else {
1263 // use the result as returned
1264 cb.onCellInfo((List<CellInfo>) ar.result);
1265 }
1266 } catch (RemoteException re) {
1267 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1268 }
1269 break;
1270 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001271 request = (MainThreadRequest) msg.obj;
1272 WorkSource ws = (WorkSource) request.argument;
1273 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001274 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001275 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001276 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001277 ar = (AsyncResult) msg.obj;
1278 request = (MainThreadRequest) ar.userObj;
1279 if (ar.exception == null) {
1280 request.result = ar.result;
1281 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001282 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001283 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001284 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001285 }
1286
1287 synchronized (request) {
1288 request.notifyAll();
1289 }
1290 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001291 case CMD_MODEM_REBOOT:
1292 request = (MainThreadRequest) msg.obj;
1293 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001294 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001295 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001296 case EVENT_CMD_MODEM_REBOOT_DONE:
1297 handleNullReturnEvent(msg, "rebootModem");
1298 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001299 case CMD_REQUEST_ENABLE_MODEM:
1300 request = (MainThreadRequest) msg.obj;
1301 boolean enable = (boolean) request.argument;
1302 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001303 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001304 PhoneConfigurationManager.getInstance()
1305 .enablePhone(request.phone, enable, onCompleted);
1306 break;
1307 case EVENT_ENABLE_MODEM_DONE:
1308 ar = (AsyncResult) msg.obj;
1309 request = (MainThreadRequest) ar.userObj;
1310 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001311 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001312 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001313 if ((boolean) request.result) {
1314 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1315 updateModemStateMetrics();
1316 } else {
1317 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1318 + ar.exception);
1319 }
1320 notifyRequester(request);
1321 break;
1322 case CMD_GET_MODEM_STATUS:
1323 request = (MainThreadRequest) msg.obj;
1324 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1325 PhoneConfigurationManager.getInstance()
1326 .getPhoneStatusFromModem(request.phone, onCompleted);
1327 break;
1328 case EVENT_GET_MODEM_STATUS_DONE:
1329 ar = (AsyncResult) msg.obj;
1330 request = (MainThreadRequest) ar.userObj;
1331 int id = request.phone.getPhoneId();
1332 if (ar.exception == null && ar.result != null) {
1333 request.result = ar.result;
1334 //update the cache as modem status has changed
1335 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1336 (boolean) request.result);
1337 } else {
1338 // Return true if modem status cannot be retrieved. For most cases,
1339 // modem status is on. And for older version modems, GET_MODEM_STATUS
1340 // and disable modem are not supported. Modem is always on.
1341 // TODO: this should be fixed in R to support a third
1342 // status UNKNOWN b/131631629
1343 request.result = true;
1344 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1345 + ar.exception);
1346 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001347 notifyRequester(request);
1348 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001349 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1350 request = (MainThreadRequest) msg.obj;
1351 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1352 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1353 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1354 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1355 break;
1356 }
1357 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1358 ar = (AsyncResult) msg.obj;
1359 request = (MainThreadRequest) ar.userObj;
1360 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1361 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1362 args.second.accept(ar.exception == null);
1363 notifyRequester(request);
1364 break;
1365 }
yincheng zhao2737e882019-09-06 17:06:54 -07001366 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1367 ar = (AsyncResult) msg.obj;
1368 request = (MainThreadRequest) ar.userObj;
1369 if (ar.exception == null && ar.result != null) {
1370 request.result = ar.result;
1371 } else {
1372 request.result = -1;
1373 loge("Failed to set Forbidden Plmns");
1374 if (ar.result == null) {
1375 loge("setForbidenPlmns: Empty response");
1376 } else if (ar.exception != null) {
1377 loge("setForbiddenPlmns: Exception: " + ar.exception);
1378 request.result = -1;
1379 } else {
1380 loge("setForbiddenPlmns: Unknown exception");
1381 }
1382 }
1383 notifyRequester(request);
1384 break;
1385 case CMD_SET_FORBIDDEN_PLMNS:
1386 request = (MainThreadRequest) msg.obj;
1387 uiccCard = getUiccCardFromRequest(request);
1388 if (uiccCard == null) {
1389 loge("setForbiddenPlmns: UiccCard is null");
1390 request.result = -1;
1391 notifyRequester(request);
1392 break;
1393 }
1394 Pair<Integer, List<String>> setFplmnsArgs =
1395 (Pair<Integer, List<String>>) request.argument;
1396 appType = setFplmnsArgs.first;
1397 List<String> fplmns = setFplmnsArgs.second;
1398 uiccApp = uiccCard.getApplicationByType(appType);
1399 if (uiccApp == null) {
1400 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1401 request.result = -1;
1402 loge("Failed to get UICC App");
1403 notifyRequester(request);
1404 } else {
1405 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1406 ((SIMRecords) uiccApp.getIccRecords())
1407 .setForbiddenPlmns(onCompleted, fplmns);
1408 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001409 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001410 case CMD_ERASE_MODEM_CONFIG:
1411 request = (MainThreadRequest) msg.obj;
1412 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1413 defaultPhone.eraseModemConfig(onCompleted);
1414 break;
1415 case EVENT_ERASE_MODEM_CONFIG_DONE:
1416 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001417 break;
zoey chene02881a2019-12-30 16:11:23 +08001418
1419 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1420 request = (MainThreadRequest) msg.obj;
1421 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1422 Pair<String, String> changed = (Pair<String, String>) request.argument;
1423 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1424 changed.first, changed.second, onCompleted);
1425 break;
1426 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1427 ar = (AsyncResult) msg.obj;
1428 request = (MainThreadRequest) ar.userObj;
1429 if (ar.exception == null) {
1430 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1431 } else {
1432 request.result = msg.arg1;
1433 }
1434 notifyRequester(request);
1435 break;
1436
1437 case CMD_SET_ICC_LOCK_ENABLED:
1438 request = (MainThreadRequest) msg.obj;
1439 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1440 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1441 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1442 enabled.first, enabled.second, onCompleted);
1443 break;
1444 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1445 ar = (AsyncResult) msg.obj;
1446 request = (MainThreadRequest) ar.userObj;
1447 if (ar.exception == null) {
1448 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1449 } else {
1450 request.result = msg.arg1;
1451 }
1452 notifyRequester(request);
1453 break;
1454
Peter Wangdafb9ac2020-01-15 14:13:38 -08001455 case MSG_NOTIFY_USER_ACTIVITY:
1456 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001457 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001458 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1459 getDefaultPhone().getContext().sendBroadcastAsUser(
1460 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1461 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 default:
1463 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1464 break;
1465 }
1466 }
Jake Hambye994d462014-02-03 13:10:13 -08001467
Pengquan Menga1bb6272018-09-06 09:59:22 -07001468 private void notifyRequester(MainThreadRequest request) {
1469 synchronized (request) {
1470 request.notifyAll();
1471 }
1472 }
1473
Jake Hambye994d462014-02-03 13:10:13 -08001474 private void handleNullReturnEvent(Message msg, String command) {
1475 AsyncResult ar = (AsyncResult) msg.obj;
1476 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1477 if (ar.exception == null) {
1478 request.result = true;
1479 } else {
1480 request.result = false;
1481 if (ar.exception instanceof CommandException) {
1482 loge(command + ": CommandException: " + ar.exception);
1483 } else {
1484 loge(command + ": Unknown exception");
1485 }
1486 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001487 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 }
1490
1491 /**
1492 * Posts the specified command to be executed on the main thread,
1493 * waits for the request to complete, and returns the result.
1494 * @see #sendRequestAsync
1495 */
1496 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001497 return sendRequest(
1498 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001499 }
1500
1501 /**
1502 * Posts the specified command to be executed on the main thread,
1503 * waits for the request to complete, and returns the result.
1504 * @see #sendRequestAsync
1505 */
1506 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1507 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001508 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001509 }
1510
1511 /**
1512 * Posts the specified command to be executed on the main thread,
1513 * waits for the request to complete, and returns the result.
1514 * @see #sendRequestAsync
1515 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001516 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001517 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001518 }
1519
1520 /**
1521 * Posts the specified command to be executed on the main thread,
1522 * waits for the request to complete, and returns the result.
1523 * @see #sendRequestAsync
1524 */
Nathan Harold92bed182018-10-12 18:16:49 -07001525 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1526 return sendRequest(command, argument, subId, null, workSource);
1527 }
1528
1529 /**
1530 * Posts the specified command to be executed on the main thread,
1531 * waits for the request to complete, and returns the result.
1532 * @see #sendRequestAsync
1533 */
1534 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1535 return sendRequest(
1536 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1537 }
1538
1539 /**
1540 * Posts the specified command to be executed on the main thread,
1541 * waits for the request to complete, and returns the result.
1542 * @see #sendRequestAsync
1543 */
1544 private Object sendRequest(
1545 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001546 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1547 throw new RuntimeException("This method will deadlock if called from the main thread.");
1548 }
1549
Nathan Harold92bed182018-10-12 18:16:49 -07001550 MainThreadRequest request = null;
1551 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1552 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1553 } else if (phone != null) {
1554 request = new MainThreadRequest(argument, phone, workSource);
1555 } else {
1556 request = new MainThreadRequest(argument, subId, workSource);
1557 }
1558
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 Message msg = mMainThreadHandler.obtainMessage(command, request);
1560 msg.sendToTarget();
1561
1562 // Wait for the request to complete
1563 synchronized (request) {
1564 while (request.result == null) {
1565 try {
1566 request.wait();
1567 } catch (InterruptedException e) {
1568 // Do nothing, go back and wait until the request is complete
1569 }
1570 }
1571 }
1572 return request.result;
1573 }
1574
1575 /**
1576 * Asynchronous ("fire and forget") version of sendRequest():
1577 * Posts the specified command to be executed on the main thread, and
1578 * returns immediately.
1579 * @see #sendRequest
1580 */
1581 private void sendRequestAsync(int command) {
1582 mMainThreadHandler.sendEmptyMessage(command);
1583 }
1584
1585 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001586 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001587 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001588 */
1589 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001590 sendRequestAsync(command, argument, null, null);
1591 }
1592
1593 /**
1594 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1595 * @see {@link #sendRequest(int,Object)}
1596 */
1597 private void sendRequestAsync(
1598 int command, Object argument, Phone phone, WorkSource workSource) {
1599 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001600 Message msg = mMainThreadHandler.obtainMessage(command, request);
1601 msg.sendToTarget();
1602 }
1603
1604 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 * Initialize the singleton PhoneInterfaceManager instance.
1606 * This is only done once, at startup, from PhoneApp.onCreate().
1607 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001608 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 synchronized (PhoneInterfaceManager.class) {
1610 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001611 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 } else {
1613 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1614 }
1615 return sInstance;
1616 }
1617 }
1618
1619 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001620 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001623 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001624 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1626 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001627 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001628 mTelephonySharedPreferences =
1629 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001630 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001631 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001632 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001633
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 publish();
1635 }
1636
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001637 private Phone getDefaultPhone() {
1638 Phone thePhone = getPhone(getDefaultSubscription());
1639 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1640 }
1641
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 private void publish() {
1643 if (DBG) log("publish: " + this);
1644
Peter Wangc035ce42020-01-08 21:00:22 -08001645 TelephonyFrameworkInitializer
1646 .getTelephonyServiceManager()
1647 .getTelephonyServiceRegisterer()
1648 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 }
1650
Stuart Scott584921c2015-01-15 17:10:34 -08001651 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001652 if (request.phone != null) {
1653 return request.phone;
1654 } else {
1655 return getPhoneFromSubId(request.subId);
1656 }
1657 }
1658
1659 private Phone getPhoneFromSubId(int subId) {
1660 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1661 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001662 }
1663
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001664 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1665 Phone phone = getPhoneFromRequest(request);
1666 return phone == null ? null :
1667 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1668 }
1669
Wink Saville36469e72014-06-11 15:17:00 -07001670 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001671 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001672 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674
Naina Nallurid63128d2019-09-17 14:10:30 -07001675 private void sendEraseModemConfig(Phone phone) {
1676 if (phone != null) {
1677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1678 mApp, phone.getSubId(), "eraseModemConfig");
1679 final long identity = Binder.clearCallingIdentity();
1680 try {
1681 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1682 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1683 } finally {
1684 Binder.restoreCallingIdentity(identity);
1685 }
1686 }
1687 }
1688
Peter Wang44b186e2020-01-13 23:33:09 -08001689 private boolean isImsAvailableOnDevice() {
1690 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1691 if (pm == null) {
1692 // For some reason package manger is not available.. This will fail internally anyway,
1693 // so do not throw error and allow.
1694 return true;
1695 }
1696 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1697 }
1698
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001700 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001701 }
1702
Wink Savilleb564aae2014-10-23 10:18:09 -07001703 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 if (DBG) log("dial: " + number);
1705 // No permission check needed here: This is just a wrapper around the
1706 // ACTION_DIAL intent, which is available to any app since it puts up
1707 // the UI before it does anything.
1708
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001709 final long identity = Binder.clearCallingIdentity();
1710 try {
1711 String url = createTelUrl(number);
1712 if (url == null) {
1713 return;
1714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001716 // PENDING: should we just silently fail if phone is offhook or ringing?
1717 PhoneConstants.State state = mCM.getState(subId);
1718 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1719 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1720 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1721 mApp.startActivity(intent);
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726 }
1727
1728 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001729 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001730 }
1731
Wink Savilleb564aae2014-10-23 10:18:09 -07001732 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 if (DBG) log("call: " + number);
1734
1735 // This is just a wrapper around the ACTION_CALL intent, but we still
1736 // need to do a permission check since we're calling startActivity()
1737 // from the context of the phone app.
1738 enforceCallPermission();
1739
Jordan Liu1617b712019-07-10 15:06:26 -07001740 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 != AppOpsManager.MODE_ALLOWED) {
1742 return;
1743 }
1744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001745 final long identity = Binder.clearCallingIdentity();
1746 try {
1747 String url = createTelUrl(number);
1748 if (url == null) {
1749 return;
1750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001752 boolean isValid = false;
1753 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1754 if (slist != null) {
1755 for (SubscriptionInfo subInfoRecord : slist) {
1756 if (subInfoRecord.getSubscriptionId() == subId) {
1757 isValid = true;
1758 break;
1759 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001760 }
Wink Saville08874612014-08-31 19:19:58 -07001761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001762 if (!isValid) {
1763 return;
1764 }
Wink Saville08874612014-08-31 19:19:58 -07001765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001766 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1767 intent.putExtra(SUBSCRIPTION_KEY, subId);
1768 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1769 mApp.startActivity(intent);
1770 } finally {
1771 Binder.restoreCallingIdentity(identity);
1772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 }
1774
Wink Savilleb564aae2014-10-23 10:18:09 -07001775 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001776 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001777 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1778 }
1779
Wink Savilleb564aae2014-10-23 10:18:09 -07001780 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001781 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001782 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1783 }
1784
Wink Savilleb564aae2014-10-23 10:18:09 -07001785 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001787
1788 final long identity = Binder.clearCallingIdentity();
1789 try {
1790 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1791 checkSimPin.start();
1792 return checkSimPin.unlockSim(null, pin);
1793 } finally {
1794 Binder.restoreCallingIdentity(identity);
1795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 }
1797
Wink Savilleb564aae2014-10-23 10:18:09 -07001798 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001799 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001800
1801 final long identity = Binder.clearCallingIdentity();
1802 try {
1803 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1804 checkSimPuk.start();
1805 return checkSimPuk.unlockSim(puk, pin);
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
1808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
1811 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001812 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 * a synchronous one.
1814 */
1815 private static class UnlockSim extends Thread {
1816
1817 private final IccCard mSimCard;
1818
1819 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001820 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1821 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822
1823 // For replies from SimCard interface
1824 private Handler mHandler;
1825
1826 // For async handler to identify request type
1827 private static final int SUPPLY_PIN_COMPLETE = 100;
1828
1829 public UnlockSim(IccCard simCard) {
1830 mSimCard = simCard;
1831 }
1832
1833 @Override
1834 public void run() {
1835 Looper.prepare();
1836 synchronized (UnlockSim.this) {
1837 mHandler = new Handler() {
1838 @Override
1839 public void handleMessage(Message msg) {
1840 AsyncResult ar = (AsyncResult) msg.obj;
1841 switch (msg.what) {
1842 case SUPPLY_PIN_COMPLETE:
1843 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1844 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001845 mRetryCount = msg.arg1;
1846 if (ar.exception != null) {
1847 if (ar.exception instanceof CommandException &&
1848 ((CommandException)(ar.exception)).getCommandError()
1849 == CommandException.Error.PASSWORD_INCORRECT) {
1850 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1851 } else {
1852 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1853 }
1854 } else {
1855 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 mDone = true;
1858 UnlockSim.this.notifyAll();
1859 }
1860 break;
1861 }
1862 }
1863 };
1864 UnlockSim.this.notifyAll();
1865 }
1866 Looper.loop();
1867 }
1868
1869 /*
1870 * Use PIN or PUK to unlock SIM card
1871 *
1872 * If PUK is null, unlock SIM card with PIN
1873 *
1874 * If PUK is not null, unlock SIM card with PUK and set PIN code
1875 */
Wink Saville9de0f752013-10-22 19:04:03 -07001876 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877
1878 while (mHandler == null) {
1879 try {
1880 wait();
1881 } catch (InterruptedException e) {
1882 Thread.currentThread().interrupt();
1883 }
1884 }
1885 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1886
1887 if (puk == null) {
1888 mSimCard.supplyPin(pin, callback);
1889 } else {
1890 mSimCard.supplyPuk(puk, pin, callback);
1891 }
1892
1893 while (!mDone) {
1894 try {
1895 Log.d(LOG_TAG, "wait for done");
1896 wait();
1897 } catch (InterruptedException e) {
1898 // Restore the interrupted status
1899 Thread.currentThread().interrupt();
1900 }
1901 }
1902 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001903 int[] resultArray = new int[2];
1904 resultArray[0] = mResult;
1905 resultArray[1] = mRetryCount;
1906 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 }
1908 }
1909
1910 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001911 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001912
1913 }
1914
Wink Savilleb564aae2014-10-23 10:18:09 -07001915 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 // No permission check needed here: this call is harmless, and it's
1917 // needed for the ServiceState.requestStateUpdate() call (which is
1918 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001919 final long identity = Binder.clearCallingIdentity();
1920 try {
1921 final Phone phone = getPhone(subId);
1922 if (phone != null) {
1923 phone.updateServiceLocation();
1924 }
1925 } finally {
1926 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001927 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001928 }
1929
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001930 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001931 @Override
1932 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001933 return isRadioOnWithFeature(callingPackage, null);
1934 }
1935
1936
1937 @Override
1938 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1939 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1940 callingFeatureId);
1941 }
1942
1943 @Deprecated
1944 @Override
1945 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1946 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001947 }
1948
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001949 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001950 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1951 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001952 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001953 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001954 return false;
1955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001956
1957 final long identity = Binder.clearCallingIdentity();
1958 try {
1959 return isRadioOnForSubscriber(subId);
1960 } finally {
1961 Binder.restoreCallingIdentity(identity);
1962 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001963 }
1964
1965 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001966 final long identity = Binder.clearCallingIdentity();
1967 try {
1968 final Phone phone = getPhone(subId);
1969 if (phone != null) {
1970 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1971 } else {
1972 return false;
1973 }
1974 } finally {
1975 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 }
1978
1979 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001980 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 }
Wink Saville36469e72014-06-11 15:17:00 -07001982
Wink Savilleb564aae2014-10-23 10:18:09 -07001983 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985
1986 final long identity = Binder.clearCallingIdentity();
1987 try {
1988 final Phone phone = getPhone(subId);
1989 if (phone != null) {
1990 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1991 }
1992 } finally {
1993 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001994 }
Wink Saville36469e72014-06-11 15:17:00 -07001995 }
1996
1997 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001998 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001999 }
2000
Wink Savilleb564aae2014-10-23 10:18:09 -07002001 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002002 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002003
2004 final long identity = Binder.clearCallingIdentity();
2005 try {
2006 final Phone phone = getPhone(subId);
2007 if (phone == null) {
2008 return false;
2009 }
2010 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2011 toggleRadioOnOffForSubscriber(subId);
2012 }
2013 return true;
2014 } finally {
2015 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
Wink Saville36469e72014-06-11 15:17:00 -07002018
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002019 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002020 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002021 /*
2022 * If any of the Radios are available, it will need to be
2023 * shutdown. So return true if any Radio is available.
2024 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002025 final long identity = Binder.clearCallingIdentity();
2026 try {
2027 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2028 Phone phone = PhoneFactory.getPhone(i);
2029 if (phone != null && phone.isRadioAvailable()) return true;
2030 }
2031 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2032 return false;
2033 } finally {
2034 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002035 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002036 }
2037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002038 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002039 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040 enforceModifyPermission();
2041
2042 final long identity = Binder.clearCallingIdentity();
2043 try {
2044 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2045 logv("Shutting down Phone " + i);
2046 shutdownRadioUsingPhoneId(i);
2047 }
2048 } finally {
2049 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002050 }
2051 }
2052
2053 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002054 Phone phone = PhoneFactory.getPhone(phoneId);
2055 if (phone != null && phone.isRadioAvailable()) {
2056 phone.shutdownRadio();
2057 }
2058 }
2059
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002060 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002061 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002062
2063 final long identity = Binder.clearCallingIdentity();
2064 try {
2065 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2066 if (defaultPhone != null) {
2067 defaultPhone.setRadioPower(turnOn);
2068 return true;
2069 } else {
2070 loge("There's no default phone.");
2071 return false;
2072 }
2073 } finally {
2074 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002075 }
Wink Saville36469e72014-06-11 15:17:00 -07002076 }
2077
Wink Savilleb564aae2014-10-23 10:18:09 -07002078 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080
2081 final long identity = Binder.clearCallingIdentity();
2082 try {
2083 final Phone phone = getPhone(subId);
2084 if (phone != null) {
2085 phone.setRadioPower(turnOn);
2086 return true;
2087 } else {
2088 return false;
2089 }
2090 } finally {
2091 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 }
2094
Wink Saville36469e72014-06-11 15:17:00 -07002095 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002096 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 public boolean enableDataConnectivity() {
2098 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099
2100 final long identity = Binder.clearCallingIdentity();
2101 try {
2102 int subId = mSubscriptionController.getDefaultDataSubId();
2103 final Phone phone = getPhone(subId);
2104 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002105 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002106 return true;
2107 } else {
2108 return false;
2109 }
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 }
2114
Wink Saville36469e72014-06-11 15:17:00 -07002115 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002116 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002117 public boolean disableDataConnectivity() {
2118 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002119
2120 final long identity = Binder.clearCallingIdentity();
2121 try {
2122 int subId = mSubscriptionController.getDefaultDataSubId();
2123 final Phone phone = getPhone(subId);
2124 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002125 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002126 return true;
2127 } else {
2128 return false;
2129 }
2130 } finally {
2131 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002132 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 }
2134
Sanket Padawe356d7632015-06-22 14:03:32 -07002135 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002136 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002137 final long identity = Binder.clearCallingIdentity();
2138 try {
2139 final Phone phone = getPhone(subId);
2140 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002141 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002142 } else {
2143 return false;
2144 }
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002148 }
2149
2150 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002151 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002152 }
2153
pkanwarae03a6b2016-11-06 20:37:09 -08002154 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002155 enforceCallPermission();
2156
2157 final long identity = Binder.clearCallingIdentity();
2158 try {
2159 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2160 return;
2161 }
2162 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2163 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2164 } finally {
2165 Binder.restoreCallingIdentity(identity);
2166 }
pkanwar32d516d2016-10-14 19:37:38 -07002167 };
2168
Wink Savilleb564aae2014-10-23 10:18:09 -07002169 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171
2172 final long identity = Binder.clearCallingIdentity();
2173 try {
2174 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2175 return false;
2176 }
2177 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2178 } finally {
2179 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
2182
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002184 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002185 }
2186
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002187 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002188 final long identity = Binder.clearCallingIdentity();
2189 try {
2190 Phone phone = PhoneFactory.getPhone(slotIndex);
2191 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2192 PhoneConstantConversions.convertCallState(phone.getState());
2193 } finally {
2194 Binder.restoreCallingIdentity(identity);
2195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 }
2197
Sanket Padawe356d7632015-06-22 14:03:32 -07002198 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002199 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002200 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2201 }
2202
2203 @Override
2204 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205 final long identity = Binder.clearCallingIdentity();
2206 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002207 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002208 if (phone != null) {
2209 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2210 } else {
2211 return PhoneConstantConversions.convertDataState(
2212 PhoneConstants.DataState.DISCONNECTED);
2213 }
2214 } finally {
2215 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218
Sanket Padawe356d7632015-06-22 14:03:32 -07002219 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002220 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002221 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2222 }
2223
2224 @Override
2225 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002226 final long identity = Binder.clearCallingIdentity();
2227 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002228 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002229 if (phone != null) {
2230 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2231 } else {
2232 return TelephonyManager.DATA_ACTIVITY_NONE;
2233 }
2234 } finally {
2235 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 }
2238
2239 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002240 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002241 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002242 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002243
2244 LocationAccessPolicy.LocationPermissionResult locationResult =
2245 LocationAccessPolicy.checkLocationPermission(mApp,
2246 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2247 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002248 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002249 .setCallingPid(Binder.getCallingPid())
2250 .setCallingUid(Binder.getCallingUid())
2251 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002252 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002253 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2254 .build());
2255 switch (locationResult) {
2256 case DENIED_HARD:
2257 throw new SecurityException("Not allowed to access cell location");
2258 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002259 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2260 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 }
2262
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264 final long identity = Binder.clearCallingIdentity();
2265 try {
2266 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002267 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002268 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002269 } finally {
2270 Binder.restoreCallingIdentity(identity);
2271 }
Svetoslav64fad262015-04-14 14:35:21 -07002272 }
2273
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002275 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2276 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002277 if (!TextUtils.isEmpty(callingPackage)) {
2278 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2280 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002281 return "";
2282 }
2283 }
2284
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002285 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2286 // registered cell info, so return a NULL country instead.
2287 final long identity = Binder.clearCallingIdentity();
2288 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002289 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2290 // Get default phone in this case.
2291 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2292 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002293 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002294 // Todo: fix this when we can get the actual cellular network info when the device
2295 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002296 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002297 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2298 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002299 return "";
2300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002301 Phone phone = PhoneFactory.getPhone(phoneId);
2302 if (phone != null) {
2303 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002304 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305 if (sst != null) {
2306 LocaleTracker lt = sst.getLocaleTracker();
2307 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002308 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2309 return lt.getCurrentCountry();
2310 } else if (emergencyNumberTracker != null) {
2311 return emergencyNumberTracker.getEmergencyCountryIso();
2312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002313 }
2314 }
2315 }
2316 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002317 } finally {
2318 Binder.restoreCallingIdentity(identity);
2319 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002320 }
2321
2322 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002324 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002325 }
2326
Sanket Padawe356d7632015-06-22 14:03:32 -07002327 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002328 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 mApp.enforceCallingOrSelfPermission(
2330 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002331
2332 final long identity = Binder.clearCallingIdentity();
2333 try {
2334 final Phone phone = getPhone(subId);
2335 if (phone != null) {
2336 phone.enableLocationUpdates();
2337 }
2338 } finally {
2339 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 }
2342
2343 @Override
2344 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002345 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002346 }
2347
Sanket Padawe356d7632015-06-22 14:03:32 -07002348 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002349 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 mApp.enforceCallingOrSelfPermission(
2351 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002352
2353 final long identity = Binder.clearCallingIdentity();
2354 try {
2355 final Phone phone = getPhone(subId);
2356 if (phone != null) {
2357 phone.disableLocationUpdates();
2358 }
2359 } finally {
2360 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 }
2363
Nathan Harold31d7ff32018-10-15 20:20:30 -07002364 /**
2365 * Returns the target SDK version number for a given package name.
2366 *
Nathan Haroldec184742019-07-10 17:04:16 -07002367 * This call MUST be invoked before clearing the calling UID.
2368 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002369 * @return target SDK if the package is found or INT_MAX.
2370 */
2371 private int getTargetSdk(String packageName) {
2372 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002373 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002374 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002375 if (ai != null) return ai.targetSdkVersion;
2376 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002377 loge("Failed to get package info for pkg="
2378 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002379 }
2380 return Integer.MAX_VALUE;
2381 }
2382
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 @Override
2384 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002385 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2386 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002387 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002388 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2389 throw new SecurityException(
2390 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2391 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002392
Jordan Liu1617b712019-07-10 15:06:26 -07002393 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2395 return null;
2396 }
Svetoslav64fad262015-04-14 14:35:21 -07002397
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002398 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002400 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002401 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402
Nathan Haroldf180aac2018-06-01 18:43:55 -07002403 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2404 for (CellInfo ci : info) {
2405 if (ci instanceof CellInfoGsm) {
2406 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2407 } else if (ci instanceof CellInfoWcdma) {
2408 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002411 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 }
2413
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002414 private List<CellInfo> getCachedCellInfo() {
2415 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2416 for (Phone phone : PhoneFactory.getPhones()) {
2417 List<CellInfo> info = phone.getAllCellInfo();
2418 if (info != null) cellInfos.addAll(info);
2419 }
2420 return cellInfos;
2421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422
2423 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002424 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002425 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002426 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002427
2428 LocationAccessPolicy.LocationPermissionResult locationResult =
2429 LocationAccessPolicy.checkLocationPermission(mApp,
2430 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2431 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002432 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002433 .setCallingPid(Binder.getCallingPid())
2434 .setCallingUid(Binder.getCallingUid())
2435 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002436 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002437 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2438 .build());
2439 switch (locationResult) {
2440 case DENIED_HARD:
2441 throw new SecurityException("Not allowed to access cell info");
2442 case DENIED_SOFT:
2443 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 }
2445
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002446 final int targetSdk = getTargetSdk(callingPackage);
2447 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2448 return getCachedCellInfo();
2449 }
2450
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002451 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002452 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453 final long identity = Binder.clearCallingIdentity();
2454 try {
2455 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2456 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002457 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002458 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 if (info != null) cellInfos.addAll(info);
2460 }
2461 return cellInfos;
2462 } finally {
2463 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465 }
2466
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002467 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002468 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2469 String callingFeatureId) {
2470 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2471 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002472 }
2473
2474 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002475 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2476 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002477 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002478 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002479 }
2480
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002481 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2482 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002483 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002484 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002485
2486 LocationAccessPolicy.LocationPermissionResult locationResult =
2487 LocationAccessPolicy.checkLocationPermission(mApp,
2488 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2489 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002490 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002491 .setCallingPid(Binder.getCallingPid())
2492 .setCallingUid(Binder.getCallingUid())
2493 .setMethod("requestCellInfoUpdate")
2494 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2495 .build());
2496 switch (locationResult) {
2497 case DENIED_HARD:
2498 throw new SecurityException("Not allowed to access cell info");
2499 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002500 try {
2501 cb.onCellInfo(new ArrayList<CellInfo>());
2502 } catch (RemoteException re) {
2503 // Drop without consequences
2504 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002505 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002506 }
2507
Nathan Harolda939a962019-05-09 10:13:47 -07002508
2509 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002510 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2511
2512 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2513 }
2514
2515 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002517 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002518 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002522 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523 } finally {
2524 Binder.restoreCallingIdentity(identity);
2525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526 }
2527
Shishir Agrawala9f32182016-04-12 12:00:16 -07002528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002529 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002530 Phone phone = PhoneFactory.getPhone(slotIndex);
2531 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002532 return null;
2533 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002534 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002535 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002536 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002537 return null;
2538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002539
2540 final long identity = Binder.clearCallingIdentity();
2541 try {
2542 return phone.getImei();
2543 } finally {
2544 Binder.restoreCallingIdentity(identity);
2545 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002546 }
2547
2548 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002549 public String getTypeAllocationCodeForSlot(int slotIndex) {
2550 Phone phone = PhoneFactory.getPhone(slotIndex);
2551 String tac = null;
2552 if (phone != null) {
2553 String imei = phone.getImei();
2554 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2555 }
2556 return tac;
2557 }
2558
2559 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002560 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002561 Phone phone = PhoneFactory.getPhone(slotIndex);
2562 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002563 return null;
2564 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002565
Jeff Davidson913390f2018-02-23 17:11:49 -08002566 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002567 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002568 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002569 return null;
2570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571
2572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 return phone.getMeid();
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
2577 }
Jack Yu2af8d712017-03-15 17:14:14 -07002578 }
2579
2580 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002581 public String getManufacturerCodeForSlot(int slotIndex) {
2582 Phone phone = PhoneFactory.getPhone(slotIndex);
2583 String manufacturerCode = null;
2584 if (phone != null) {
2585 String meid = phone.getMeid();
2586 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2587 }
2588 return manufacturerCode;
2589 }
2590
2591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002592 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2593 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002594 Phone phone = PhoneFactory.getPhone(slotIndex);
2595 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002596 return null;
2597 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002598 int subId = phone.getSubId();
2599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002600 mApp, subId, callingPackage, callingFeatureId,
2601 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002602 return null;
2603 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604
2605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 return phone.getDeviceSvn();
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
2610 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002611 }
2612
fionaxu43304da2017-11-27 22:51:16 -08002613 @Override
2614 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 final Phone phone = getPhone(subId);
2618 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
2621 }
fionaxu43304da2017-11-27 22:51:16 -08002622 }
2623
2624 @Override
2625 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 final long identity = Binder.clearCallingIdentity();
2627 try {
2628 final Phone phone = getPhone(subId);
2629 return phone == null ? null : phone.getCarrierName();
2630 } finally {
2631 Binder.restoreCallingIdentity(identity);
2632 }
fionaxu43304da2017-11-27 22:51:16 -08002633 }
2634
calvinpanffe225e2018-11-01 19:43:06 +08002635 @Override
chen xu0026ca62019-03-06 15:28:50 -08002636 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 final Phone phone = getPhone(subId);
2640 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002641 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002642 } finally {
2643 Binder.restoreCallingIdentity(identity);
2644 }
2645 }
2646
2647 @Override
chen xu0026ca62019-03-06 15:28:50 -08002648 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002649 final long identity = Binder.clearCallingIdentity();
2650 try {
2651 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002652 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002653 } finally {
2654 Binder.restoreCallingIdentity(identity);
2655 }
2656 }
2657
chen xu651eec72018-11-11 19:03:44 -08002658 @Override
chen xu864e11c2018-12-06 22:10:03 -08002659 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2660 if (!isSubscriptionMccMnc) {
2661 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2662 }
chen xu651eec72018-11-11 19:03:44 -08002663 final Phone phone = PhoneFactory.getPhone(slotIndex);
2664 if (phone == null) {
2665 return TelephonyManager.UNKNOWN_CARRIER_ID;
2666 }
2667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
2672 }
2673 }
2674
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 //
2676 // Internal helper methods.
2677 //
2678
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002679 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2681 *
2682 * @throws SecurityException if the caller does not have the required permission
2683 */
2684 private void enforceModifyPermission() {
2685 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2686 }
2687
Shuo Qiancd19c462020-01-16 20:51:11 -08002688 /**
2689 * Make sure the caller is system.
2690 *
2691 * @throws SecurityException if the caller is not system.
2692 */
2693 private void enforceSystemCaller() {
2694 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2695 throw new SecurityException("Caller must be system");
2696 }
2697 }
2698
Shuo Qian3b6ee772019-11-13 17:43:31 -08002699 private void enforceActiveEmergencySessionPermission() {
2700 mApp.enforceCallingOrSelfPermission(
2701 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2702 }
2703
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 /**
2705 * Make sure the caller has the CALL_PHONE permission.
2706 *
2707 * @throws SecurityException if the caller does not have the required permission
2708 */
2709 private void enforceCallPermission() {
2710 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2711 }
2712
paulhu5a773602019-08-23 19:17:33 +08002713 private void enforceSettingsPermission() {
2714 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002715 }
2716
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 private String createTelUrl(String number) {
2718 if (TextUtils.isEmpty(number)) {
2719 return null;
2720 }
2721
Jake Hambye994d462014-02-03 13:10:13 -08002722 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 }
2724
Ihab Awadf9e92732013-12-05 18:02:52 -08002725 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2727 }
2728
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002729 private static void logv(String msg) {
2730 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2731 }
2732
Ihab Awadf9e92732013-12-05 18:02:52 -08002733 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2735 }
2736
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002737 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002739 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002740 }
2741
Sanket Padawe356d7632015-06-22 14:03:32 -07002742 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002743 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744 final long identity = Binder.clearCallingIdentity();
2745 try {
2746 final Phone phone = PhoneFactory.getPhone(slotIndex);
2747 if (phone == null) {
2748 return PhoneConstants.PHONE_TYPE_NONE;
2749 } else {
2750 return phone.getPhoneType();
2751 }
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002755 }
2756
2757 /**
2758 * Returns the CDMA ERI icon index to display
2759 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002761 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2762 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2763 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002764 }
2765
Sanket Padawe356d7632015-06-22 14:03:32 -07002766 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002767 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2768 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002770 mApp, subId, callingPackage, callingFeatureId,
2771 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002772 return -1;
2773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774
2775 final long identity = Binder.clearCallingIdentity();
2776 try {
2777 final Phone phone = getPhone(subId);
2778 if (phone != null) {
2779 return phone.getCdmaEriIconIndex();
2780 } else {
2781 return -1;
2782 }
2783 } finally {
2784 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002786 }
2787
2788 /**
2789 * Returns the CDMA ERI icon mode,
2790 * 0 - ON
2791 * 1 - FLASHING
2792 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002793 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002794 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2795 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2796 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002797 }
2798
Sanket Padawe356d7632015-06-22 14:03:32 -07002799 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002800 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2801 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002803 mApp, subId, callingPackage, callingFeatureId,
2804 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002805 return -1;
2806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807
2808 final long identity = Binder.clearCallingIdentity();
2809 try {
2810 final Phone phone = getPhone(subId);
2811 if (phone != null) {
2812 return phone.getCdmaEriIconMode();
2813 } else {
2814 return -1;
2815 }
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 }
2820
2821 /**
2822 * Returns the CDMA ERI text,
2823 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002824 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002825 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2826 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2827 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002828 }
2829
Sanket Padawe356d7632015-06-22 14:03:32 -07002830 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002831 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2832 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002834 mApp, subId, callingPackage, callingFeatureId,
2835 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002836 return null;
2837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838
2839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 final Phone phone = getPhone(subId);
2842 if (phone != null) {
2843 return phone.getCdmaEriText();
2844 } else {
2845 return null;
2846 }
2847 } finally {
2848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 }
2851
2852 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002853 * Returns the CDMA MDN.
2854 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002855 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002856 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2858 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859
2860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002863 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 return phone.getLine1Number();
2865 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002866 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 return null;
2868 }
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002871 }
2872 }
2873
2874 /**
2875 * Returns the CDMA MIN.
2876 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002877 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002878 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2880 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881
2882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 final Phone phone = getPhone(subId);
2885 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2886 return phone.getCdmaMin();
2887 } else {
2888 return null;
2889 }
2890 } finally {
2891 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002892 }
2893 }
2894
Hall Liud892bec2018-11-30 14:51:45 -08002895 @Override
2896 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2897 INumberVerificationCallback callback, String callingPackage) {
2898 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2899 != PERMISSION_GRANTED) {
2900 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2901 }
2902 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2903
2904 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2905 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2906 throw new SecurityException("Calling package must be configured in the device config");
2907 }
2908
2909 if (range == null) {
2910 throw new NullPointerException("Range must be non-null");
2911 }
2912
2913 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002914 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002915
2916 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2917 }
2918
Junda Liuca05d5d2014-08-14 22:36:34 -07002919 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 * Returns true if CDMA provisioning needs to run.
2921 */
2922 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923 final long identity = Binder.clearCallingIdentity();
2924 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002925 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926 } finally {
2927 Binder.restoreCallingIdentity(identity);
2928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
2930
2931 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002932 * Sets the voice mail number of a given subId.
2933 */
2934 @Override
2935 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002936 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2937 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938
2939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2942 new Pair<String, String>(alphaTag, number), new Integer(subId));
2943 return success;
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
2946 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002947 }
2948
Ta-wei Yen87c49842016-05-13 21:19:52 -07002949 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002950 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2951 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002952 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2953 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002954 if (!TextUtils.equals(callingPackage, systemDialer)) {
2955 throw new SecurityException("caller must be system dialer");
2956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957
2958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2961 if (phoneAccountHandle == null) {
2962 return null;
2963 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002964 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965 } finally {
2966 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002967 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002968 }
2969
2970 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002971 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2972 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002973 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002974 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002975 mApp, subId, callingPackage, callingFeatureId,
2976 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002977 return null;
2978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002980 final long identity = Binder.clearCallingIdentity();
2981 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002982 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002986 }
2987
2988 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002989 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2990 VisualVoicemailSmsFilterSettings settings) {
2991 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992
2993 final long identity = Binder.clearCallingIdentity();
2994 try {
2995 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002996 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 } finally {
2998 Binder.restoreCallingIdentity(identity);
2999 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003000 }
3001
3002 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003003 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3004 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005
3006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003009 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003010 } finally {
3011 Binder.restoreCallingIdentity(identity);
3012 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003013 }
3014
3015 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003016 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3017 String callingPackage, int subId) {
3018 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019
3020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003023 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003027 }
3028
3029 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003030 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003032
3033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003036 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003040 }
3041
3042 @Override
3043 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3044 String number, int port, String text, PendingIntent sentIntent) {
3045 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003046 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003047 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003048 SmsController smsController = PhoneFactory.getSmsController();
3049 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3050 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003051 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003052
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003053 /**
fionaxu0152e512016-11-14 13:36:14 -08003054 * Sets the voice activation state of a given subId.
3055 */
3056 @Override
3057 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3059 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 final Phone phone = getPhone(subId);
3064 if (phone != null) {
3065 phone.setVoiceActivationState(activationState);
3066 } else {
3067 loge("setVoiceActivationState fails with invalid subId: " + subId);
3068 }
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003071 }
3072 }
3073
3074 /**
3075 * Sets the data activation state of a given subId.
3076 */
3077 @Override
3078 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3080 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081
3082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 final Phone phone = getPhone(subId);
3085 if (phone != null) {
3086 phone.setDataActivationState(activationState);
3087 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003088 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089 }
3090 } finally {
3091 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003092 }
3093 }
3094
3095 /**
3096 * Returns the voice activation state of a given subId.
3097 */
3098 @Override
3099 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003100 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101
fionaxu0152e512016-11-14 13:36:14 -08003102 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 if (phone != null) {
3106 return phone.getVoiceActivationState();
3107 } else {
3108 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3109 }
3110 } finally {
3111 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003112 }
3113 }
3114
3115 /**
3116 * Returns the data activation state of a given subId.
3117 */
3118 @Override
3119 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003120 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003121
fionaxu0152e512016-11-14 13:36:14 -08003122 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 if (phone != null) {
3126 return phone.getDataActivationState();
3127 } else {
3128 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3129 }
3130 } finally {
3131 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003132 }
3133 }
3134
3135 /**
Wink Saville36469e72014-06-11 15:17:00 -07003136 * Returns the unread count of voicemails for a subId
3137 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003138 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003139 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3140 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003142 mApp, subId, callingPackage, callingFeatureId,
3143 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003144 return 0;
3145 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 final Phone phone = getPhone(subId);
3149 if (phone != null) {
3150 return phone.getVoiceMessageCount();
3151 } else {
3152 return 0;
3153 }
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 }
3158
3159 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003160 * returns true, if the device is in a state where both voice and data
3161 * are supported simultaneously. This can change based on location or network condition.
3162 */
3163 @Override
3164 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 final Phone phone = getPhone(subId);
3168 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003172 }
3173
3174 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003175 * Send the dialer code if called from the current default dialer or the caller has
3176 * carrier privilege.
3177 * @param inputCode The dialer code to send
3178 */
3179 @Override
3180 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003181 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003182 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003183 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3184 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003185 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003186 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003187 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003188 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189
3190 final long identity = Binder.clearCallingIdentity();
3191 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003192 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
fionaxu235cc5e2017-03-06 22:25:57 -08003196 }
3197
Pengquan Menga1bb6272018-09-06 09:59:22 -07003198 @Override
3199 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003200 TelephonyPermissions
3201 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3202 mApp, subId, "getNetworkSelectionMode");
3203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 if (!isActiveSubscription(subId)) {
3206 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3207 }
3208 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003211 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003212 }
3213
Brad Ebinger35c841c2018-10-01 10:40:55 -07003214 @Override
Sarah Chin0605abf2019-12-06 10:24:18 -08003215 public PhoneCapability getPhoneCapability(int subId, String callingPackage,
3216 String callingFeatureId) {
3217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3218 mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) {
3219 return null;
3220 }
3221 final long identity = Binder.clearCallingIdentity();
3222 try {
3223 return mPhoneConfigurationManager.getStaticPhoneCapability();
3224 } finally {
3225 Binder.restoreCallingIdentity(identity);
3226 }
3227 }
3228
3229 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003230 public boolean isInEmergencySmsMode() {
3231 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3232 final long identity = Binder.clearCallingIdentity();
3233 try {
3234 for (Phone phone : PhoneFactory.getPhones()) {
3235 if (phone.isInEmergencySmsMode()) {
3236 return true;
3237 }
3238 }
3239 } finally {
3240 Binder.restoreCallingIdentity(identity);
3241 }
3242 return false;
3243 }
3244
shilu366312e2019-12-17 09:28:10 -08003245 /**
3246 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3247 * @param subId The subscription to use to check the configuration.
3248 * @param c The callback that will be used to send the result.
3249 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003250 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003251 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3252 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003253 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3254 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003255
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003256 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3257 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3258 "IMS not available on device.");
3259 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003260 final long token = Binder.clearCallingIdentity();
3261 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003262 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003263 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003264 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003265 } catch (ImsException e) {
3266 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003267 } finally {
3268 Binder.restoreCallingIdentity(token);
3269 }
3270 }
3271
shilu366312e2019-12-17 09:28:10 -08003272 /**
3273 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3274 * @param subId The subscription to use to check the configuration.
3275 * @param c The callback that will be used to send the result.
3276 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003277 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003278 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003279 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3280 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003281 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3282 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3283 }
Meng Wangafbc5852019-09-19 17:37:13 -07003284 final long token = Binder.clearCallingIdentity();
3285 try {
3286 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3287 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3288 .removeRegistrationCallbackForSubscription(c, subId);
3289 } catch (ImsException e) {
3290 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3291 + "is inactive, ignoring unregister.");
3292 // If the subscription is no longer active, just return, since the callback
3293 // will already have been removed internally.
3294 } finally {
3295 Binder.restoreCallingIdentity(token);
3296 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003297 }
3298
Brad Ebingera34a6c22019-10-22 17:36:18 -07003299 /**
3300 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3301 */
3302 @Override
3303 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3304 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3305 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3306 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3307 "IMS not available on device.");
3308 }
3309 final long token = Binder.clearCallingIdentity();
3310 try {
3311 Phone phone = getPhone(subId);
3312 if (phone == null) {
3313 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3314 + subId + "'");
3315 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3316 }
3317 phone.getImsRegistrationState(regState -> {
3318 try {
3319 consumer.accept((regState == null)
3320 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3321 } catch (RemoteException e) {
3322 // Ignore if the remote process is no longer available to call back.
3323 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3324 }
3325 });
3326 } finally {
3327 Binder.restoreCallingIdentity(token);
3328 }
3329 }
3330
3331 /**
3332 * Get the transport type for the IMS service registration state.
3333 */
3334 @Override
3335 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003336 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3337 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003338 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3339 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3340 "IMS not available on device.");
3341 }
3342 final long token = Binder.clearCallingIdentity();
3343 try {
3344 Phone phone = getPhone(subId);
3345 if (phone == null) {
3346 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3347 + subId + "'");
3348 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3349 }
3350 phone.getImsRegistrationTech(regTech -> {
3351 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3352 int regTechConverted = (regTech == null)
3353 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3354 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3355 regTechConverted);
3356 try {
3357 consumer.accept(regTechConverted);
3358 } catch (RemoteException e) {
3359 // Ignore if the remote process is no longer available to call back.
3360 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3361 }
3362 });
3363 } finally {
3364 Binder.restoreCallingIdentity(token);
3365 }
3366 }
3367
shilu366312e2019-12-17 09:28:10 -08003368 /**
3369 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3370 * @param subId The subscription to use to check the configuration.
3371 * @param c The callback that will be used to send the result.
3372 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003373 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003374 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3375 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003376 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3377 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003378 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3379 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3380 "IMS not available on device.");
3381 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003382 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3383 final long token = Binder.clearCallingIdentity();
3384 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003385 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003386 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003387 } catch (ImsException e) {
3388 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003389 } finally {
3390 Binder.restoreCallingIdentity(token);
3391 }
3392 }
3393
shilu366312e2019-12-17 09:28:10 -08003394 /**
3395 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3396 * @param subId The subscription to use to check the configuration.
3397 * @param c The callback that will be used to send the result.
3398 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003399 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003400 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003401 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3402 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003403 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3404 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3405 }
Meng Wangafbc5852019-09-19 17:37:13 -07003406
3407 final long token = Binder.clearCallingIdentity();
3408 try {
3409 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3410 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003411 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003412 } catch (ImsException e) {
3413 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3414 + "is inactive, ignoring unregister.");
3415 // If the subscription is no longer active, just return, since the callback
3416 // will already have been removed internally.
3417 } finally {
3418 Binder.restoreCallingIdentity(token);
3419 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003420 }
3421
3422 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003423 public boolean isCapable(int subId, int capability, int regTech) {
3424 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003425 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3426 final long token = Binder.clearCallingIdentity();
3427 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003428 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003429 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003430 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003431 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3432 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003433 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003434 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3435 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003436 } finally {
3437 Binder.restoreCallingIdentity(token);
3438 }
3439 }
3440
3441 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003442 public boolean isAvailable(int subId, int capability, int regTech) {
3443 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003444 final long token = Binder.clearCallingIdentity();
3445 try {
3446 Phone phone = getPhone(subId);
3447 if (phone == null) return false;
3448 return phone.isImsCapabilityAvailable(capability, regTech);
3449 } finally {
3450 Binder.restoreCallingIdentity(token);
3451 }
3452 }
3453
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003454 /**
3455 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3456 * subscription.
3457 * @param subId The subscription to use to check the configuration.
3458 * @param callback The callback that will be used to send the result.
3459 * @param capability The MmTelFeature capability that will be used to send the result.
3460 * @param transportType The transport type of the MmTelFeature capability.
3461 */
3462 @Override
3463 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3464 int transportType) {
3465 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3466 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3467 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3468 "IMS not available on device.");
3469 }
3470 final long token = Binder.clearCallingIdentity();
3471 try {
3472 int slotId = getSlotIndex(subId);
3473 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3474 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3475 + subId + "'");
3476 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3477 }
3478 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3479 transportType, aBoolean -> {
3480 try {
3481 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3482 } catch (RemoteException e) {
3483 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3484 + "running. Ignore");
3485 }
3486 });
3487 } finally {
3488 Binder.restoreCallingIdentity(token);
3489 }
3490 }
3491
shilu366312e2019-12-17 09:28:10 -08003492 /**
3493 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3494 * @param subId The subscription to use to check the configuration.
3495 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003496 @Override
3497 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003498 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3499 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003500
Brad Ebinger35c841c2018-10-01 10:40:55 -07003501 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3502 final long token = Binder.clearCallingIdentity();
3503 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003504 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003505 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003506 } catch (ImsException e) {
3507 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003508 } finally {
3509 Binder.restoreCallingIdentity(token);
3510 }
3511 }
3512
3513 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003514 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003516 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003517 final long identity = Binder.clearCallingIdentity();
3518 try {
3519 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003520 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003521 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003522 } catch (ImsException e) {
3523 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003524 } finally {
3525 Binder.restoreCallingIdentity(identity);
3526 }
3527 }
3528
shilu366312e2019-12-17 09:28:10 -08003529 /**
3530 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3531 * @param subId The subscription to use to check the configuration.
3532 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003533 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003534 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003535 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3536 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003540 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3541 } catch (ImsException e) {
3542 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003543 } finally {
3544 Binder.restoreCallingIdentity(identity);
3545 }
3546 }
3547
3548 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003549 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003551 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003555 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003556 } catch (ImsException e) {
3557 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003558 } finally {
3559 Binder.restoreCallingIdentity(identity);
3560 }
3561 }
3562
shilu366312e2019-12-17 09:28:10 -08003563 /**
3564 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3565 * @param subId The subscription to use to check the configuration.
3566 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003567 @Override
3568 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003569 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3570 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003571 final long identity = Binder.clearCallingIdentity();
3572 try {
3573 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003574 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003576 } catch (ImsException e) {
3577 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003578 } finally {
3579 Binder.restoreCallingIdentity(identity);
3580 }
3581 }
3582
3583 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003584 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003586 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003587 final long identity = Binder.clearCallingIdentity();
3588 try {
3589 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003590 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003591 } catch (ImsException e) {
3592 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003593 } finally {
3594 Binder.restoreCallingIdentity(identity);
3595 }
3596 }
3597
shilu366312e2019-12-17 09:28:10 -08003598 /**
3599 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3600 * @param subId The subscription to use to check the configuration.
3601 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 @Override
3603 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003604 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3605 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003609 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003610 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003611 } catch (ImsException e) {
3612 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003613 } finally {
3614 Binder.restoreCallingIdentity(identity);
3615 }
3616 }
3617
3618 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003619 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003621 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003625 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003626 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003627 } catch (ImsException e) {
3628 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003629 } finally {
3630 Binder.restoreCallingIdentity(identity);
3631 }
3632 }
3633
3634 @Override
3635 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3637 "setVoWiFiNonPersistent");
3638 final long identity = Binder.clearCallingIdentity();
3639 try {
3640 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003641 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003642 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003643 } catch (ImsException e) {
3644 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003645 } finally {
3646 Binder.restoreCallingIdentity(identity);
3647 }
3648 }
3649
shilu366312e2019-12-17 09:28:10 -08003650 /**
3651 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3652 * @param subId The subscription to use to check the configuration.
3653 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003654 @Override
3655 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003656 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3657 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003661 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003662 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003663 } catch (ImsException e) {
3664 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003665 } finally {
3666 Binder.restoreCallingIdentity(identity);
3667 }
3668 }
3669
3670 @Override
3671 public void setVoWiFiModeSetting(int subId, int mode) {
3672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3673 "setVoWiFiModeSetting");
3674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003677 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003678 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003679 } catch (ImsException e) {
3680 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003681 } finally {
3682 Binder.restoreCallingIdentity(identity);
3683 }
3684 }
3685
3686 @Override
3687 public int getVoWiFiRoamingModeSetting(int subId) {
3688 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003692 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003693 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003694 } catch (ImsException e) {
3695 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003696 } finally {
3697 Binder.restoreCallingIdentity(identity);
3698 }
3699 }
3700
3701 @Override
3702 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3704 "setVoWiFiRoamingModeSetting");
3705 final long identity = Binder.clearCallingIdentity();
3706 try {
3707 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003708 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003709 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003710 } catch (ImsException e) {
3711 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
3715 }
3716
3717 @Override
3718 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3720 "setRttCapabilityEnabled");
3721 final long identity = Binder.clearCallingIdentity();
3722 try {
3723 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003724 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3725 } catch (ImsException e) {
3726 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
3730 }
3731
shilu366312e2019-12-17 09:28:10 -08003732 /**
3733 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3734 * @param subId The subscription to use to check the configuration.
3735 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003736 @Override
3737 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003738 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3739 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003743 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003744 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003745 } catch (ImsException e) {
3746 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
3750 }
3751
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003752 @Override
3753 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3754 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3755 final long identity = Binder.clearCallingIdentity();
3756 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003757 if (!isImsAvailableOnDevice()) {
3758 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3759 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003760 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003761 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003762 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003763 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003764 } catch (ImsException e) {
3765 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003766 } finally {
3767 Binder.restoreCallingIdentity(identity);
3768 }
3769 }
3770
3771 @Override
3772 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3773 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3774 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003775 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3776 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3777 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003778 try {
3779 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003780 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003781 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003782 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003783 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3784 + "is inactive, ignoring unregister.");
3785 // If the subscription is no longer active, just return, since the callback will already
3786 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003787 } finally {
3788 Binder.restoreCallingIdentity(identity);
3789 }
3790 }
3791
allenwtsu99c623b2020-01-03 18:24:23 +08003792
3793 private void checkModifyPhoneStatePermission(int subId, String message) {
3794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3795 message);
3796 }
3797
3798 private boolean isImsProvisioningRequired(int subId, int capability,
3799 boolean isMmtelCapability) {
3800 Phone phone = getPhone(subId);
3801 if (phone == null) {
3802 loge("phone instance null for subid " + subId);
3803 return false;
3804 }
3805 if (isMmtelCapability) {
3806 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3807 return false;
3808 }
3809 } else {
3810 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3811 return false;
3812 }
3813 }
3814 return true;
3815 }
3816
3817 @Override
3818 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3819 boolean isProvisioned) {
3820 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3821
3822 final long identity = Binder.clearCallingIdentity();
3823 try {
3824 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3825 if (!isImsProvisioningRequired(subId, capability, false)) {
3826 return;
3827 }
3828
3829 // this capability requires provisioning, route to the correct API.
3830 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3831 switch (capability) {
3832 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3833 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3834 ims.setEabProvisioned(isProvisioned);
3835 break;
3836 default: {
3837 throw new IllegalArgumentException("Tried to set provisioning for "
3838 + "rcs capability '" + capability + "', which does not require "
3839 + "provisioning.");
3840 }
3841 }
3842 } finally {
3843 Binder.restoreCallingIdentity(identity);
3844 }
3845
3846 }
3847
3848
3849 @Override
3850 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3851 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3852 final long identity = Binder.clearCallingIdentity();
3853 try {
3854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3855 if (!isImsProvisioningRequired(subId, capability, false)) {
3856 return true;
3857 }
3858
3859 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3860 switch (capability) {
3861 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3862 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3863 return ims.isEabProvisionedOnDevice();
3864
3865 default: {
3866 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3867 + "capability '" + capability + "', which does not require "
3868 + "provisioning.");
3869 }
3870 }
3871
3872 } finally {
3873 Binder.restoreCallingIdentity(identity);
3874 }
3875 }
3876
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003877 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003878 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3879 boolean isProvisioned) {
3880 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3881 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3882 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3883 }
allenwtsu99c623b2020-01-03 18:24:23 +08003884 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003885 final long identity = Binder.clearCallingIdentity();
3886 try {
3887 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003888 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003889 return;
3890 }
3891
3892 // this capability requires provisioning, route to the correct API.
3893 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3894 switch (capability) {
3895 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3896 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3897 ims.setVolteProvisioned(isProvisioned);
3898 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3899 ims.setWfcProvisioned(isProvisioned);
3900 }
3901 break;
3902 }
3903 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3904 // There is currently no difference in VT provisioning type.
3905 ims.setVtProvisioned(isProvisioned);
3906 break;
3907 }
3908 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3909 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3910 // change the capability of the feature instead if needed.
3911 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3912 == isProvisioned) {
3913 // No change in provisioning.
3914 return;
3915 }
3916 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3917 try {
3918 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003919 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003920 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3921 + ", Exception" + e.getMessage());
3922 }
3923 break;
3924 }
3925 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003926 throw new IllegalArgumentException("Tried to set provisioning for "
3927 + "MmTel capability '" + capability + "', which does not require "
3928 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003929 }
3930 }
3931
3932 } finally {
3933 Binder.restoreCallingIdentity(identity);
3934 }
3935 }
3936
3937 @Override
3938 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3939 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3940 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3941 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3942 }
3943 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3944 final long identity = Binder.clearCallingIdentity();
3945 try {
3946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003947 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003948 return true;
3949 }
3950
3951 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3952 switch (capability) {
3953 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3954 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3955 return ims.isVolteProvisionedOnDevice();
3956 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3957 return ims.isWfcProvisionedOnDevice();
3958 }
3959 // This should never happen, since we are checking tech above to make sure it
3960 // is either LTE or IWLAN.
3961 throw new IllegalArgumentException("Invalid radio technology for voice "
3962 + "capability.");
3963 }
3964 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3965 // There is currently no difference in VT provisioning type.
3966 return ims.isVtProvisionedOnDevice();
3967 }
3968 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3969 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3970 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3971 }
3972 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003973 throw new IllegalArgumentException(
3974 "Tried to get provisioning for MmTel capability '" + capability
3975 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003976 }
3977 }
3978
3979 } finally {
3980 Binder.restoreCallingIdentity(identity);
3981 }
3982 }
3983
3984 @Override
3985 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3986 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3987 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3988 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3989 }
3990 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3991 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3992 return (provisionedBits & capability) > 0;
3993 }
3994
3995 @Override
3996 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3997 boolean isProvisioned) {
3998 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3999 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4000 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4001 }
4002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4003 "setProvisioningStatusForCapability");
4004 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4005 // If the current provisioning status for capability already matches isProvisioned,
4006 // do nothing.
4007 if (((provisionedBits & capability) > 0) == isProvisioned) {
4008 return;
4009 }
4010 if (isProvisioned) {
4011 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4012 } else {
4013 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4014 }
4015 }
4016
4017 /**
4018 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4019 * technology. The bitfield should mirror the bitfield defined by
4020 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4021 */
4022 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4023 String key = getMmTelProvisioningKey(subId, tech);
4024 // Default is no capabilities are provisioned.
4025 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4026 }
4027
4028 /**
4029 * Sets the MmTel capability provisioning bitfield (defined by
4030 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4031 * technology specified.
4032 *
4033 * Note: This is a synchronous command and should not be called on UI thread.
4034 */
4035 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4036 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4037 String key = getMmTelProvisioningKey(subId, tech);
4038 editor.putInt(key, newField);
4039 editor.commit();
4040 }
4041
4042 private static String getMmTelProvisioningKey(int subId, int tech) {
4043 // resulting key is provision_ims_mmtel_{subId}_{tech}
4044 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4045 }
4046
4047 /**
4048 * Query CarrierConfig to see if the specified capability requires provisioning for the
4049 * carrier associated with the subscription id.
4050 */
4051 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4052 int capability) {
4053 CarrierConfigManager configManager = new CarrierConfigManager(context);
4054 PersistableBundle c = configManager.getConfigForSubId(subId);
4055 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004056 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004057 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4058 false);
4059 boolean requireVoiceVtProvisioning = c.getBoolean(
4060 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4061
4062 // First check to make sure that the capability requires provisioning.
4063 switch (capability) {
4064 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4065 // intentional fallthrough
4066 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4067 if (requireVoiceVtProvisioning) {
4068 // Voice and Video requires provisioning
4069 return true;
4070 }
4071 break;
4072 }
4073 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4074 if (requireUtProvisioning) {
4075 // UT requires provisioning
4076 return true;
4077 }
4078 break;
4079 }
4080 }
4081 return false;
4082 }
4083
allenwtsu99c623b2020-01-03 18:24:23 +08004084 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4085 int capability) {
4086 CarrierConfigManager configManager = new CarrierConfigManager(context);
4087 PersistableBundle c = configManager.getConfigForSubId(subId);
4088
4089 boolean requireRcsProvisioning = c.getBoolean(
4090 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4091
4092 // First check to make sure that the capability requires provisioning.
4093 switch (capability) {
4094 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4095 // intentional fallthrough
4096 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4097 if (requireRcsProvisioning) {
4098 // OPTION or PRESENCE requires provisioning
4099 return true;
4100 }
4101 break;
4102 }
4103 }
4104 return false;
4105 }
4106
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004107 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004108 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004109 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4110 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4111 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004112 enforceReadPrivilegedPermission("getImsProvisioningInt");
4113 final long identity = Binder.clearCallingIdentity();
4114 try {
4115 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004116 int slotId = getSlotIndex(subId);
4117 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4118 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4119 + subId + "' for key:" + key);
4120 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4121 }
4122 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004123 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004124 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4125 + subId + "' for key:" + key);
4126 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004127 } finally {
4128 Binder.restoreCallingIdentity(identity);
4129 }
4130 }
4131
4132 @Override
4133 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004134 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4135 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4136 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004137 enforceReadPrivilegedPermission("getImsProvisioningString");
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004141 int slotId = getSlotIndex(subId);
4142 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4143 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4144 + subId + "' for key:" + key);
4145 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4146 }
4147 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004148 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004149 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4150 + subId + "' for key:" + key);
4151 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004152 } finally {
4153 Binder.restoreCallingIdentity(identity);
4154 }
4155 }
4156
4157 @Override
4158 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004159 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4160 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4161 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4163 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004164 final long identity = Binder.clearCallingIdentity();
4165 try {
4166 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004167 int slotId = getSlotIndex(subId);
4168 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4169 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4170 + subId + "' for key:" + key);
4171 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4172 }
4173 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004174 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004175 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4176 + "' for key:" + key);
4177 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004178 } finally {
4179 Binder.restoreCallingIdentity(identity);
4180 }
4181 }
4182
4183 @Override
4184 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004185 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4186 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4187 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4189 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004190 final long identity = Binder.clearCallingIdentity();
4191 try {
4192 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004193 int slotId = getSlotIndex(subId);
4194 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4195 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4196 + subId + "' for key:" + key);
4197 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4198 }
4199 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004200 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004201 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4202 + "' for key:" + key);
4203 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004204 } finally {
4205 Binder.restoreCallingIdentity(identity);
4206 }
4207 }
4208
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004209 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 int slotId = SubscriptionManager.getSlotIndex(subId);
4211 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004212 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4213 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 }
4215 return slotId;
4216 }
4217
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004218 private int getSlotIndex(int subId) {
4219 int slotId = SubscriptionManager.getSlotIndex(subId);
4220 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4221 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4222 }
4223 return slotId;
4224 }
4225
Wink Saville36469e72014-06-11 15:17:00 -07004226 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004227 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004228 */
4229 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004230 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4231 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004232 final int targetSdk = getTargetSdk(callingPackage);
4233 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004234 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004235 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004236 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004237 mApp, subId, callingPackage, callingFeatureId,
4238 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004239 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4240 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004242 final long identity = Binder.clearCallingIdentity();
4243 try {
4244 final Phone phone = getPhone(subId);
4245 if (phone != null) {
4246 return phone.getServiceState().getDataNetworkType();
4247 } else {
4248 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4249 }
4250 } finally {
4251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004253 }
4254
4255 /**
4256 * Returns the data network type
4257 */
4258 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004259 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4260 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4261 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004262 }
4263
4264 /**
4265 * Returns the data network type for a subId
4266 */
4267 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004268 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4269 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004271 mApp, subId, callingPackage, callingFeatureId,
4272 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004273 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4274 }
4275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 final Phone phone = getPhone(subId);
4279 if (phone != null) {
4280 return phone.getServiceState().getDataNetworkType();
4281 } else {
4282 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4283 }
4284 } finally {
4285 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004287 }
4288
4289 /**
Wink Saville36469e72014-06-11 15:17:00 -07004290 * Returns the Voice network type for a subId
4291 */
4292 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004293 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4294 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004295 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004296 mApp, subId, callingPackage, callingFeatureId,
4297 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004298 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4299 }
4300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004301 final long identity = Binder.clearCallingIdentity();
4302 try {
4303 final Phone phone = getPhone(subId);
4304 if (phone != null) {
4305 return phone.getServiceState().getVoiceNetworkType();
4306 } else {
4307 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4308 }
4309 } finally {
4310 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004312 }
4313
4314 /**
4315 * @return true if a ICC card is present
4316 */
4317 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004318 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004319 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4320 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004321 }
4322
4323 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004324 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004325 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004326 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004327 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 final Phone phone = PhoneFactory.getPhone(slotIndex);
4331 if (phone != null) {
4332 return phone.getIccCard().hasIccCard();
4333 } else {
4334 return false;
4335 }
4336 } finally {
4337 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004339 }
4340
4341 /**
4342 * Return if the current radio is LTE on CDMA. This
4343 * is a tri-state return value as for a period of time
4344 * the mode may be unknown.
4345 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004346 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004347 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004348 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004349 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004350 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004351 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4352 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4353 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004354 }
4355
Sanket Padawe356d7632015-06-22 14:03:32 -07004356 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004357 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4358 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004359 try {
4360 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4361 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004362 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4363 }
4364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004365 final long identity = Binder.clearCallingIdentity();
4366 try {
4367 final Phone phone = getPhone(subId);
4368 if (phone == null) {
4369 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4370 } else {
4371 return phone.getLteOnCdmaMode();
4372 }
4373 } finally {
4374 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004375 }
Wink Saville36469e72014-06-11 15:17:00 -07004376 }
4377
Wink Saville36469e72014-06-11 15:17:00 -07004378 /**
4379 * {@hide}
4380 * Returns Default subId, 0 in the case of single standby.
4381 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004382 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004383 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004384 }
4385
Shishir Agrawala9f32182016-04-12 12:00:16 -07004386 private int getSlotForDefaultSubscription() {
4387 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4388 }
4389
Wink Savilleb564aae2014-10-23 10:18:09 -07004390 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004391 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004392 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004393
Pengquan Menge92a50d2018-09-21 15:54:48 -07004394 private boolean isActiveSubscription(int subId) {
4395 return mSubscriptionController.isActiveSubId(subId);
4396 }
4397
Ihab Awadf2177b72013-11-25 13:33:23 -08004398 /**
4399 * @see android.telephony.TelephonyManager.WifiCallingChoices
4400 */
4401 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 final long identity = Binder.clearCallingIdentity();
4403 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004404 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4406 getWhenToMakeWifiCallsDefaultPreference());
4407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004410 }
4411
4412 /**
4413 * @see android.telephony.TelephonyManager.WifiCallingChoices
4414 */
4415 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004416 final long identity = Binder.clearCallingIdentity();
4417 try {
4418 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004419 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4421 } finally {
4422 Binder.restoreCallingIdentity(identity);
4423 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004424 }
4425
Sailesh Nepald1e68152013-12-12 19:08:02 -08004426 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004427 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004428 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004429 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004430
Jordan Liu4c733742019-02-28 12:03:40 -08004431 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4432 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4433 if (phoneId == -1) {
4434 throw new IllegalArgumentException("Given slot index: " + slotIndex
4435 + " does not correspond to an active phone");
4436 }
4437 return PhoneFactory.getPhone(phoneId);
4438 }
4439
Shishir Agrawal566b7612013-10-28 14:41:00 -07004440 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004441 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4442 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4444 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004446 if (DBG) {
4447 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4448 }
4449 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4450 p2);
4451 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004452
Jordan Liu4c733742019-02-28 12:03:40 -08004453
4454 @Override
4455 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4456 int slotIndex, String callingPackage, String aid, int p2) {
4457 enforceModifyPermission();
4458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4459 if (DBG) {
4460 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4461 }
4462 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4463 callingPackage, aid, p2);
4464 }
4465
4466 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4467 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004468 final long identity = Binder.clearCallingIdentity();
4469 try {
4470 if (TextUtils.equals(ISDR_AID, aid)) {
4471 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004472 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4473 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474 if (bestComponent == null
4475 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4476 loge("The calling package is not allowed to access ISD-R.");
4477 throw new SecurityException(
4478 "The calling package is not allowed to access ISD-R.");
4479 }
Derek Tan740e1672017-06-27 14:56:27 -07004480 }
Derek Tan740e1672017-06-27 14:56:27 -07004481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004483 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4484 null /* workSource */);
4485 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004486 return response;
4487 } finally {
4488 Binder.restoreCallingIdentity(identity);
4489 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004490 }
4491
4492 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004493 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4495 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004496 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4497 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4498 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004499
Jordan Liu4c733742019-02-28 12:03:40 -08004500 @Override
4501 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4502 enforceModifyPermission();
4503 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4504 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4505 channel);
4506 }
4507
4508 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004509 final long identity = Binder.clearCallingIdentity();
4510 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004511 if (channel < 0) {
4512 return false;
4513 }
Jordan Liu4c733742019-02-28 12:03:40 -08004514 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4515 null /* workSource */);
4516 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517 return success;
4518 } finally {
4519 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004520 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004521 }
4522
4523 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004524 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004525 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4527 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004528 if (DBG) {
4529 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4530 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4531 + p3 + " data=" + data);
4532 }
4533 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4534 command, p1, p2, p3, data);
4535 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004536
Jordan Liu4c733742019-02-28 12:03:40 -08004537 @Override
4538 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4539 int command, int p1, int p2, int p3, String data) {
4540 enforceModifyPermission();
4541 if (DBG) {
4542 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4543 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4544 + p3 + " data=" + data);
4545 }
4546 return iccTransmitApduLogicalChannelWithPermission(
4547 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4548 data);
4549 }
4550
4551 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4552 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 final long identity = Binder.clearCallingIdentity();
4554 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004555 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556 return "";
4557 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004560 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4561 null /* workSource */);
4562 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004564 // Append the returned status code to the end of the response payload.
4565 String s = Integer.toHexString(
4566 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4567 if (response.payload != null) {
4568 s = IccUtils.bytesToHexString(response.payload) + s;
4569 }
4570 return s;
4571 } finally {
4572 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004573 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004574 }
Jake Hambye994d462014-02-03 13:10:13 -08004575
Evan Charltonc66da362014-05-16 14:06:40 -07004576 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004577 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4578 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4580 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004582 if (DBG) {
4583 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4584 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4585 }
4586 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4587 cla, command, p1, p2, p3, data);
4588 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004589
Jordan Liu4c733742019-02-28 12:03:40 -08004590 @Override
4591 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4592 int command, int p1, int p2, int p3, String data) {
4593 enforceModifyPermission();
4594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4595 if (DBG) {
4596 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4597 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4598 + " data=" + data);
4599 }
4600
4601 return iccTransmitApduBasicChannelWithPermission(
4602 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4603 p2, p3, data);
4604 }
4605
4606 // open APDU basic channel assuming the caller has sufficient permissions
4607 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4608 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004609 final long identity = Binder.clearCallingIdentity();
4610 try {
4611 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4612 && TextUtils.equals(ISDR_AID, data)) {
4613 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004614 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4615 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616 if (bestComponent == null
4617 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4618 loge("The calling package is not allowed to select ISD-R.");
4619 throw new SecurityException(
4620 "The calling package is not allowed to select ISD-R.");
4621 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004622 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004623
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004625 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4626 null /* workSource */);
4627 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629 // Append the returned status code to the end of the response payload.
4630 String s = Integer.toHexString(
4631 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4632 if (response.payload != null) {
4633 s = IccUtils.bytesToHexString(response.payload) + s;
4634 }
4635 return s;
4636 } finally {
4637 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004638 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004639 }
4640
4641 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004642 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004643 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4645 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004647 final long identity = Binder.clearCallingIdentity();
4648 try {
4649 if (DBG) {
4650 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4651 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4652 }
4653
4654 IccIoResult response =
4655 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4656 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4657 subId);
4658
4659 if (DBG) {
4660 log("Exchange SIM_IO [R]" + response);
4661 }
4662
4663 byte[] result = null;
4664 int length = 2;
4665 if (response.payload != null) {
4666 length = 2 + response.payload.length;
4667 result = new byte[length];
4668 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4669 } else {
4670 result = new byte[length];
4671 }
4672
4673 result[length - 1] = (byte) response.sw2;
4674 result[length - 2] = (byte) response.sw1;
4675 return result;
4676 } finally {
4677 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004678 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004679 }
4680
Nathan Haroldb3014052017-01-25 15:57:32 -08004681 /**
4682 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4683 * on a particular subscription
4684 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004685 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4686 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004687 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004688 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004689 return null;
4690 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691
4692 final long identity = Binder.clearCallingIdentity();
4693 try {
4694 if (appType != TelephonyManager.APPTYPE_USIM
4695 && appType != TelephonyManager.APPTYPE_SIM) {
4696 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4697 return null;
4698 }
4699 Object response = sendRequest(
4700 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4701 if (response instanceof String[]) {
4702 return (String[]) response;
4703 }
yincheng zhao2737e882019-09-06 17:06:54 -07004704 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004706 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004707 } finally {
4708 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004709 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004710 }
4711
yincheng zhao2737e882019-09-06 17:06:54 -07004712 /**
4713 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4714 * subscription.
4715 *
4716 * @param subId the id of the subscription.
4717 * @param appType the uicc app type, must be USIM or SIM.
4718 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4719 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004720 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004721 * @return number of fplmns that is successfully written to the SIM.
4722 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004723 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4724 String callingFeatureId) {
4725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4726 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004727 if (DBG) logv("no permissions for setForbiddenplmns");
4728 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4729 }
4730 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4731 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4732 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4733 }
4734 if (fplmns == null) {
4735 throw new IllegalArgumentException("Fplmn List provided is null");
4736 }
4737 for (String fplmn : fplmns) {
4738 if (!CellIdentity.isValidPlmn(fplmn)) {
4739 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4740 }
4741 }
4742 final long identity = Binder.clearCallingIdentity();
4743 try {
4744 Object response = sendRequest(
4745 CMD_SET_FORBIDDEN_PLMNS,
4746 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4747 subId);
4748 return (int) response;
4749 } finally {
4750 Binder.restoreCallingIdentity(identity);
4751 }
4752 }
4753
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004754 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004755 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4757 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 final long identity = Binder.clearCallingIdentity();
4760 try {
4761 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4762 if (response.payload == null) {
4763 return "";
4764 }
Evan Charltonc66da362014-05-16 14:06:40 -07004765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004766 // Append the returned status code to the end of the response payload.
4767 String s = Integer.toHexString(
4768 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4769 s = IccUtils.bytesToHexString(response.payload) + s;
4770 return s;
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
4773 }
Evan Charltonc66da362014-05-16 14:06:40 -07004774 }
4775
Jake Hambye994d462014-02-03 13:10:13 -08004776 /**
4777 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4778 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4779 *
4780 * @param itemID the ID of the item to read
4781 * @return the NV item as a String, or null on error.
4782 */
4783 @Override
4784 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004785 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4787 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004788
4789 final long identity = Binder.clearCallingIdentity();
4790 try {
4791 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004792 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004793 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4794 return value;
4795 } finally {
4796 Binder.restoreCallingIdentity(identity);
4797 }
Jake Hambye994d462014-02-03 13:10:13 -08004798 }
4799
4800 /**
4801 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4802 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4803 *
4804 * @param itemID the ID of the item to read
4805 * @param itemValue the value to write, as a String
4806 * @return true on success; false on any failure
4807 */
4808 @Override
4809 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004810 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4812 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813
4814 final long identity = Binder.clearCallingIdentity();
4815 try {
4816 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4817 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004818 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4820 return success;
4821 } finally {
4822 Binder.restoreCallingIdentity(identity);
4823 }
Jake Hambye994d462014-02-03 13:10:13 -08004824 }
4825
4826 /**
4827 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4828 * Used for device configuration by some CDMA operators.
4829 *
4830 * @param preferredRoamingList byte array containing the new PRL
4831 * @return true on success; false on any failure
4832 */
4833 @Override
4834 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4836 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004837
4838 final long identity = Binder.clearCallingIdentity();
4839 try {
4840 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4841 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4842 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4843 return success;
4844 } finally {
4845 Binder.restoreCallingIdentity(identity);
4846 }
Jake Hambye994d462014-02-03 13:10:13 -08004847 }
4848
4849 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004850 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004851 * Used for device configuration by some CDMA operators.
4852 *
chen xu6dac5ab2018-10-26 17:39:23 -07004853 * @param slotIndex - device slot.
4854 *
Jake Hambye994d462014-02-03 13:10:13 -08004855 * @return true on success; false on any failure
4856 */
4857 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004858 public boolean resetModemConfig(int slotIndex) {
4859 Phone phone = PhoneFactory.getPhone(slotIndex);
4860 if (phone != null) {
4861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4862 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004863
chen xu6dac5ab2018-10-26 17:39:23 -07004864 final long identity = Binder.clearCallingIdentity();
4865 try {
4866 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4867 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4868 return success;
4869 } finally {
4870 Binder.restoreCallingIdentity(identity);
4871 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004872 }
chen xu6dac5ab2018-10-26 17:39:23 -07004873 return false;
4874 }
4875
4876 /**
4877 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4878 *
4879 * @param slotIndex - device slot.
4880 *
4881 * @return true on success; false on any failure
4882 */
4883 @Override
4884 public boolean rebootModem(int slotIndex) {
4885 Phone phone = PhoneFactory.getPhone(slotIndex);
4886 if (phone != null) {
4887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4888 mApp, phone.getSubId(), "rebootModem");
4889
4890 final long identity = Binder.clearCallingIdentity();
4891 try {
4892 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4893 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4894 return success;
4895 } finally {
4896 Binder.restoreCallingIdentity(identity);
4897 }
4898 }
4899 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004900 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004901
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004902 public String[] getPcscfAddress(String apnType, String callingPackage,
4903 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004904 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4906 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004907 return new String[0];
4908 }
4909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 final long identity = Binder.clearCallingIdentity();
4911 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004912 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004913 } finally {
4914 Binder.restoreCallingIdentity(identity);
4915 }
Wink Saville36469e72014-06-11 15:17:00 -07004916 }
4917
Brad Ebinger51f743a2017-01-23 13:50:20 -08004918 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004919 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4920 * {@link #disableIms(int)}.
4921 * @param slotIndex device slot.
4922 */
4923 public void resetIms(int slotIndex) {
4924 enforceModifyPermission();
4925
4926 final long identity = Binder.clearCallingIdentity();
4927 try {
4928 if (mImsResolver == null) {
4929 // may happen if the does not support IMS.
4930 return;
4931 }
4932 mImsResolver.disableIms(slotIndex);
4933 mImsResolver.enableIms(slotIndex);
4934 } finally {
4935 Binder.restoreCallingIdentity(identity);
4936 }
4937 }
4938
4939 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004940 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4941 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004942 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004943 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004944 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945
4946 final long identity = Binder.clearCallingIdentity();
4947 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004948 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004949 // may happen if the device does not support IMS.
4950 return;
4951 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004952 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 } finally {
4954 Binder.restoreCallingIdentity(identity);
4955 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004956 }
4957
4958 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004959 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4960 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004961 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004962 public void disableIms(int slotId) {
4963 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964
4965 final long identity = Binder.clearCallingIdentity();
4966 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004967 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004968 // may happen if the device does not support IMS.
4969 return;
4970 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004971 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004975 }
4976
4977 /**
4978 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4979 * feature or {@link null} if the service is not available. If the feature is available, the
4980 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4981 */
4982 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004983 IImsServiceFeatureCallback callback) {
4984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985
4986 final long identity = Binder.clearCallingIdentity();
4987 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004988 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004989 // may happen if the device does not support IMS.
4990 return null;
4991 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004992 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004996 }
4997
4998 /**
4999 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5000 * feature during emergency calling or {@link null} if the service is not available. If the
5001 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5002 * listener for feature updates.
5003 */
5004 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5005 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006
5007 final long identity = Binder.clearCallingIdentity();
5008 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005009 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005010 // may happen if the device does not support IMS.
5011 return null;
5012 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005013 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014 } finally {
5015 Binder.restoreCallingIdentity(identity);
5016 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005017 }
5018
Brad Ebinger5f64b052017-12-14 14:26:15 -08005019 /**
5020 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005021 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005022 */
5023 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5024 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025
5026 final long identity = Binder.clearCallingIdentity();
5027 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005028 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005029 // may happen if the device does not support IMS.
5030 return null;
5031 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005032 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005033 } finally {
5034 Binder.restoreCallingIdentity(identity);
5035 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005036 }
5037
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005038 /**
5039 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005040 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005041 */
5042 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5043 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044
5045 final long identity = Binder.clearCallingIdentity();
5046 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005047 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005048 // may happen if the device does not support IMS.
5049 return null;
5050 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005051 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 } finally {
5053 Binder.restoreCallingIdentity(identity);
5054 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005055 }
5056
Brad Ebinger884c07b2018-02-15 16:17:40 -08005057 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005058 * Sets the ImsService Package Name that Telephony will bind to.
5059 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005060 * @param slotIndex the slot ID that the ImsService should bind for.
5061 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005062 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005063 * @param featureTypes An integer array of feature types associated with a packageName.
5064 * @param packageName The name of the package that the current configuration will be replaced
5065 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005066 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005067 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005068 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5069 int[] featureTypes, String packageName) {
5070 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5071 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5073 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005074 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005076 final long identity = Binder.clearCallingIdentity();
5077 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005078 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005079 // may happen if the device does not support IMS.
5080 return false;
5081 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005082 Map<Integer, String> featureConfig = new HashMap<>();
5083 for (int featureType : featureTypes) {
5084 featureConfig.put(featureType, packageName);
5085 }
5086 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5087 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005088 } finally {
5089 Binder.restoreCallingIdentity(identity);
5090 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005091 }
5092
5093 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005094 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005095 *
5096 * @param slotId The slot that the ImsService is associated with.
5097 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5098 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005099 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005100 * @return the package name of the ImsService configuration.
5101 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005102 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5103 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005104 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005105 TelephonyPermissions
5106 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5107 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5108 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005110 final long identity = Binder.clearCallingIdentity();
5111 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005112 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005113 // may happen if the device does not support IMS.
5114 return "";
5115 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005116 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005117 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5118 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119 } finally {
5120 Binder.restoreCallingIdentity(identity);
5121 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005122 }
5123
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005124 /**
5125 * Get the MmTelFeature state associated with the requested subscription id.
5126 * @param subId The subscription that the MmTelFeature is associated with.
5127 * @param callback A callback with an integer containing the
5128 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5129 */
5130 @Override
5131 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5132 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5133 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5134 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5135 "IMS not available on device.");
5136 }
5137 final long token = Binder.clearCallingIdentity();
5138 try {
5139 int slotId = getSlotIndex(subId);
5140 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5141 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5142 + subId + "'");
5143 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5144 }
5145 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5146 try {
5147 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5148 } catch (RemoteException e) {
5149 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5150 + "Ignore");
5151 }
5152 });
5153 } finally {
5154 Binder.restoreCallingIdentity(token);
5155 }
5156 }
5157
Wink Saville36469e72014-06-11 15:17:00 -07005158 public void setImsRegistrationState(boolean registered) {
5159 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005160
5161 final long identity = Binder.clearCallingIdentity();
5162 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005163 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164 } finally {
5165 Binder.restoreCallingIdentity(identity);
5166 }
Wink Saville36469e72014-06-11 15:17:00 -07005167 }
5168
5169 /**
Stuart Scott54788802015-03-30 13:18:01 -07005170 * Set the network selection mode to automatic.
5171 *
5172 */
5173 @Override
5174 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5176 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177
5178 final long identity = Binder.clearCallingIdentity();
5179 try {
shilufc958392020-01-20 11:36:01 -08005180 if (!isActiveSubscription(subId)) {
5181 return;
5182 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005183 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5184 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5185 } finally {
5186 Binder.restoreCallingIdentity(identity);
5187 }
Stuart Scott54788802015-03-30 13:18:01 -07005188 }
5189
Pengquan Mengea84e042018-09-20 14:57:26 -07005190 /**
5191 * Ask the radio to connect to the input network and change selection mode to manual.
5192 *
5193 * @param subId the id of the subscription.
5194 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5195 * the operator to attach to.
5196 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5197 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5198 * normal network selection next time.
5199 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005200 */
5201 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005202 public boolean setNetworkSelectionModeManual(
5203 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5205 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005206
5207 if (!isActiveSubscription(subId)) {
5208 return false;
5209 }
5210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211 final long identity = Binder.clearCallingIdentity();
5212 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005213 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005215 if (DBG) {
5216 log("setNetworkSelectionModeManual: subId: " + subId
5217 + " operator: " + operatorInfo);
5218 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005219 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5220 } finally {
5221 Binder.restoreCallingIdentity(identity);
5222 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005223 }
shilu84f6e8b2019-12-19 13:58:01 -08005224 /**
5225 * Get the manual network selection
5226 *
5227 * @param subId the id of the subscription.
5228 *
5229 * @return the previously saved user selected PLMN
5230 */
5231 @Override
5232 public String getManualNetworkSelectionPlmn(int subId) {
5233 TelephonyPermissions
5234 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5235 mApp, subId, "getManualNetworkSelectionPlmn");
5236
5237 final long identity = Binder.clearCallingIdentity();
5238 try {
5239 if (!isActiveSubscription(subId)) {
5240 return "";
5241 }
5242
5243 final Phone phone = getPhone(subId);
5244 if (phone == null) {
5245 return "";
5246 }
5247 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5248 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5249 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5250 } finally {
5251 Binder.restoreCallingIdentity(identity);
5252 }
5253 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005254
5255 /**
5256 * Scans for available networks.
5257 */
5258 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005259 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5260 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5262 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005263 LocationAccessPolicy.LocationPermissionResult locationResult =
5264 LocationAccessPolicy.checkLocationPermission(mApp,
5265 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5266 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005267 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005268 .setCallingPid(Binder.getCallingPid())
5269 .setCallingUid(Binder.getCallingUid())
5270 .setMethod("getCellNetworkScanResults")
5271 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5272 .build());
5273 switch (locationResult) {
5274 case DENIED_HARD:
5275 throw new SecurityException("Not allowed to access scan results -- location");
5276 case DENIED_SOFT:
5277 return null;
5278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279
Pengquan Menga1bb6272018-09-06 09:59:22 -07005280 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 try {
5282 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005283 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 } finally {
5286 Binder.restoreCallingIdentity(identity);
5287 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005288 }
5289
5290 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005291 * Get the call forwarding info, given the call forwarding reason.
5292 */
5293 @Override
5294 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5295 enforceReadPrivilegedPermission("getCallForwarding");
5296 long identity = Binder.clearCallingIdentity();
5297 try {
5298 if (DBG) {
5299 log("getCallForwarding: subId " + subId
5300 + " callForwardingReason" + callForwardingReason);
5301 }
5302 return (CallForwardingInfo) sendRequest(
5303 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5304 } finally {
5305 Binder.restoreCallingIdentity(identity);
5306 }
5307 }
5308
5309 /**
5310 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5311 * reason, the number to forward, and the timeout before the forwarding is attempted.
5312 */
5313 @Override
5314 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5315 enforceModifyPermission();
5316 long identity = Binder.clearCallingIdentity();
5317 try {
5318 if (DBG) {
5319 log("setCallForwarding: subId " + subId
5320 + " callForwardingInfo" + callForwardingInfo);
5321 }
5322 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5323 } finally {
5324 Binder.restoreCallingIdentity(identity);
5325 }
5326 }
5327
5328 /**
5329 * Get the call forwarding info, given the call forwarding reason.
5330 */
5331 @Override
5332 public int getCallWaitingStatus(int subId) {
5333 enforceReadPrivilegedPermission("getCallForwarding");
5334 long identity = Binder.clearCallingIdentity();
5335 try {
5336 if (DBG) log("getCallWaitingStatus: subId " + subId);
5337 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5338 } finally {
5339 Binder.restoreCallingIdentity(identity);
5340 }
5341 }
5342
5343 /**
5344 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5345 * reason, the number to forward, and the timeout before the forwarding is attempted.
5346 */
5347 @Override
5348 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5349 enforceModifyPermission();
5350 long identity = Binder.clearCallingIdentity();
5351 try {
5352 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5353 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5354 } finally {
5355 Binder.restoreCallingIdentity(identity);
5356 }
5357 }
5358
5359 /**
yinxub1bed742017-04-17 11:45:04 -07005360 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005361 *
yinxub1bed742017-04-17 11:45:04 -07005362 * @param subId id of the subscription
5363 * @param request contains the radio access networks with bands/channels to scan
5364 * @param messenger callback messenger for scan results or errors
5365 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005366 * @return the id of the requested scan which can be used to stop the scan.
5367 */
5368 @Override
5369 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005370 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5372 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005373 LocationAccessPolicy.LocationPermissionResult locationResult =
5374 LocationAccessPolicy.checkLocationPermission(mApp,
5375 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5376 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005377 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005378 .setCallingPid(Binder.getCallingPid())
5379 .setCallingUid(Binder.getCallingUid())
5380 .setMethod("requestNetworkScan")
5381 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5382 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005383 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005384 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005385 if (e != null) {
5386 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5387 throw e;
5388 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005389 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005390 return TelephonyScanManager.INVALID_SCAN_ID;
5391 }
5392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 }
Hall Liu912dfd32019-04-25 14:02:26 -07005394 int callingUid = Binder.getCallingUid();
5395 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005396 final long identity = Binder.clearCallingIdentity();
5397 try {
5398 return mNetworkScanRequestTracker.startNetworkScan(
5399 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005400 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005401 } finally {
5402 Binder.restoreCallingIdentity(identity);
5403 }
yinxu504e1392017-04-12 16:03:22 -07005404 }
5405
Hall Liub2ac8ef2019-02-28 15:56:23 -08005406 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005407 NetworkScanRequest request, int subId) {
5408 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5409 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5410 boolean hasNetworkScanPermission =
5411 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5412 == PERMISSION_GRANTED;
5413
5414 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5415 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5416 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005417 }
5418
5419 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5420 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005421 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5422 return new SecurityException("Specific channels must not be"
5423 + " scanned without location access.");
5424 }
5425 }
5426 }
5427
Hall Liub2ac8ef2019-02-28 15:56:23 -08005428 return null;
5429 }
5430
yinxu504e1392017-04-12 16:03:22 -07005431 /**
5432 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005433 *
5434 * @param subId id of the subscription
5435 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005436 */
5437 @Override
5438 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5440 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441
Hall Liu912dfd32019-04-25 14:02:26 -07005442 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443 final long identity = Binder.clearCallingIdentity();
5444 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005445 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 } finally {
5447 Binder.restoreCallingIdentity(identity);
5448 }
yinxu504e1392017-04-12 16:03:22 -07005449 }
5450
5451 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005452 * Get the calculated preferred network type.
5453 * Used for debugging incorrect network type.
5454 *
5455 * @return the preferred network type, defined in RILConstants.java.
5456 */
5457 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005458 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005459 final Phone defaultPhone = getDefaultPhone();
5460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005461 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005462 return RILConstants.PREFERRED_NETWORK_MODE;
5463 }
5464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005468 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469 } finally {
5470 Binder.restoreCallingIdentity(identity);
5471 }
Junda Liu84d15a22014-07-02 11:21:04 -07005472 }
5473
5474 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005475 * Get the preferred network type.
5476 * Used for device configuration by some CDMA operators.
5477 *
5478 * @return the preferred network type, defined in RILConstants.java.
5479 */
5480 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005481 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005482 TelephonyPermissions
5483 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5484 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485
5486 final long identity = Binder.clearCallingIdentity();
5487 try {
5488 if (DBG) log("getPreferredNetworkType");
5489 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5490 int networkType = (result != null ? result[0] : -1);
5491 if (DBG) log("getPreferredNetworkType: " + networkType);
5492 return networkType;
5493 } finally {
5494 Binder.restoreCallingIdentity(identity);
5495 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005496 }
5497
5498 /**
5499 * Set the preferred network type.
5500 * Used for device configuration by some CDMA operators.
5501 *
5502 * @param networkType the preferred network type, defined in RILConstants.java.
5503 * @return true on success; false on any failure.
5504 */
5505 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005506 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5508 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509
5510 final long identity = Binder.clearCallingIdentity();
5511 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005512 Settings.Global.putInt(mApp.getContentResolver(),
5513 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5514 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515 } finally {
5516 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005517 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005518 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005519
5520 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005521 * Get the allowed network types that store in the telephony provider.
5522 *
5523 * @param subId the id of the subscription.
5524 * @return allowedNetworkTypes the allowed network types.
5525 */
5526 @Override
5527 public long getAllowedNetworkTypes(int subId) {
5528 TelephonyPermissions
5529 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5530 mApp, subId, "getAllowedNetworkTypes");
5531
5532 final long identity = Binder.clearCallingIdentity();
5533 try {
5534 return SubscriptionManager.getLongSubscriptionProperty(
5535 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5536 } finally {
5537 Binder.restoreCallingIdentity(identity);
5538 }
5539 }
5540
5541 /**
5542 * Set the allowed network types.
5543 *
5544 * @param subId the id of the subscription.
5545 * @param allowedNetworkTypes the allowed network types.
5546 * @return true on success; false on any failure.
5547 */
5548 @Override
5549 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5551 mApp, subId, "setAllowedNetworkTypes");
5552 final long identity = Binder.clearCallingIdentity();
5553 try {
5554 SubscriptionManager.setSubscriptionProperty(subId,
5555 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5556 String.valueOf(allowedNetworkTypes));
5557 return setPreferredNetworkTypesInternal(subId);
5558 } finally {
5559 Binder.restoreCallingIdentity(identity);
5560 }
5561 }
5562
5563 private boolean setPreferredNetworkTypesInternal(int subId) {
5564 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5565 Settings.Global.getInt(mApp.getContentResolver(),
5566 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5567 RILConstants.PREFERRED_NETWORK_MODE));
5568 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5569 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5570 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5571 (int) (networkTypeBitMask & allowedNetworkTypes));
5572
5573 if (DBG) {
5574 log("setPreferredNetworkTypesInternal: subId " + subId
5575 + " networkTypes " + networkTypeBitMask
5576 + " allowedNetworkTypes " + allowedNetworkTypes
5577 + " networkMode " + networkMode);
5578 }
5579
5580 Boolean success = (Boolean) sendRequest(
5581 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5582 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5583 return success;
5584 }
5585
5586 /**
Miaoa84611c2019-03-15 09:21:10 +08005587 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005588 *
Miaoa84611c2019-03-15 09:21:10 +08005589 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005590 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005591 * @hide
5592 */
5593 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005594 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005595 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005597 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598 try {
Miaoa84611c2019-03-15 09:21:10 +08005599 if (phone != null) {
5600 return phone.hasMatchedTetherApnSetting();
5601 } else {
5602 return false;
5603 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604 } finally {
5605 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005606 }
Junda Liu475951f2014-11-07 16:45:03 -08005607 }
5608
5609 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005610 * Set mobile data enabled
5611 * Used by the user through settings etc to turn on/off mobile data
5612 *
5613 * @param enable {@code true} turn turn data on, else {@code false}
5614 */
5615 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005616 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5618 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619
5620 final long identity = Binder.clearCallingIdentity();
5621 try {
5622 int phoneId = mSubscriptionController.getPhoneId(subId);
5623 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5624 Phone phone = PhoneFactory.getPhone(phoneId);
5625 if (phone != null) {
5626 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005627 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005629 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630 }
5631 } finally {
5632 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005633 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005634 }
5635
5636 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005637 * Enable or disable always reporting signal strength changes from radio.
5638 *
5639 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5640 */
5641 @Override
5642 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5643 enforceModifyPermission();
5644 enforceSystemCaller();
5645
5646 final long identity = Binder.clearCallingIdentity();
5647 final Phone phone = getPhone(subId);
5648 try {
5649 if (phone != null) {
5650 if (DBG) {
5651 log("setAlwaysReportSignalStrength: subId=" + subId
5652 + " isEnable=" + isEnable);
5653 }
5654 phone.setAlwaysReportSignalStrength(isEnable);
5655 } else {
5656 loge("setAlwaysReportSignalStrength: no phone found for subId="
5657 + subId);
5658 }
5659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
5662 }
5663
5664 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005665 * Get the user enabled state of Mobile Data.
5666 *
5667 * TODO: remove and use isUserDataEnabled.
5668 * This can't be removed now because some vendor codes
5669 * calls through ITelephony directly while they should
5670 * use TelephonyManager.
5671 *
5672 * @return true on enabled
5673 */
5674 @Override
5675 public boolean getDataEnabled(int subId) {
5676 return isUserDataEnabled(subId);
5677 }
5678
5679 /**
5680 * Get whether mobile data is enabled per user setting.
5681 *
5682 * There are other factors deciding whether mobile data is actually enabled, but they are
5683 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005684 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005685 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005686 *
5687 * @return {@code true} if data is enabled else {@code false}
5688 */
5689 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005690 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005691 try {
5692 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5693 null);
5694 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5696 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698
5699 final long identity = Binder.clearCallingIdentity();
5700 try {
5701 int phoneId = mSubscriptionController.getPhoneId(subId);
5702 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5703 Phone phone = PhoneFactory.getPhone(phoneId);
5704 if (phone != null) {
5705 boolean retVal = phone.isUserDataEnabled();
5706 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5707 return retVal;
5708 } else {
5709 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5710 return false;
5711 }
5712 } finally {
5713 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005714 }
5715 }
5716
5717 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005718 * Checks if the device is capable of mobile data by considering whether whether the
5719 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5720 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005721 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005722 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005723 */
5724 @Override
5725 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005726 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727
5728 final long identity = Binder.clearCallingIdentity();
5729 try {
5730 int phoneId = mSubscriptionController.getPhoneId(subId);
5731 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5732 Phone phone = PhoneFactory.getPhone(phoneId);
5733 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005734 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5736 return retVal;
5737 } else {
5738 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5739 return false;
5740 }
5741 } finally {
5742 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005743 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005744 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005745
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005746 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5747 Phone phone) {
5748 //load access rules from carrier configs, and check those as well: b/139133814
5749 SubscriptionController subController = SubscriptionController.getInstance();
5750 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5751 || subController == null) return privilegeFromSim;
5752
5753 int uid = Binder.getCallingUid();
5754 PackageManager pkgMgr = phone.getContext().getPackageManager();
5755 String[] packages = pkgMgr.getPackagesForUid(uid);
5756
5757 final long identity = Binder.clearCallingIdentity();
5758 try {
5759 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5760 SubscriptionManager subManager = (SubscriptionManager)
5761 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5762 for (String pkg : packages) {
5763 if (subManager.canManageSubscription(subInfo, pkg)) {
5764 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5765 }
5766 }
5767 return privilegeFromSim;
5768 } finally {
5769 Binder.restoreCallingIdentity(identity);
5770 }
5771 }
5772
5773 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5774 String pkgName) {
5775 //load access rules from carrier configs, and check those as well: b/139133814
5776 SubscriptionController subController = SubscriptionController.getInstance();
5777 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5778 || subController == null) return privilegeFromSim;
5779
5780 final long identity = Binder.clearCallingIdentity();
5781 try {
5782 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5783 SubscriptionManager subManager = (SubscriptionManager)
5784 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5785 return subManager.canManageSubscription(subInfo, pkgName)
5786 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5787 } finally {
5788 Binder.restoreCallingIdentity(identity);
5789 }
5790 }
5791
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005792 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005793 public int getCarrierPrivilegeStatus(int subId) {
5794 final Phone phone = getPhone(subId);
5795 if (phone == null) {
5796 loge("getCarrierPrivilegeStatus: Invalid subId");
5797 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5798 }
5799 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005800 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005801 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005802 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5803 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005804
5805 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5806 card.getCarrierPrivilegeStatusForCurrentTransaction(
5807 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005808 }
Junda Liu29340342014-07-10 15:23:27 -07005809
5810 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005811 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005812 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005813 final Phone phone = getPhone(subId);
5814 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005815 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005816 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5817 }
5818 UiccProfile profile =
5819 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5820 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005821 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005822 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5823 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005824 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005825 profile.getCarrierPrivilegeStatusForUid(
5826 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005827 }
5828
5829 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005830 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5831 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005832 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005833 }
5834
5835 int phoneId = SubscriptionManager.getPhoneId(subId);
5836 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005837 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005838 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005839 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5840 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005841 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5842 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5843 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005844 }
5845
5846 @Override
5847 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005848 if (TextUtils.isEmpty(pkgName))
5849 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005850 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5851 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5852 UiccCard card = UiccController.getInstance().getUiccCard(i);
5853 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005854 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005855 continue;
5856 }
5857
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005858 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5859 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5860 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005861 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5862 break;
5863 }
5864 }
5865
5866 return result;
Junda Liu29340342014-07-10 15:23:27 -07005867 }
Derek Tan89e89d42014-07-08 17:00:10 -07005868
5869 @Override
Junda Liue64de782015-04-16 17:19:16 -07005870 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5871 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5872 loge("phoneId " + phoneId + " is not valid.");
5873 return null;
5874 }
5875 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005876 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005877 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005878 return null ;
5879 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005880 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005881 }
5882
Amith Yamasani6e118872016-02-19 12:53:51 -08005883 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005884 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005885 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005886 List<String> privilegedPackages = new ArrayList<>();
5887 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005888 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5889 // has UICC in that slot.
5890 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005891 if (card.hasCarrierPrivilegeRules()) {
5892 if (packages == null) {
5893 // Only check packages in user 0 for now
5894 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005895 PackageManager.MATCH_DISABLED_COMPONENTS
5896 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005897 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005898 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005899 }
5900 for (int p = packages.size() - 1; p >= 0; p--) {
5901 PackageInfo pkgInfo = packages.get(p);
5902 if (pkgInfo != null && pkgInfo.packageName != null
5903 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005904 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005905 privilegedPackages.add(pkgInfo.packageName);
5906 }
5907 }
5908 }
5909 }
5910 return privilegedPackages;
5911 }
5912
chen xuf7e9fe82019-05-09 19:31:02 -07005913 @Override
5914 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005915 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5916
5917 final long identity = Binder.clearCallingIdentity();
5918
chen xuf7e9fe82019-05-09 19:31:02 -07005919 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005920 try {
5921 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5922 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5923 }
5924 } finally {
5925 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005926 }
5927 return privilegedPackages;
5928 }
5929
Wink Savilleb564aae2014-10-23 10:18:09 -07005930 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005931 final Phone phone = getPhone(subId);
5932 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005933 if (card == null) {
5934 loge("getIccId: No UICC");
5935 return null;
5936 }
5937 String iccId = card.getIccId();
5938 if (TextUtils.isEmpty(iccId)) {
5939 loge("getIccId: ICC ID is null or empty.");
5940 return null;
5941 }
5942 return iccId;
5943 }
5944
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005945 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005946 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5947 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005948 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005949 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 final long identity = Binder.clearCallingIdentity();
5952 try {
5953 final String iccId = getIccId(subId);
5954 final Phone phone = getPhone(subId);
5955 if (phone == null) {
5956 return false;
5957 }
5958 final String subscriberId = phone.getSubscriberId();
5959
5960 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08005961 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 + subscriberId + " to " + number);
5963 }
5964
5965 if (TextUtils.isEmpty(iccId)) {
5966 return false;
5967 }
5968
5969 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5970
5971 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5972 if (alphaTag == null) {
5973 editor.remove(alphaTagPrefKey);
5974 } else {
5975 editor.putString(alphaTagPrefKey, alphaTag);
5976 }
5977
5978 // Record both the line number and IMSI for this ICCID, since we need to
5979 // track all merged IMSIs based on line number
5980 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5981 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5982 if (number == null) {
5983 editor.remove(numberPrefKey);
5984 editor.remove(subscriberPrefKey);
5985 } else {
5986 editor.putString(numberPrefKey, number);
5987 editor.putString(subscriberPrefKey, subscriberId);
5988 }
5989
5990 editor.commit();
5991 return true;
5992 } finally {
5993 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005994 }
Derek Tan7226c842014-07-02 17:42:23 -07005995 }
5996
5997 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005998 public String getLine1NumberForDisplay(int subId, String callingPackage,
5999 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006000 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006001 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006002 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006003 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006004 return null;
6005 }
Derek Tan97ebb422014-09-05 16:55:38 -07006006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 final long identity = Binder.clearCallingIdentity();
6008 try {
6009 String iccId = getIccId(subId);
6010 if (iccId != null) {
6011 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6012 if (DBG_MERGE) {
6013 log("getLine1NumberForDisplay returning "
6014 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6015 }
6016 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6019 return null;
6020 } finally {
6021 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006022 }
Derek Tan7226c842014-07-02 17:42:23 -07006023 }
6024
6025 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006026 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6027 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006028 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006029 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006030 return null;
6031 }
Derek Tan97ebb422014-09-05 16:55:38 -07006032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 final long identity = Binder.clearCallingIdentity();
6034 try {
6035 String iccId = getIccId(subId);
6036 if (iccId != null) {
6037 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6038 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6039 }
6040 return null;
6041 } finally {
6042 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006043 }
Derek Tan7226c842014-07-02 17:42:23 -07006044 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006045
6046 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006047 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6048 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006049 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6050 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006051 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006052 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006053 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006054 return null;
6055 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006056
Jordan Liub49b04b2019-05-06 14:45:15 -07006057 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6058 // the process, where TelephonyManager was instantiated.
6059 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006060 final long identity = Binder.clearCallingIdentity();
6061 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006062 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063 final TelephonyManager tele = TelephonyManager.from(context);
6064 final SubscriptionManager sub = SubscriptionManager.from(context);
6065
6066 // Figure out what subscribers are currently active
6067 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068
Jordan Liub49b04b2019-05-06 14:45:15 -07006069 // Only consider subs which match the current subId
6070 // This logic can be simplified. See b/131189269 for progress.
6071 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006072 activeSubscriberIds.add(tele.getSubscriberId(subId));
6073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006074
6075 // First pass, find a number override for an active subscriber
6076 String mergeNumber = null;
6077 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6078 for (String key : prefs.keySet()) {
6079 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6080 final String subscriberId = (String) prefs.get(key);
6081 if (activeSubscriberIds.contains(subscriberId)) {
6082 final String iccId = key.substring(
6083 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6084 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6085 mergeNumber = (String) prefs.get(numberKey);
6086 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006087 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088 + " for active subscriber " + subscriberId);
6089 }
6090 if (!TextUtils.isEmpty(mergeNumber)) {
6091 break;
6092 }
6093 }
6094 }
6095 }
6096
6097 // Shortcut when no active merged subscribers
6098 if (TextUtils.isEmpty(mergeNumber)) {
6099 return null;
6100 }
6101
6102 // Second pass, find all subscribers under that line override
6103 final ArraySet<String> result = new ArraySet<>();
6104 for (String key : prefs.keySet()) {
6105 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6106 final String number = (String) prefs.get(key);
6107 if (mergeNumber.equals(number)) {
6108 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6109 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6110 final String subscriberId = (String) prefs.get(subscriberKey);
6111 if (!TextUtils.isEmpty(subscriberId)) {
6112 result.add(subscriberId);
6113 }
6114 }
6115 }
6116 }
6117
6118 final String[] resultArray = result.toArray(new String[result.size()]);
6119 Arrays.sort(resultArray);
6120 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006121 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6123 }
6124 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006125 } finally {
6126 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006127 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006128 }
6129
6130 @Override
zoey chen38003472019-12-13 17:16:31 +08006131 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6132 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006133
6134 final long identity = Binder.clearCallingIdentity();
6135 try {
6136 final TelephonyManager telephonyManager = mApp.getSystemService(
6137 TelephonyManager.class);
6138 String subscriberId = telephonyManager.getSubscriberId(subId);
6139 if (subscriberId == null) {
6140 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006141 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006142 + subId);
6143 }
6144 return null;
6145 }
6146
6147 final SubscriptionInfo info = SubscriptionController.getInstance()
6148 .getSubscriptionInfo(subId);
6149 final ParcelUuid groupUuid = info.getGroupUuid();
6150 // If it doesn't belong to any group, return just subscriberId of itself.
6151 if (groupUuid == null) {
6152 return new String[]{subscriberId};
6153 }
6154
6155 // Get all subscriberIds from the group.
6156 final List<String> mergedSubscriberIds = new ArrayList<>();
6157 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006158 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6159 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006160 for (SubscriptionInfo subInfo : groupInfos) {
6161 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6162 if (subscriberId != null) {
6163 mergedSubscriberIds.add(subscriberId);
6164 }
6165 }
6166
6167 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6168 } finally {
6169 Binder.restoreCallingIdentity(identity);
6170
6171 }
6172 }
6173
6174 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006175 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006176 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006177 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006178
6179 final long identity = Binder.clearCallingIdentity();
6180 try {
6181 final Phone phone = getPhone(subId);
6182 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6183 } finally {
6184 Binder.restoreCallingIdentity(identity);
6185 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006186 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006187
6188 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006189 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006190 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6191 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006192 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6193 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006194
6195 final long identity = Binder.clearCallingIdentity();
6196 try {
6197 final Phone phone = getPhone(subId);
6198 if (phone == null) {
6199 return false;
6200 }
6201 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6202 cdmaNonRoamingList);
6203 } finally {
6204 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006205 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006206 }
6207
6208 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006209 @Deprecated
6210 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6211 enforceModifyPermission();
6212
6213 int returnValue = 0;
6214 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006215 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006216 if(result.exception == null) {
6217 if (result.result != null) {
6218 byte[] responseData = (byte[])(result.result);
6219 if(responseData.length > oemResp.length) {
6220 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6221 responseData.length + "bytes. Buffer Size is " +
6222 oemResp.length + "bytes.");
6223 }
6224 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6225 returnValue = responseData.length;
6226 }
6227 } else {
6228 CommandException ex = (CommandException) result.exception;
6229 returnValue = ex.getCommandError().ordinal();
6230 if(returnValue > 0) returnValue *= -1;
6231 }
6232 } catch (RuntimeException e) {
6233 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6234 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6235 if(returnValue > 0) returnValue *= -1;
6236 }
6237
6238 return returnValue;
6239 }
6240
6241 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006242 public void setRadioCapability(RadioAccessFamily[] rafs) {
6243 try {
6244 ProxyController.getInstance().setRadioCapability(rafs);
6245 } catch (RuntimeException e) {
6246 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6247 }
6248 }
6249
6250 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006251 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006252 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006253 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006254 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006255 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006256 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257 final long identity = Binder.clearCallingIdentity();
6258 try {
chen xub97461a2018-10-26 14:17:57 -07006259 TelephonyPermissions
6260 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6261 mApp, phone.getSubId(), "getRadioAccessFamily");
6262 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006263 } finally {
6264 Binder.restoreCallingIdentity(identity);
6265 }
chen xub97461a2018-10-26 14:17:57 -07006266 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006267 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006268
6269 @Override
6270 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006271 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006272 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006273
6274 final long identity = Binder.clearCallingIdentity();
6275 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006276 ImsManager.getInstance(defaultPhone.getContext(),
6277 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278 } finally {
6279 Binder.restoreCallingIdentity(identity);
6280 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006281 }
6282
6283 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006284 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006285 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6287 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006288 return false;
6289 }
Svet Ganovb320e182015-04-16 12:30:10 -07006290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006291 final long identity = Binder.clearCallingIdentity();
6292 try {
6293 // Check the user preference and the system-level IMS setting. Even if the user has
6294 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6295 // In the long run, we may instead need to check if there exists a connection service
6296 // which can support video calling.
6297 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006298 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 return imsManager.isVtEnabledByPlatform()
6300 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6301 && imsManager.isVtEnabledByUser();
6302 } finally {
6303 Binder.restoreCallingIdentity(identity);
6304 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006305 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006306
Andrew Leea1239f22015-03-02 17:44:07 -08006307 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006308 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6309 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006311 mApp, subId, callingPackage, callingFeatureId,
6312 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006313 return false;
6314 }
6315
6316 final long identity = Binder.clearCallingIdentity();
6317 try {
6318 CarrierConfigManager configManager =
6319 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006320 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6322 } finally {
6323 Binder.restoreCallingIdentity(identity);
6324 }
Andrew Leea1239f22015-03-02 17:44:07 -08006325 }
6326
6327 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006328 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006330 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006331 return false;
6332 }
6333
6334 final long identity = Binder.clearCallingIdentity();
6335 try {
6336 CarrierConfigManager configManager =
6337 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006338 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006339 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6340 } finally {
6341 Binder.restoreCallingIdentity(identity);
6342 }
Andrew Leea1239f22015-03-02 17:44:07 -08006343 }
6344
Andrew Lee9431b832015-03-09 18:46:45 -07006345 @Override
6346 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006347 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006348 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006349 }
6350
6351 @Override
6352 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 final long identity = Binder.clearCallingIdentity();
6354 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006355 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356 } finally {
6357 Binder.restoreCallingIdentity(identity);
6358 }
Andrew Lee9431b832015-03-09 18:46:45 -07006359 }
6360
Hall Liuf6668912018-10-31 17:05:23 -07006361 /**
6362 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6363 * support for the feature and device firmware support.
6364 *
6365 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6366 */
6367 @Override
6368 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006369 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006370 final Phone phone = getPhone(subscriptionId);
6371 if (phone == null) {
6372 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6373 return false;
6374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006376 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6378 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006379 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380 return isCarrierSupported && isDeviceSupported;
6381 } finally {
6382 Binder.restoreCallingIdentity(identity);
6383 }
Hall Liu98187582018-01-22 19:15:32 -08006384 }
6385
Hall Liuf6668912018-10-31 17:05:23 -07006386 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006387 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6388 * RTT setting, will return true if the device and carrier both support RTT.
6389 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006390 */
6391 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006392 final long identity = Binder.clearCallingIdentity();
6393 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006394 boolean isRttSupported = isRttSupported(subscriptionId);
6395 boolean isUserRttSettingOn = Settings.Secure.getInt(
6396 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6397 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6398 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6399 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400 } finally {
6401 Binder.restoreCallingIdentity(identity);
6402 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006403 }
6404
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006405 @Deprecated
6406 @Override
6407 public String getDeviceId(String callingPackage) {
6408 return getDeviceIdWithFeature(callingPackage, null);
6409 }
6410
Sanket Padawe7310cc72015-01-14 09:53:20 -08006411 /**
6412 * Returns the unique device ID of phone, for example, the IMEI for
6413 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6414 *
6415 * <p>Requires Permission:
6416 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6417 */
6418 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006419 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006420 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006421 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006422 return null;
6423 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006424 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006425 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006426 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006427 return null;
6428 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429
6430 final long identity = Binder.clearCallingIdentity();
6431 try {
6432 return phone.getDeviceId();
6433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006436 }
6437
Ping Sunc67b7c22016-03-02 19:16:45 +08006438 /**
6439 * {@hide}
6440 * Returns the IMS Registration Status on a particular subid
6441 *
6442 * @param subId
6443 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006444 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006445 Phone phone = getPhone(subId);
6446 if (phone != null) {
6447 return phone.isImsRegistered();
6448 } else {
6449 return false;
6450 }
6451 }
6452
Santos Cordon7a1885b2015-02-03 11:15:19 -08006453 @Override
6454 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006455 final long identity = Binder.clearCallingIdentity();
6456 try {
6457 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6458 } finally {
6459 Binder.restoreCallingIdentity(identity);
6460 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006461 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006462
Tyler Gunnf70ed162019-04-03 15:28:53 -07006463 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006464 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006465 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006467 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006468 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6469 }
6470 final long identity = Binder.clearCallingIdentity();
6471 try {
6472 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6473 } finally {
6474 Binder.restoreCallingIdentity(identity);
6475 }
6476 }
6477
6478 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006479 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6480 final long identity = Binder.clearCallingIdentity();
6481 try {
6482 Phone phone = getPhone(subscriptionId);
6483 if (phone == null) {
6484 return null;
6485 }
6486 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6487 } finally {
6488 Binder.restoreCallingIdentity(identity);
6489 }
6490 }
6491
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006492 /**
6493 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006494 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006495 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006496 final long identity = Binder.clearCallingIdentity();
6497 try {
6498 Phone phone = getPhone(subId);
6499 if (phone != null) {
6500 return phone.isWifiCallingEnabled();
6501 } else {
6502 return false;
6503 }
6504 } finally {
6505 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006506 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006507 }
6508
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006509 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006510 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006511 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006512 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513 final long identity = Binder.clearCallingIdentity();
6514 try {
6515 Phone phone = getPhone(subId);
6516 if (phone != null) {
6517 return phone.isVideoEnabled();
6518 } else {
6519 return false;
6520 }
6521 } finally {
6522 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006523 }
6524 }
6525
6526 /**
6527 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6528 * defined in {@link ImsRegistrationImplBase}.
6529 */
6530 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006531 final long identity = Binder.clearCallingIdentity();
6532 try {
6533 Phone phone = getPhone(subId);
6534 if (phone != null) {
6535 return phone.getImsRegistrationTech();
6536 } else {
6537 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6538 }
6539 } finally {
6540 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006541 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006542 }
6543
Stuart Scott8eef64f2015-04-08 15:13:54 -07006544 @Override
6545 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006546 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006547 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6548 return;
6549 }
6550
Svet Ganovcc087f82015-05-12 20:35:54 -07006551 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006552
Svet Ganovcc087f82015-05-12 20:35:54 -07006553 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006554 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6555 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006556 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006557 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006558 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006559 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6560 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006561 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006562 // There has been issues when Sms raw table somehow stores orphan
6563 // fragments. They lead to garbled message when new fragments come
6564 // in and combined with those stale ones. In case this happens again,
6565 // user can reset all network settings which will clean up this table.
6566 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006567 // Clean up IMS settings as well here.
6568 int slotId = getSlotIndex(subId);
6569 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6570 ImsManager.getInstance(mApp, slotId).factoryReset();
6571 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006572
6573 // Erase modem config if erase modem on network setting is enabled.
6574 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6575 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6576 if (configValue != null && Boolean.parseBoolean(configValue)) {
6577 sendEraseModemConfig(getDefaultPhone());
6578 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006579 } finally {
6580 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006581 }
6582 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006583
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006584 private void cleanUpSmsRawTable(Context context) {
6585 ContentResolver resolver = context.getContentResolver();
6586 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6587 resolver.delete(uri, null, null);
6588 }
6589
Narayan Kamath1c496c22015-04-16 14:40:19 +01006590 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006591 public String getSimLocaleForSubscriber(int subId) {
6592 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6593 final Phone phone = getPhone(subId);
6594 if (phone == null) {
6595 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006596 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598 final long identity = Binder.clearCallingIdentity();
6599 try {
chen xu5d3637b2019-01-21 23:31:38 -08006600 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006601 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006602 if (info == null) {
6603 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6604 return null;
6605 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006606 // Try and fetch the locale from the carrier properties or from the SIM language
6607 // preferences (EF-PL and EF-LI)...
6608 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006610 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6611 if (localeFromDefaultSim != null) {
6612 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6613 if (DBG) log("Using locale from subId: " + subId + " locale: "
6614 + localeFromDefaultSim);
6615 return localeFromDefaultSim.toLanguageTag();
6616 } else {
6617 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006618 }
6619 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006621 // The SIM language preferences only store a language (e.g. fr = French), not an
6622 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6623 // the SIM and carrier preferences does not include a country we add the country
6624 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006625 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006626 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006627 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628 return mccLocale.toLanguageTag();
6629 }
6630
6631 if (DBG) log("No locale found - returning null");
6632 return null;
6633 } finally {
6634 Binder.restoreCallingIdentity(identity);
6635 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006636 }
6637
6638 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006639 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6640 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006641 }
6642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643 /**
6644 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6645 */
6646 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006647 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6648 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006649 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006650
Chenjie Yu1ba97252018-01-11 18:16:20 -08006651 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006652 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006653
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006654 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006655 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6656 * representing the state of the modem.
6657 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006658 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6659 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006660 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006661 */
6662 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006663 public void requestModemActivityInfo(ResultReceiver result) {
6664 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006665 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006666
6667 final long identity = Binder.clearCallingIdentity();
6668 try {
6669 ModemActivityInfo ret = null;
6670 synchronized (mLastModemActivityInfo) {
6671 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6672 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006673 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006674 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006675 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006676 int[] txTimeMs = info.getTransmitTimeMillis();
6677 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006678 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006679 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006680 }
6681 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006682 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6683 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684 mLastModemActivityInfo.setIdleTimeMillis(
6685 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006686 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6687 mLastModemActivityInfo.setReceiveTimeMillis(
6688 info.getReceiveTimeMillis() + mLastModemActivityInfo
6689 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006690 }
Chen Xud78231e2019-09-10 18:49:52 -07006691
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006692 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6693 mLastModemActivityInfo.getSleepTimeMillis(),
6694 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006695 mLastModemActivityInfo.getTransmitTimeMillis(),
6696 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006698 Bundle bundle = new Bundle();
6699 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6700 result.send(0, bundle);
6701 } finally {
6702 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006703 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006704 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006705
Siddharth Rayb8114062018-06-17 15:02:38 -07006706 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6707 // less than total activity duration.
6708 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6709 if (info == null) {
6710 return false;
6711 }
6712 int activityDurationMs =
6713 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6714 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006715 int[] txTimeMs = info.getTransmitTimeMillis();
6716 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6717 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006718 }
6719 return (info.isValid()
6720 && (info.getSleepTimeMillis() <= activityDurationMs)
6721 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006722 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006723 && (totalTxTimeMs <= activityDurationMs));
6724 }
6725
Jack Yu85bd38a2015-11-09 11:34:32 -08006726 /**
6727 * {@hide}
6728 * Returns the service state information on specified subscription.
6729 */
6730 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006731 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6732 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006733 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006734 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006735 return null;
6736 }
6737
Hall Liuf19c44f2018-11-27 14:38:17 -08006738 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6739 LocationAccessPolicy.checkLocationPermission(mApp,
6740 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6741 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006742 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006743 .setCallingPid(Binder.getCallingPid())
6744 .setCallingUid(Binder.getCallingUid())
6745 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006746 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006747 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6748 .build());
6749
6750 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6751 LocationAccessPolicy.checkLocationPermission(mApp,
6752 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6753 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006754 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006755 .setCallingPid(Binder.getCallingPid())
6756 .setCallingUid(Binder.getCallingUid())
6757 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006758 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006759 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6760 .build());
6761 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6762 boolean hasFinePermission =
6763 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6764 boolean hasCoarsePermission =
6765 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 final long identity = Binder.clearCallingIdentity();
6768 try {
6769 final Phone phone = getPhone(subId);
6770 if (phone == null) {
6771 return null;
6772 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006773
Hall Liuf19c44f2018-11-27 14:38:17 -08006774 ServiceState ss = phone.getServiceState();
6775
6776 // Scrub out the location info in ServiceState depending on what level of access
6777 // the caller has.
6778 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006779 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6780 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 } finally {
6782 Binder.restoreCallingIdentity(identity);
6783 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006784 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006785
6786 /**
6787 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6788 *
6789 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6790 * voicemail ringtone.
6791 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6792 * PhoneAccount.
6793 */
6794 @Override
6795 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796 final long identity = Binder.clearCallingIdentity();
6797 try {
6798 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6799 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006800 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006802
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6804 } finally {
6805 Binder.restoreCallingIdentity(identity);
6806 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006807 }
6808
6809 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006810 * Sets the per-account voicemail ringtone.
6811 *
6812 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6813 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6814 *
6815 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6816 * voicemail ringtone.
6817 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6818 * PhoneAccount.
6819 */
6820 @Override
6821 public void setVoicemailRingtoneUri(String callingPackage,
6822 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006823 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006824 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006825 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6826 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6828 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6829 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006830 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831
6832 final long identity = Binder.clearCallingIdentity();
6833 try {
6834 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6835 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006836 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006837 }
6838 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6839 } finally {
6840 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006841 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006842 }
6843
6844 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006845 * Returns whether vibration is set for voicemail notification in Phone settings.
6846 *
6847 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6848 * voicemail vibration setting.
6849 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6850 */
6851 @Override
6852 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006853 final long identity = Binder.clearCallingIdentity();
6854 try {
6855 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6856 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006857 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006858 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006860 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6861 } finally {
6862 Binder.restoreCallingIdentity(identity);
6863 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006864 }
6865
Youhan Wange64578a2016-05-02 15:32:42 -07006866 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006867 * Sets the per-account voicemail vibration.
6868 *
6869 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6870 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6871 *
6872 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6873 * voicemail vibration setting.
6874 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6875 * specific PhoneAccount.
6876 */
6877 @Override
6878 public void setVoicemailVibrationEnabled(String callingPackage,
6879 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006880 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006881 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006882 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6883 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6885 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6886 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006887 }
6888
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006889 final long identity = Binder.clearCallingIdentity();
6890 try {
6891 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6892 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006893 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006894 }
6895 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6896 } finally {
6897 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006898 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006899 }
6900
6901 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006902 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6903 *
6904 * @throws SecurityException if the caller does not have the required permission
6905 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006906 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006907 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006908 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006909 }
6910
6911 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006912 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6913 * permission.
6914 *
6915 * @throws SecurityException if the caller does not have the required permission
6916 */
6917 private void enforceSendSmsPermission() {
6918 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6919 }
6920
6921 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006922 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006923 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006924 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006925 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006926 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006927 final long identity = Binder.clearCallingIdentity();
6928 try {
6929 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006930 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006931 if (componentName == null) {
6932 throw new SecurityException(
6933 "Caller not current active visual voicemail package[null]");
6934 }
6935 String vvmPackage = componentName.getPackageName();
6936 if (!callingPackage.equals(vvmPackage)) {
6937 throw new SecurityException("Caller not current active visual voicemail package["
6938 + vvmPackage + "]");
6939 }
6940 } finally {
6941 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006942 }
6943 }
6944
6945 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006946 * Return the application ID for the app type.
6947 *
6948 * @param subId the subscription ID that this request applies to.
6949 * @param appType the uicc app type.
6950 * @return Application ID for specificied app type, or null if no uicc.
6951 */
6952 @Override
6953 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006954 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006955 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006956
6957 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006958 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006959 if (phone == null) {
6960 return null;
6961 }
6962 String aid = null;
6963 try {
6964 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6965 .getApplicationByType(appType).getAid();
6966 } catch (Exception e) {
6967 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6968 }
6969 return aid;
6970 } finally {
6971 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006972 }
Youhan Wange64578a2016-05-02 15:32:42 -07006973 }
6974
Youhan Wang4001d252016-05-11 10:29:41 -07006975 /**
6976 * Return the Electronic Serial Number.
6977 *
6978 * @param subId the subscription ID that this request applies to.
6979 * @return ESN or null if error.
6980 */
6981 @Override
6982 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006983 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006984 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006985
6986 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006987 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006988 if (phone == null) {
6989 return null;
6990 }
6991 String esn = null;
6992 try {
6993 esn = phone.getEsn();
6994 } catch (Exception e) {
6995 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6996 }
6997 return esn;
6998 } finally {
6999 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007000 }
Youhan Wang4001d252016-05-11 10:29:41 -07007001 }
7002
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007003 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007004 * Return the Preferred Roaming List Version.
7005 *
7006 * @param subId the subscription ID that this request applies to.
7007 * @return PRLVersion or null if error.
7008 */
7009 @Override
7010 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007011 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007012 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007013
7014 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007015 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007016 if (phone == null) {
7017 return null;
7018 }
7019 String cdmaPrlVersion = null;
7020 try {
7021 cdmaPrlVersion = phone.getCdmaPrlVersion();
7022 } catch (Exception e) {
7023 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7024 }
7025 return cdmaPrlVersion;
7026 } finally {
7027 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007028 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007029 }
7030
7031 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007032 * Get snapshot of Telephony histograms
7033 * @return List of Telephony histograms
7034 * @hide
7035 */
7036 @Override
7037 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7039 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040
7041 final long identity = Binder.clearCallingIdentity();
7042 try {
7043 return RIL.getTelephonyRILTimingHistograms();
7044 } finally {
7045 Binder.restoreCallingIdentity(identity);
7046 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007047 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007048
7049 /**
7050 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007051 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7052 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007053 * Require system privileges. In the future we may add this to carrier APIs.
7054 *
Michele Berionne482f8202018-11-27 18:57:59 -08007055 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007056 */
7057 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007058 @TelephonyManager.SetCarrierRestrictionResult
7059 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007060 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007061 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007062
Michele Berionne482f8202018-11-27 18:57:59 -08007063 if (carrierRestrictionRules == null) {
7064 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007065 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007066
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067 final long identity = Binder.clearCallingIdentity();
7068 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007069 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007070 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071 } finally {
7072 Binder.restoreCallingIdentity(identity);
7073 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007074 }
7075
7076 /**
7077 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007078 * Get the allowed carrier list and the excluded carrier list, including the priority between
7079 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007080 * Require system privileges. In the future we may add this to carrier APIs.
7081 *
Michele Berionne482f8202018-11-27 18:57:59 -08007082 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007083 */
7084 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007085 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007086 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007087 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007088
7089 final long identity = Binder.clearCallingIdentity();
7090 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007091 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7092 if (response instanceof CarrierRestrictionRules) {
7093 return (CarrierRestrictionRules) response;
7094 }
7095 // Response is an Exception of some kind,
7096 // which is signalled to the user as a NULL retval
7097 return null;
7098 } catch (Exception e) {
7099 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7100 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007101 } finally {
7102 Binder.restoreCallingIdentity(identity);
7103 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007104 }
7105
fionaxu59545b42016-05-25 15:53:37 -07007106 /**
7107 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7108 * @param subId the subscription ID that this action applies to.
7109 * @param enabled control enable or disable metered apns.
7110 * {@hide}
7111 */
7112 @Override
7113 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7114 enforceModifyPermission();
7115 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116
7117 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007118 if (phone == null) {
7119 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7120 return;
7121 }
7122 try {
7123 phone.carrierActionSetMeteredApnsEnabled(enabled);
7124 } catch (Exception e) {
7125 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126 } finally {
7127 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007128 }
7129 }
7130
7131 /**
7132 * Action set from carrier signalling broadcast receivers to enable/disable radio
7133 * @param subId the subscription ID that this action applies to.
7134 * @param enabled control enable or disable radio.
7135 * {@hide}
7136 */
7137 @Override
7138 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7139 enforceModifyPermission();
7140 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141
7142 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007143 if (phone == null) {
7144 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7145 return;
7146 }
7147 try {
7148 phone.carrierActionSetRadioEnabled(enabled);
7149 } catch (Exception e) {
7150 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151 } finally {
7152 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007153 }
7154 }
7155
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007156 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007157 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7158 * network status based on which carrier apps could apply actions accordingly,
7159 * enable/disable default url handler for example.
7160 *
7161 * @param subId the subscription ID that this action applies to.
7162 * @param report control start/stop reporting the default network status.
7163 * {@hide}
7164 */
7165 @Override
7166 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7167 enforceModifyPermission();
7168 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007169
7170 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007171 if (phone == null) {
7172 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7173 return;
7174 }
7175 try {
7176 phone.carrierActionReportDefaultNetworkStatus(report);
7177 } catch (Exception e) {
7178 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179 } finally {
7180 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007181 }
7182 }
7183
7184 /**
fionaxud9622282017-07-17 17:51:30 -07007185 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7186 * @param subId the subscription ID that this action applies to.
7187 * {@hide}
7188 */
7189 @Override
7190 public void carrierActionResetAll(int subId) {
7191 enforceModifyPermission();
7192 final Phone phone = getPhone(subId);
7193 if (phone == null) {
7194 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7195 return;
7196 }
7197 try {
7198 phone.carrierActionResetAll();
7199 } catch (Exception e) {
7200 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7201 }
7202 }
7203
7204 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007205 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7206 * bug report is being generated.
7207 */
7208 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007209 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007210 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7211 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007212 writer.println("Permission Denial: can't dump Phone from pid="
7213 + Binder.getCallingPid()
7214 + ", uid=" + Binder.getCallingUid()
7215 + "without permission "
7216 + android.Manifest.permission.DUMP);
7217 return;
7218 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007219 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007220 }
Jack Yueb89b242016-06-22 13:27:47 -07007221
Brad Ebingerdac2f002018-04-03 15:17:52 -07007222 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007223 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7224 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7225 @NonNull String[] args) {
7226 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7227 this, in.getFileDescriptor(), out.getFileDescriptor(),
7228 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007229 }
7230
Jack Yueb89b242016-06-22 13:27:47 -07007231 /**
Jack Yu84291ec2017-05-26 16:07:50 -07007232 * Get aggregated video call data usage since boot.
7233 *
7234 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
7235 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07007236 * {@hide}
7237 */
7238 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07007239 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07007240 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
7241 null);
7242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 final long identity = Binder.clearCallingIdentity();
7244 try {
7245 // NetworkStatsService keeps tracking the active network interface and identity. It
7246 // records the delta with the corresponding network identity.
7247 // We just return the total video call data usage snapshot since boot.
7248 Phone phone = getPhone(subId);
7249 if (phone != null) {
7250 return phone.getVtDataUsage(perUidStats);
7251 }
7252 return null;
7253 } finally {
7254 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07007255 }
Jack Yueb89b242016-06-22 13:27:47 -07007256 }
Jack Yu75ab2952016-07-08 14:29:33 -07007257
7258 /**
7259 * Policy control of data connection. Usually used when data limit is passed.
7260 * @param enabled True if enabling the data, otherwise disabling.
7261 * @param subId Subscription index
7262 * {@hide}
7263 */
7264 @Override
7265 public void setPolicyDataEnabled(boolean enabled, int subId) {
7266 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007267
7268 final long identity = Binder.clearCallingIdentity();
7269 try {
7270 Phone phone = getPhone(subId);
7271 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007272 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007273 }
7274 } finally {
7275 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007276 }
7277 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007278
7279 /**
7280 * Get Client request stats
7281 * @return List of Client Request Stats
7282 * @hide
7283 */
7284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007285 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7286 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007288 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007289 return null;
7290 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007291 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007293 final long identity = Binder.clearCallingIdentity();
7294 try {
7295 if (phone != null) {
7296 return phone.getClientRequestStats();
7297 }
7298
7299 return null;
7300 } finally {
7301 Binder.restoreCallingIdentity(identity);
7302 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007303 }
7304
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007305 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007306 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007307 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007308 }
Jack Yueb4124c2017-02-16 15:32:43 -08007309
7310 /**
Grace Chen70990072017-03-24 17:21:30 -07007311 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007312 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007313 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007314 * @param state State of SIM (power down, power up, pass through)
7315 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7316 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7317 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007318 *
7319 **/
7320 @Override
Grace Chen70990072017-03-24 17:21:30 -07007321 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007322 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007323 Phone phone = PhoneFactory.getPhone(slotIndex);
7324
vagdeviaf9a5b92018-08-15 16:01:53 -07007325 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 final long identity = Binder.clearCallingIdentity();
7328 try {
7329 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007330 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007331 }
7332 } finally {
7333 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007334 }
7335 }
Shuo Qiandd210312017-04-12 22:11:33 +00007336
Tyler Gunn65d45c22017-06-05 11:22:26 -07007337 private boolean isUssdApiAllowed(int subId) {
7338 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007339 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007340 if (configManager == null) {
7341 return false;
7342 }
7343 PersistableBundle pb = configManager.getConfigForSubId(subId);
7344 if (pb == null) {
7345 return false;
7346 }
7347 return pb.getBoolean(
7348 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7349 }
7350
Shuo Qiandd210312017-04-12 22:11:33 +00007351 /**
7352 * Check if phone is in emergency callback mode
7353 * @return true if phone is in emergency callback mode
7354 * @param subId sub id
7355 */
goneil9c5f4872017-12-05 14:07:56 -08007356 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007357 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007358 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007359 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360
7361 final long identity = Binder.clearCallingIdentity();
7362 try {
7363 if (phone != null) {
7364 return phone.isInEcm();
7365 } else {
7366 return false;
7367 }
7368 } finally {
7369 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007370 }
7371 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007372
7373 /**
7374 * Get the current signal strength information for the given subscription.
7375 * Because this information is not updated when the device is in a low power state
7376 * it should not be relied-upon to be current.
7377 * @param subId Subscription index
7378 * @return the most recent cached signal strength info from the modem
7379 */
7380 @Override
7381 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 final long identity = Binder.clearCallingIdentity();
7383 try {
7384 Phone p = getPhone(subId);
7385 if (p == null) {
7386 return null;
7387 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 return p.getSignalStrength();
7390 } finally {
7391 Binder.restoreCallingIdentity(identity);
7392 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007393 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007394
Pengquan Meng77b7f132018-08-22 14:49:57 -07007395 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007396 * Get the current modem radio state for the given slot.
7397 * @param slotIndex slot index.
7398 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007399 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007400 * @return the current radio power state from the modem
7401 */
7402 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007403 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007404 Phone phone = PhoneFactory.getPhone(slotIndex);
7405 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007406 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7407 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007408 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7409 }
7410
7411 final long identity = Binder.clearCallingIdentity();
7412 try {
7413 return phone.getRadioPowerState();
7414 } finally {
7415 Binder.restoreCallingIdentity(identity);
7416 }
7417 }
7418 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7419 }
7420
7421 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007422 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7423 *
7424 * <p>Requires one of the following permissions:
7425 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7426 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7427 * privileges.
7428 *
7429 * @param subId subscription id
7430 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7431 * {@code false}.
7432 */
7433 @Override
7434 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007435 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7436 null /* message */);
7437
Pengquan Menga1bb6272018-09-06 09:59:22 -07007438 boolean isEnabled = false;
7439 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007440 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007441 Phone phone = getPhone(subId);
7442 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007443 } catch (Exception e) {
7444 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7445 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007446 } finally {
7447 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007448 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007449 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007450 }
7451
7452
7453 /**
7454 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7455 *
7456 * <p> Requires permission:
7457 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7458 * privileges.
7459 *
7460 * @param subId subscription id
7461 * @param isEnabled {@code true} means enable, {@code false} means disable.
7462 */
7463 @Override
7464 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7466 mApp, subId, "setDataRoamingEnabled");
7467
Pengquan Menga1bb6272018-09-06 09:59:22 -07007468 final long identity = Binder.clearCallingIdentity();
7469 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007470 Phone phone = getPhone(subId);
7471 if (phone != null) {
7472 phone.setDataRoamingEnabled(isEnabled);
7473 }
7474 } finally {
7475 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007476 }
7477 }
7478
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007479 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007480 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007481 TelephonyPermissions
7482 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007483 mApp, subId, "isManualNetworkSelectionAllowed");
7484
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007485 boolean isAllowed = true;
7486 final long identity = Binder.clearCallingIdentity();
7487 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007488 Phone phone = getPhone(subId);
7489 if (phone != null) {
7490 isAllowed = phone.isCspPlmnEnabled();
7491 }
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
7494 }
7495 return isAllowed;
7496 }
7497
7498 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007499 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007500 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007501 try {
7502 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007503 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007504 } catch (SecurityException e) {
7505 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7506 // has carrier privileges on an active UICC
7507 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7508 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007509 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007510 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007511 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007512
7513 final long identity = Binder.clearCallingIdentity();
7514 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007515 UiccController uiccController = UiccController.getInstance();
7516 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007517 if (hasReadPermission) {
7518 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007519 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007520
7521 // Remove private info if the caller doesn't have access
7522 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7523 for (UiccCardInfo cardInfo : cardInfos) {
7524 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7525 // is available
7526 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7527 if (card == null || card.getUiccProfile() == null) {
7528 // assume no access if the card or profile is unavailable
7529 filteredInfos.add(cardInfo.getUnprivileged());
7530 continue;
7531 }
7532 UiccProfile profile = card.getUiccProfile();
7533 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7534 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7535 filteredInfos.add(cardInfo);
7536 } else {
7537 filteredInfos.add(cardInfo.getUnprivileged());
7538 }
7539 }
7540 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
7544 }
7545
7546 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007547 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007548 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 final long identity = Binder.clearCallingIdentity();
7551 try {
7552 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7553 if (slots == null) {
7554 Rlog.i(LOG_TAG, "slots is null.");
7555 return null;
7556 }
7557
7558 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7559 for (int i = 0; i < slots.length; i++) {
7560 UiccSlot slot = slots[i];
7561 if (slot == null) {
7562 continue;
7563 }
7564
Jordan Liu7be7e652019-05-06 18:55:02 +00007565 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 UiccCard card = slot.getUiccCard();
7567 if (card != null) {
7568 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007569 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007570 cardId = slot.getEid();
7571 if (TextUtils.isEmpty(cardId)) {
7572 cardId = slot.getIccId();
7573 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007574 }
7575
Jordan Liu857451f2019-05-09 16:35:35 -07007576 if (cardId != null) {
7577 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7578 // if cardId is an EID, it's all digits so this is fine
7579 cardId = IccUtils.stripTrailingFs(cardId);
7580 }
7581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007582 int cardState = 0;
7583 switch (slot.getCardState()) {
7584 case CARDSTATE_ABSENT:
7585 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7586 break;
7587 case CARDSTATE_PRESENT:
7588 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7589 break;
7590 case CARDSTATE_ERROR:
7591 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7592 break;
7593 case CARDSTATE_RESTRICTED:
7594 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7595 break;
7596 default:
7597 break;
7598
7599 }
7600
7601 infos[i] = new UiccSlotInfo(
7602 slot.isActive(),
7603 slot.isEuicc(),
7604 cardId,
7605 cardState,
7606 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007607 slot.isExtendedApduSupported(),
7608 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609 }
7610 return infos;
7611 } finally {
7612 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007613 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007614 }
7615
7616 @Override
7617 public boolean switchSlots(int[] physicalSlots) {
7618 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619
7620 final long identity = Binder.clearCallingIdentity();
7621 try {
7622 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7623 } finally {
7624 Binder.restoreCallingIdentity(identity);
7625 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007626 }
Jack Yu4c988042018-02-27 15:30:01 -08007627
7628 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007629 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007630 final long identity = Binder.clearCallingIdentity();
7631 try {
7632 return UiccController.getInstance().getCardIdForDefaultEuicc();
7633 } finally {
7634 Binder.restoreCallingIdentity(identity);
7635 }
7636 }
7637
Pengquan Meng85728fb2018-03-12 16:31:21 -07007638 /**
goneil47ffb6e2018-04-06 15:40:58 -07007639 * A test API to reload the UICC profile.
7640 *
7641 * <p>Requires that the calling app has permission
7642 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7643 * @hide
7644 */
7645 @Override
7646 public void refreshUiccProfile(int subId) {
7647 enforceModifyPermission();
7648
7649 final long identity = Binder.clearCallingIdentity();
7650 try {
7651 Phone phone = getPhone(subId);
7652 if (phone == null) {
7653 return;
7654 }
7655 UiccCard uiccCard = phone.getUiccCard();
7656 if (uiccCard == null) {
7657 return;
7658 }
7659 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7660 if (uiccProfile == null) {
7661 return;
7662 }
7663 uiccProfile.refresh();
7664 } finally {
7665 Binder.restoreCallingIdentity(identity);
7666 }
7667 }
7668
7669 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007670 * Returns false if the mobile data is disabled by default, otherwise return true.
7671 */
7672 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007673 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007674 }
7675
7676 /**
7677 * Returns true if the data roaming is enabled by default, i.e the system property
7678 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7679 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7680 */
7681 private boolean getDefaultDataRoamingEnabled(int subId) {
7682 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007683 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007684 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007685 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7686 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7687 return isDataRoamingEnabled;
7688 }
7689
7690 /**
7691 * Returns the default network type for the given {@code subId}, if the default network type is
7692 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7693 */
7694 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007695 List<Integer> list = TelephonyProperties.default_network();
7696 int phoneId = mSubscriptionController.getPhoneId(subId);
7697 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7698 return list.get(phoneId);
7699 }
7700 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007701 }
fionaxua13278b2018-03-21 00:08:13 -07007702
7703 @Override
7704 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007705 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007706 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007707
7708 final long identity = Binder.clearCallingIdentity();
7709 try {
7710 final Phone phone = getPhone(subId);
7711 if (phone == null) {
7712 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7713 return;
7714 }
chen xueaba88a2019-03-15 13:15:10 -07007715 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7716 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007717 } finally {
7718 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007719 }
fionaxua13278b2018-03-21 00:08:13 -07007720 }
7721
7722 @Override
7723 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007724 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007725
7726 final long identity = Binder.clearCallingIdentity();
7727 try {
7728 final Phone phone = getPhone(subId);
7729 if (phone == null) {
7730 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7731 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7732 }
7733 return phone.getCarrierIdListVersion();
7734 } finally {
7735 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007736 }
fionaxua13278b2018-03-21 00:08:13 -07007737 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007738
7739 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007740 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7741 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007742 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007743 mApp, subId, callingPackage, callingFeatureId,
7744 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007745 return -1;
7746 }
7747
7748 final long identity = Binder.clearCallingIdentity();
7749 try {
7750 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7751 } finally {
7752 Binder.restoreCallingIdentity(identity);
7753 }
7754 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007755
7756 @Override
7757 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007758 TelephonyPermissions
7759 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007760 mApp, subId, "getCdmaRoamingMode");
7761
7762 final long identity = Binder.clearCallingIdentity();
7763 try {
7764 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7765 } finally {
7766 Binder.restoreCallingIdentity(identity);
7767 }
7768 }
7769
7770 @Override
7771 public boolean setCdmaRoamingMode(int subId, int mode) {
7772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7773 mApp, subId, "setCdmaRoamingMode");
7774
7775 final long identity = Binder.clearCallingIdentity();
7776 try {
7777 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7778 } finally {
7779 Binder.restoreCallingIdentity(identity);
7780 }
7781 }
7782
7783 @Override
7784 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7786 mApp, subId, "setCdmaSubscriptionMode");
7787
7788 final long identity = Binder.clearCallingIdentity();
7789 try {
7790 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7791 } finally {
7792 Binder.restoreCallingIdentity(identity);
7793 }
7794 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007795
sqianc5eccab2018-10-19 18:46:41 -07007796 @Override
sqian8c685422019-02-22 15:55:18 -08007797 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007798 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007799 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007800 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7801 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007802 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7803 }
7804 final long identity = Binder.clearCallingIdentity();
7805 try {
sqian854d44b2018-12-12 16:48:18 -08007806 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7807 for (Phone phone: PhoneFactory.getPhones()) {
7808 if (phone.getEmergencyNumberTracker() != null
7809 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7810 emergencyNumberListInternal.put(
7811 phone.getSubId(),
7812 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7813 }
sqian11b7a0e2018-12-05 18:48:28 -08007814 }
sqian854d44b2018-12-12 16:48:18 -08007815 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007816 } finally {
7817 Binder.restoreCallingIdentity(identity);
7818 }
sqianc5eccab2018-10-19 18:46:41 -07007819 }
7820
7821 @Override
sqian8c685422019-02-22 15:55:18 -08007822 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007823 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007824 if (!exactMatch) {
7825 TelephonyPermissions
7826 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007827 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007828 }
7829 final long identity = Binder.clearCallingIdentity();
7830 try {
sqian854d44b2018-12-12 16:48:18 -08007831 for (Phone phone: PhoneFactory.getPhones()) {
7832 if (phone.getEmergencyNumberTracker() != null
7833 && phone.getEmergencyNumberTracker() != null) {
7834 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7835 number, exactMatch)) {
7836 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007837 }
7838 }
sqian11b7a0e2018-12-05 18:48:28 -08007839 }
7840 return false;
7841 } finally {
7842 Binder.restoreCallingIdentity(identity);
7843 }
7844 }
7845
sqianf4ca7ed2019-01-15 18:32:07 -08007846 /**
7847 * Update emergency number list for test mode.
7848 */
7849 @Override
7850 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7851 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7852 "updateEmergencyNumberListTestMode");
7853
7854 final long identity = Binder.clearCallingIdentity();
7855 try {
7856 for (Phone phone: PhoneFactory.getPhones()) {
7857 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7858 if (tracker != null) {
7859 tracker.executeEmergencyNumberTestModeCommand(action, num);
7860 }
7861 }
7862 } finally {
7863 Binder.restoreCallingIdentity(identity);
7864 }
7865 }
7866
7867 /**
7868 * Get the full emergency number list for test mode.
7869 */
7870 @Override
7871 public List<String> getEmergencyNumberListTestMode() {
7872 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7873 "getEmergencyNumberListTestMode");
7874
7875 final long identity = Binder.clearCallingIdentity();
7876 try {
7877 Set<String> emergencyNumbers = new HashSet<>();
7878 for (Phone phone: PhoneFactory.getPhones()) {
7879 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7880 if (tracker != null) {
7881 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7882 emergencyNumbers.add(num.getNumber());
7883 }
7884 }
7885 }
7886 return new ArrayList<>(emergencyNumbers);
7887 } finally {
7888 Binder.restoreCallingIdentity(identity);
7889 }
7890 }
7891
chen xud6b45bd2018-10-30 22:27:10 -07007892 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007893 public int getEmergencyNumberDbVersion(int subId) {
7894 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7895
7896 final long identity = Binder.clearCallingIdentity();
7897 try {
7898 final Phone phone = getPhone(subId);
7899 if (phone == null) {
7900 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7901 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7902 }
7903 return phone.getEmergencyNumberDbVersion();
7904 } finally {
7905 Binder.restoreCallingIdentity(identity);
7906 }
7907 }
7908
7909 @Override
7910 public void notifyOtaEmergencyNumberDbInstalled() {
7911 enforceModifyPermission();
7912
7913 final long identity = Binder.clearCallingIdentity();
7914 try {
7915 for (Phone phone: PhoneFactory.getPhones()) {
7916 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7917 if (tracker != null) {
7918 tracker.updateOtaEmergencyNumberDatabase();
7919 }
7920 }
7921 } finally {
7922 Binder.restoreCallingIdentity(identity);
7923 }
7924 }
7925
7926 @Override
7927 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7928 enforceActiveEmergencySessionPermission();
7929
7930 final long identity = Binder.clearCallingIdentity();
7931 try {
7932 for (Phone phone: PhoneFactory.getPhones()) {
7933 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7934 if (tracker != null) {
7935 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7936 }
7937 }
7938 } finally {
7939 Binder.restoreCallingIdentity(identity);
7940 }
7941 }
7942
7943 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007944 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7945 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7946 Phone phone = getPhone(subId);
7947 if (phone == null) {
7948 return null;
7949 }
7950 final long identity = Binder.clearCallingIdentity();
7951 try {
7952 UiccProfile profile = UiccController.getInstance()
7953 .getUiccProfileForPhone(phone.getPhoneId());
7954 if (profile != null) {
7955 return profile.getCertsFromCarrierPrivilegeAccessRules();
7956 }
7957 } finally {
7958 Binder.restoreCallingIdentity(identity);
7959 }
7960 return null;
7961 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007962
7963 /**
7964 * Enable or disable a modem stack.
7965 */
7966 @Override
7967 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7968 enforceModifyPermission();
7969
7970 final long identity = Binder.clearCallingIdentity();
7971 try {
7972 Phone phone = PhoneFactory.getPhone(slotIndex);
7973 if (phone == null) {
7974 return false;
7975 } else {
7976 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7977 }
7978 } finally {
7979 Binder.restoreCallingIdentity(identity);
7980 }
7981 }
Michelecea4cf22018-12-21 15:00:11 -08007982
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007983 /**
7984 * Whether a modem stack is enabled or not.
7985 */
7986 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007987 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7988 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007989 Phone phone = PhoneFactory.getPhone(slotIndex);
7990 if (phone == null) return false;
7991
7992 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007993 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7994 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007995 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7996 }
7997
7998 final long identity = Binder.clearCallingIdentity();
7999 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008000 try {
8001 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8002 } catch (NoSuchElementException ex) {
8003 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8004 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008005 } finally {
8006 Binder.restoreCallingIdentity(identity);
8007 }
8008 }
8009
Michelecea4cf22018-12-21 15:00:11 -08008010 @Override
Michele0ea7d782019-03-19 14:58:42 -07008011 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008012 enforceModifyPermission();
8013
8014 final long identity = Binder.clearCallingIdentity();
8015 try {
8016 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008017 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008018 .commit();
8019 } finally {
8020 Binder.restoreCallingIdentity(identity);
8021 }
8022 }
8023
8024 @Override
Michele0ea7d782019-03-19 14:58:42 -07008025 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008026 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008027 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008028 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8029 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008030 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008031 }
Michelecea4cf22018-12-21 15:00:11 -08008032
8033 final long identity = Binder.clearCallingIdentity();
8034 try {
Michele0ea7d782019-03-19 14:58:42 -07008035 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008036 } finally {
8037 Binder.restoreCallingIdentity(identity);
8038 }
8039 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008040
Michele0ea7d782019-03-19 14:58:42 -07008041 @TelephonyManager.IsMultiSimSupportedResult
8042 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008043 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8044 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8045 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008046 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8047 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008048 }
8049 // Check if the hardware supports multisim functionality. If usage of multisim is not
8050 // supported by the modem, indicate that it is restricted.
8051 PhoneCapability staticCapability =
8052 mPhoneConfigurationManager.getStaticPhoneCapability();
8053 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008054 loge("isMultiSimSupportedInternal: no static configuration available");
8055 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008056 }
Sarah Chin0605abf2019-12-06 10:24:18 -08008057 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008058 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8059 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008060 }
8061 // Check if support of multiple SIMs is restricted by carrier
8062 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008063 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008064 }
8065
Michele0ea7d782019-03-19 14:58:42 -07008066 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008067 }
8068
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008069 /**
8070 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008071 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8072 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8073 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008074 * @param numOfSims number of active sims we want to switch to
8075 */
8076 @Override
8077 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008078 if (numOfSims == 1) {
8079 enforceModifyPermission();
8080 } else {
8081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8082 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8083 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008084 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008085
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008086 try {
Michele30b57b22019-03-01 12:01:14 -08008087 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008088 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008089 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8090 return;
8091 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008092 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8093 } finally {
8094 Binder.restoreCallingIdentity(identity);
8095 }
8096 }
8097
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008098 @Override
8099 public boolean isApplicationOnUicc(int subId, int appType) {
8100 enforceReadPrivilegedPermission("isApplicationOnUicc");
8101 Phone phone = getPhone(subId);
8102 if (phone == null) {
8103 return false;
8104 }
8105 final long identity = Binder.clearCallingIdentity();
8106 try {
8107 UiccCard uiccCard = phone.getUiccCard();
8108 if (uiccCard == null) {
8109 return false;
8110 }
8111 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8112 if (uiccProfile == null) {
8113 return false;
8114 }
8115 if (TelephonyManager.APPTYPE_SIM <= appType
8116 && appType <= TelephonyManager.APPTYPE_ISIM) {
8117 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8118 }
8119 return false;
8120 } finally {
8121 Binder.restoreCallingIdentity(identity);
8122 }
8123 }
8124
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008125 /**
chen xub4baa772019-04-03 10:23:41 -07008126 * Get whether making changes to modem configurations will trigger reboot.
8127 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008128 */
8129 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008130 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8131 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008133 mApp, subId, callingPackage, callingFeatureId,
8134 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008135 return false;
8136 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008137 final long identity = Binder.clearCallingIdentity();
8138 try {
8139 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8140 } finally {
8141 Binder.restoreCallingIdentity(identity);
8142 }
8143 }
8144
Nathan Harold29f5f052019-02-15 13:41:57 -08008145 private void updateModemStateMetrics() {
8146 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8147 // TODO: check the state for each modem if the api is ready.
8148 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8149 }
8150
Pengquan Meng3889a572019-01-23 11:16:29 -08008151 @Override
8152 public int[] getSlotsMapping() {
8153 enforceReadPrivilegedPermission("getSlotsMapping");
8154
8155 final long identity = Binder.clearCallingIdentity();
8156 try {
8157 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8158 // All logical slots should have a mapping to a physical slot.
8159 int[] logicalSlotsMapping = new int[phoneCount];
8160 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8161 for (int i = 0; i < slotInfos.length; i++) {
8162 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8163 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8164 }
8165 }
8166 return logicalSlotsMapping;
8167 } finally {
8168 Binder.restoreCallingIdentity(identity);
8169 }
8170 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008171
8172 /**
8173 * Get the IRadio HAL Version
8174 */
8175 @Override
8176 public int getRadioHalVersion() {
8177 Phone phone = getDefaultPhone();
8178 if (phone == null) return -1;
8179 HalVersion hv = phone.getHalVersion();
8180 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8181 return hv.major * 100 + hv.minor;
8182 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008183
8184 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008185 * Get the current calling package name.
8186 * @return the current calling package name
8187 */
8188 @Override
8189 public String getCurrentPackageName() {
8190 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8191 }
8192
8193 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008194 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8195 * corresponding network requests on a subId.
8196 *
8197 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008198 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008199 * 2) APN is un-metered for this subscription, or
8200 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008201 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008202 *
8203 * @return whether data is allowed for a apn type.
8204 *
8205 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008206 */
8207 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008208 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008209 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8210 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008211
8212 // Now that all security checks passes, perform the operation as ourselves.
8213 final long identity = Binder.clearCallingIdentity();
8214 try {
8215 Phone phone = getPhone(subId);
8216 if (phone == null) return false;
8217
Jack Yu41407ee2019-05-13 16:54:09 -07008218 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008219 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8220 } finally {
8221 Binder.restoreCallingIdentity(identity);
8222 }
8223 }
8224
8225 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008226 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008227 enforceReadPrivilegedPermission("isApnMetered");
8228
8229 // Now that all security checks passes, perform the operation as ourselves.
8230 final long identity = Binder.clearCallingIdentity();
8231 try {
8232 Phone phone = getPhone(subId);
8233 if (phone == null) return true; // By default return true.
8234
Jack Yu41407ee2019-05-13 16:54:09 -07008235 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008236 } finally {
8237 Binder.restoreCallingIdentity(identity);
8238 }
8239 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008240
8241 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008242 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8243 int subscriptionId, IBooleanConsumer resultCallback) {
8244 enforceModifyPermission();
8245 long token = Binder.clearCallingIdentity();
8246 try {
8247 Phone phone = getPhone(subscriptionId);
8248 if (phone == null) {
8249 try {
8250 if (resultCallback != null) {
8251 resultCallback.accept(false);
8252 }
8253 } catch (RemoteException e) {
8254 // ignore
8255 }
8256 return;
8257 }
8258 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8259 Pair.create(specifiers, (x) -> {
8260 try {
8261 if (resultCallback != null) {
8262 resultCallback.accept(x);
8263 }
8264 } catch (RemoteException e) {
8265 // ignore
8266 }
8267 });
8268 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8269 } finally {
8270 Binder.restoreCallingIdentity(token);
8271 }
8272 }
8273
8274 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008275 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8276 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8277 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8278 if (iccRecords == null) {
8279 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8280 return false;
8281 }
8282 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8283 }
8284
8285 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008286 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008287 if (callingPackage == null) {
8288 callingPackage = getCurrentPackageName();
8289 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008290 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8291 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8292 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8293 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8294 }
8295 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8296 Intent intent = new Intent();
8297 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8298 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8299 // Bring up choose default SMS subscription dialog right now
8300 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8301 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8302 mApp.startActivity(intent);
8303 }
chen xud5ca2d52019-05-28 15:20:57 -07008304
8305 @Override
8306 public String getMmsUAProfUrl(int subId) {
8307 //TODO investigate if this API should require proper permission check in R b/133791609
8308 final long identity = Binder.clearCallingIdentity();
8309 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008310 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8311 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008312 } finally {
8313 Binder.restoreCallingIdentity(identity);
8314 }
8315 }
8316
8317 @Override
8318 public String getMmsUserAgent(int subId) {
8319 //TODO investigate if this API should require proper permission check in R b/133791609
8320 final long identity = Binder.clearCallingIdentity();
8321 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008322 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8323 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008324 } finally {
8325 Binder.restoreCallingIdentity(identity);
8326 }
8327 }
Jack Yub07d4972019-05-28 16:12:25 -07008328
8329 @Override
8330 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8331 enforceModifyPermission();
8332
8333 // Now that all security checks passes, perform the operation as ourselves.
8334 final long identity = Binder.clearCallingIdentity();
8335 try {
8336 Phone phone = getPhone(subId);
8337 if (phone == null) return false;
8338
8339 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8340 } finally {
8341 Binder.restoreCallingIdentity(identity);
8342 }
8343 }
8344
8345 @Override
8346 public boolean isDataAllowedInVoiceCall(int subId) {
8347 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8348
8349 // Now that all security checks passes, perform the operation as ourselves.
8350 final long identity = Binder.clearCallingIdentity();
8351 try {
8352 Phone phone = getPhone(subId);
8353 if (phone == null) return false;
8354
8355 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8356 } finally {
8357 Binder.restoreCallingIdentity(identity);
8358 }
8359 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008360
changbettyd5c246e2019-12-24 15:40:37 +08008361 @Override
8362 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8363 enforceModifyPermission();
8364
8365 // Now that all security checks passes, perform the operation as ourselves.
8366 final long identity = Binder.clearCallingIdentity();
8367 try {
8368 Phone phone = getPhone(subId);
8369 if (phone == null) return false;
8370
8371 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8372 } finally {
8373 Binder.restoreCallingIdentity(identity);
8374 }
8375 }
8376
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008377 /**
8378 * Updates whether conference event pacakge handling is enabled.
8379 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8380 * otherwise.
8381 */
8382 @Override
8383 public void setCepEnabled(boolean isCepEnabled) {
8384 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8385
8386 final long identity = Binder.clearCallingIdentity();
8387 try {
8388 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8389 for (Phone phone : PhoneFactory.getPhones()) {
8390 Phone defaultPhone = phone.getImsPhone();
8391 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8392 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8393 ImsPhoneCallTracker imsPhoneCallTracker =
8394 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8395 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8396 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8397 + imsPhone.getMsisdn());
8398 }
8399 }
8400 } finally {
8401 Binder.restoreCallingIdentity(identity);
8402 }
8403 }
allenwtsu46dcc572020-01-08 18:24:03 +08008404
8405 /**
8406 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8407 *
8408 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8409 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8410 * before being read.
8411 */
8412 @Override
8413 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8414 isCompressed) {
8415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8416 mApp, subId, "notifyRcsAutoConfigurationReceived");
8417 try {
8418 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8419 if (configBinder == null) {
8420 Rlog.e(LOG_TAG, "null result for getImsConfig");
8421 } else {
8422 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8423 }
8424 } catch (RemoteException e) {
8425 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8426 }
8427 }
zoey chene02881a2019-12-30 16:11:23 +08008428
8429 @Override
8430 public boolean isIccLockEnabled(int subId) {
8431 enforceReadPrivilegedPermission("isIccLockEnabled");
8432
8433 // Now that all security checks passes, perform the operation as ourselves.
8434 final long identity = Binder.clearCallingIdentity();
8435 try {
8436 Phone phone = getPhone(subId);
8437 if (phone != null && phone.getIccCard() != null) {
8438 return phone.getIccCard().getIccLockEnabled();
8439 } else {
8440 return false;
8441 }
8442 } finally {
8443 Binder.restoreCallingIdentity(identity);
8444 }
8445 }
8446
8447 /**
8448 * Set the ICC pin lock enabled or disabled.
8449 *
8450 * @return an integer representing the status of IccLock enabled or disabled in the following
8451 * three cases:
8452 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8453 * successfully.
8454 * - Positive number and zero for remaining password attempts.
8455 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8456 *
8457 */
8458 @Override
8459 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8460 enforceModifyPermission();
8461
8462 Phone phone = getPhone(subId);
8463 if (phone == null) {
8464 return 0;
8465 }
8466 // Now that all security checks passes, perform the operation as ourselves.
8467 final long identity = Binder.clearCallingIdentity();
8468 try {
8469 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8470 new Pair<Boolean, String>(enabled, password), phone, null);
8471 return attemptsRemaining;
8472
8473 } catch (Exception e) {
8474 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8475 } finally {
8476 Binder.restoreCallingIdentity(identity);
8477 }
8478 return 0;
8479 }
8480
8481 /**
8482 * Change the ICC password used in ICC pin lock.
8483 *
8484 * @return an integer representing the status of IccLock changed in the following three cases:
8485 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8486 * - Positive number and zero for remaining password attempts.
8487 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8488 *
8489 */
8490 @Override
8491 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8492 enforceModifyPermission();
8493
8494 Phone phone = getPhone(subId);
8495 if (phone == null) {
8496 return 0;
8497 }
8498 // Now that all security checks passes, perform the operation as ourselves.
8499 final long identity = Binder.clearCallingIdentity();
8500 try {
8501 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8502 new Pair<String, String>(oldPassword, newPassword), phone, null);
8503 return attemptsRemaining;
8504
8505 } catch (Exception e) {
8506 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8507 } finally {
8508 Binder.restoreCallingIdentity(identity);
8509 }
8510 return 0;
8511 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008512
8513 /**
8514 * Request for receiving user activity notification
8515 */
8516 @Override
8517 public void requestUserActivityNotification() {
8518 if (!mNotifyUserActivity.get()
8519 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8520 mNotifyUserActivity.set(true);
8521 }
8522 }
8523
8524 /**
8525 * Called when userActivity is signalled in the power manager.
8526 * This is safe to call from any thread, with any window manager locks held or not.
8527 */
8528 @Override
8529 public void userActivity() {
8530 // ***************************************
8531 // * Inherited from PhoneWindowManager *
8532 // ***************************************
8533 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8534 // WITH ITS LOCKS HELD.
8535 //
8536 // This code must be VERY careful about the locks
8537 // it acquires.
8538 // In fact, the current code acquires way too many,
8539 // and probably has lurking deadlocks.
8540
8541 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8542 throw new SecurityException("Only the OS may call notifyUserActivity()");
8543 }
8544
8545 if (mNotifyUserActivity.getAndSet(false)) {
8546 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8547 USER_ACTIVITY_NOTIFICATION_DELAY);
8548 }
8549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008550}