blob: 86093a1bc3481b1c7f2baf302aa91036628c79df [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;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800120import android.util.Slog;
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;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800131import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800132import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700133import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800134import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800136import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700137import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700138import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700141import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800142import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700143import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700144import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700145import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700146import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700147import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700148import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700149import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700150import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800151import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800152import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700153import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800154import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700155import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800156import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700157import com.android.internal.telephony.imsphone.ImsPhone;
158import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800159import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700160import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800162import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700165import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000169import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800170import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700171import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800172import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800175import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700176import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700177import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800178import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800179
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700180import java.io.FileDescriptor;
181import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800184import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800186import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100187import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800188import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700189import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800190import java.util.Set;
Hall Liu73f5d362020-01-20 13:42:00 -0800191import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192
193/**
194 * Implementation of the ITelephony interface.
195 */
Santos Cordon117fee72014-05-16 17:56:12 -0700196public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197 private static final String LOG_TAG = "PhoneInterfaceManager";
198 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
199 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800200 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201
202 // Message codes used with mMainThreadHandler
203 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700204 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
205 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700206 private static final int CMD_OPEN_CHANNEL = 9;
207 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
208 private static final int CMD_CLOSE_CHANNEL = 11;
209 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800210 private static final int CMD_NV_READ_ITEM = 13;
211 private static final int EVENT_NV_READ_ITEM_DONE = 14;
212 private static final int CMD_NV_WRITE_ITEM = 15;
213 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
214 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
215 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700216 private static final int CMD_RESET_MODEM_CONFIG = 19;
217 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800218 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
219 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
220 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
221 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800222 private static final int CMD_SEND_ENVELOPE = 25;
223 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000224 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
225 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700226 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
227 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
228 private static final int CMD_EXCHANGE_SIM_IO = 31;
229 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800230 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
231 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700232 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
233 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700234 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
235 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700236 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
237 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
238 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
239 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700240 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
241 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
242 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
243 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700244 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800245 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
246 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000247 private static final int CMD_SWITCH_SLOTS = 50;
248 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700249 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
250 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
251 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
252 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
253 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
254 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
255 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
256 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700257 private static final int CMD_GET_ALL_CELL_INFO = 60;
258 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
259 private static final int CMD_GET_CELL_LOCATION = 62;
260 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700261 private static final int CMD_MODEM_REBOOT = 64;
262 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700263 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
264 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800265 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
266 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700267 private static final int CMD_GET_MODEM_STATUS = 70;
268 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700269 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
270 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700271 private static final int CMD_ERASE_MODEM_CONFIG = 74;
272 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800273 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
274 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
275 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
276 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800277 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
278 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700279
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800280 // Parameters of select command.
281 private static final int SELECT_COMMAND = 0xA4;
282 private static final int SELECT_P1 = 0x04;
283 private static final int SELECT_P2 = 0;
284 private static final int SELECT_P3 = 0x10;
285
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286 /** The singleton instance. */
287 private static PhoneInterfaceManager sInstance;
288
Wink Saville3ab207e2014-11-20 13:07:20 -0800289 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800290 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800291 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700292 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800293 private AppOpsManager mAppOps;
294 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800295 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800296 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700297 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298
Derek Tan97ebb422014-09-05 16:55:38 -0700299 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
300 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800301 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800302 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700303
Michelecea4cf22018-12-21 15:00:11 -0800304 // String to store multi SIM allowed
305 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
306
Derek Tan740e1672017-06-27 14:56:27 -0700307 // The AID of ISD-R.
308 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
309
yinxub1bed742017-04-17 11:45:04 -0700310 private NetworkScanRequestTracker mNetworkScanRequestTracker;
311
David Kelly5e06a7f2018-03-12 14:10:59 +0000312 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
313 private static final int MANUFACTURER_CODE_LENGTH = 8;
314
Derek Tan89e89d42014-07-08 17:00:10 -0700315 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700316 * Experiment flag to enable erase modem config on reset network, default value is false
317 */
318 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
319 "reset_network_erase_modem_config_enabled";
320
321 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700322 * A request object to use for transmitting data to an ICC.
323 */
324 private static final class IccAPDUArgument {
325 public int channel, cla, command, p1, p2, p3;
326 public String data;
327
328 public IccAPDUArgument(int channel, int cla, int command,
329 int p1, int p2, int p3, String data) {
330 this.channel = channel;
331 this.cla = cla;
332 this.command = command;
333 this.p1 = p1;
334 this.p2 = p2;
335 this.p3 = p3;
336 this.data = data;
337 }
338 }
339
340 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700341 * A request object to use for transmitting data to an ICC.
342 */
343 private static final class ManualNetworkSelectionArgument {
344 public OperatorInfo operatorInfo;
345 public boolean persistSelection;
346
347 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
348 this.operatorInfo = operatorInfo;
349 this.persistSelection = persistSelection;
350 }
351 }
352
353 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
355 * request after sending. The main thread will notify the request when it is complete.
356 */
357 private static final class MainThreadRequest {
358 /** The argument to use for the request */
359 public Object argument;
360 /** The result of the request that is run on the main thread */
361 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800362 // The subscriber id that this request applies to. Defaults to
363 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
364 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365
Nathan Harold92bed182018-10-12 18:16:49 -0700366 // In cases where subId is unavailable, the caller needs to specify the phone.
367 public Phone phone;
368
vagdeviaf9a5b92018-08-15 16:01:53 -0700369 public WorkSource workSource;
370
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 public MainThreadRequest(Object argument) {
372 this.argument = argument;
373 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800374
Nathan Harold92bed182018-10-12 18:16:49 -0700375 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
376 this.argument = argument;
377 if (phone != null) {
378 this.phone = phone;
379 }
380 this.workSource = workSource;
381 }
382
vagdeviaf9a5b92018-08-15 16:01:53 -0700383 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800384 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800385 if (subId != null) {
386 this.subId = subId;
387 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700388 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390 }
391
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800392 private static final class IncomingThirdPartyCallArgs {
393 public final ComponentName component;
394 public final String callId;
395 public final String callerDisplayName;
396
397 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
398 String callerDisplayName) {
399 this.component = component;
400 this.callId = callId;
401 this.callerDisplayName = callerDisplayName;
402 }
403 }
404
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 /**
406 * A handler that processes messages on the main thread in the phone process. Since many
407 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
408 * inbound binder threads to the main thread in the phone process. The Binder thread
409 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
410 * on, which will be notified when the operation completes and will contain the result of the
411 * request.
412 *
413 * <p>If a MainThreadRequest object is provided in the msg.obj field,
414 * note that request.result must be set to something non-null for the calling thread to
415 * unblock.
416 */
417 private final class MainThreadHandler extends Handler {
418 @Override
419 public void handleMessage(Message msg) {
420 MainThreadRequest request;
421 Message onCompleted;
422 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800423 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700424 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800425 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700426
427 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700428 case CMD_HANDLE_USSD_REQUEST: {
429 request = (MainThreadRequest) msg.obj;
430 final Phone phone = getPhoneFromRequest(request);
431 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
432 String ussdRequest = ussdObject.first;
433 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700434
Pengquan Menga1bb6272018-09-06 09:59:22 -0700435 if (!isUssdApiAllowed(request.subId)) {
436 // Carrier does not support use of this API, return failure.
437 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
438 UssdResponse response = new UssdResponse(ussdRequest, null);
439 Bundle returnData = new Bundle();
440 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
441 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700442
Pengquan Menga1bb6272018-09-06 09:59:22 -0700443 request.result = true;
444 notifyRequester(request);
445 return;
446 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700447
Pengquan Menga1bb6272018-09-06 09:59:22 -0700448 try {
449 request.result = phone != null
450 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
451 } catch (CallStateException cse) {
452 request.result = false;
453 }
454 // Wake up the requesting thread
455 notifyRequester(request);
456 break;
pkanwar32d516d2016-10-14 19:37:38 -0700457 }
458
Yorke Lee716f67e2015-06-17 15:39:16 -0700459 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700461 final Phone phone = getPhoneFromRequest(request);
462 request.result = phone != null ?
463 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
464 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700465 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700466 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700471 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800473 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700474 if (uiccCard == null) {
475 loge("iccTransmitApduLogicalChannel: No UICC");
476 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700477 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700478 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
480 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700481 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 iccArgument.channel, iccArgument.cla, iccArgument.command,
483 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700484 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700485 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700486 break;
487
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 ar = (AsyncResult) msg.obj;
490 request = (MainThreadRequest) ar.userObj;
491 if (ar.exception == null && ar.result != null) {
492 request.result = ar.result;
493 } else {
494 request.result = new IccIoResult(0x6F, 0, (byte[])null);
495 if (ar.result == null) {
496 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800497 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700498 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800499 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700500 } else {
501 loge("iccTransmitApduLogicalChannel: Unknown exception");
502 }
503 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 break;
506
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
508 request = (MainThreadRequest) msg.obj;
509 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800510 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700511 if (uiccCard == null) {
512 loge("iccTransmitApduBasicChannel: No UICC");
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700514 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 } else {
516 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
517 request);
518 uiccCard.iccTransmitApduBasicChannel(
519 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
520 iccArgument.p3, iccArgument.data, onCompleted);
521 }
522 break;
523
524 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
525 ar = (AsyncResult) msg.obj;
526 request = (MainThreadRequest) ar.userObj;
527 if (ar.exception == null && ar.result != null) {
528 request.result = ar.result;
529 } else {
530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
531 if (ar.result == null) {
532 loge("iccTransmitApduBasicChannel: Empty response");
533 } else if (ar.exception instanceof CommandException) {
534 loge("iccTransmitApduBasicChannel: CommandException: " +
535 ar.exception);
536 } else {
537 loge("iccTransmitApduBasicChannel: Unknown exception");
538 }
539 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700540 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 break;
542
543 case CMD_EXCHANGE_SIM_IO:
544 request = (MainThreadRequest) msg.obj;
545 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800546 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700547 if (uiccCard == null) {
548 loge("iccExchangeSimIO: No UICC");
549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700551 } else {
552 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
553 request);
554 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
555 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
556 iccArgument.data, onCompleted);
557 }
558 break;
559
560 case EVENT_EXCHANGE_SIM_IO_DONE:
561 ar = (AsyncResult) msg.obj;
562 request = (MainThreadRequest) ar.userObj;
563 if (ar.exception == null && ar.result != null) {
564 request.result = ar.result;
565 } else {
566 request.result = new IccIoResult(0x6f, 0, (byte[])null);
567 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 break;
570
Derek Tan4d5e5c12014-02-04 11:54:58 -0800571 case CMD_SEND_ENVELOPE:
572 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800573 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700574 if (uiccCard == null) {
575 loge("sendEnvelopeWithStatus: No UICC");
576 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700577 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700578 } else {
579 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
580 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
581 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800582 break;
583
584 case EVENT_SEND_ENVELOPE_DONE:
585 ar = (AsyncResult) msg.obj;
586 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700587 if (ar.exception == null && ar.result != null) {
588 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800589 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700590 request.result = new IccIoResult(0x6F, 0, (byte[])null);
591 if (ar.result == null) {
592 loge("sendEnvelopeWithStatus: Empty response");
593 } else if (ar.exception instanceof CommandException) {
594 loge("sendEnvelopeWithStatus: CommandException: " +
595 ar.exception);
596 } else {
597 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
598 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800599 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800601 break;
602
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 case CMD_OPEN_CHANNEL:
604 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800605 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800606 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700607 if (uiccCard == null) {
608 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800609 request.result = new IccOpenLogicalChannelResponse(-1,
610 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700611 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700612 } else {
613 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800614 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
615 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700616 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 break;
618
619 case EVENT_OPEN_CHANNEL_DONE:
620 ar = (AsyncResult) msg.obj;
621 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 int[] result = (int[]) ar.result;
625 int channelId = result[0];
626 byte[] selectResponse = null;
627 if (result.length > 1) {
628 selectResponse = new byte[result.length - 1];
629 for (int i = 1; i < result.length; ++i) {
630 selectResponse[i - 1] = (byte) result[i];
631 }
632 }
633 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700634 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 if (ar.result == null) {
637 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 if (ar.exception != null) {
640 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
641 }
642
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700643 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700644 if (ar.exception instanceof CommandException) {
645 CommandException.Error error =
646 ((CommandException) (ar.exception)).getCommandError();
647 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700648 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700649 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700650 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700651 }
652 }
653 openChannelResp = new IccOpenLogicalChannelResponse(
654 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700656 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 break;
659
660 case CMD_CLOSE_CHANNEL:
661 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800662 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700663 if (uiccCard == null) {
664 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900665 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700667 } else {
668 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
669 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
670 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 break;
672
673 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800674 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
675 break;
676
677 case CMD_NV_READ_ITEM:
678 request = (MainThreadRequest) msg.obj;
679 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800680 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
681 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800682 break;
683
684 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700685 ar = (AsyncResult) msg.obj;
686 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800687 if (ar.exception == null && ar.result != null) {
688 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800690 request.result = "";
691 if (ar.result == null) {
692 loge("nvReadItem: Empty response");
693 } else if (ar.exception instanceof CommandException) {
694 loge("nvReadItem: CommandException: " +
695 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800697 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700698 }
699 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700700 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 break;
702
Jake Hambye994d462014-02-03 13:10:13 -0800703 case CMD_NV_WRITE_ITEM:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
706 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800707 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700708 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800709 break;
710
711 case EVENT_NV_WRITE_ITEM_DONE:
712 handleNullReturnEvent(msg, "nvWriteItem");
713 break;
714
715 case CMD_NV_WRITE_CDMA_PRL:
716 request = (MainThreadRequest) msg.obj;
717 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800718 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800719 break;
720
721 case EVENT_NV_WRITE_CDMA_PRL_DONE:
722 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
723 break;
724
chen xu6dac5ab2018-10-26 17:39:23 -0700725 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800726 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700727 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800728 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800729 break;
730
chen xu6dac5ab2018-10-26 17:39:23 -0700731 case EVENT_RESET_MODEM_CONFIG_DONE:
732 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800733 break;
734
Jake Hamby7c27be32014-03-03 13:25:59 -0800735 case CMD_GET_PREFERRED_NETWORK_TYPE:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700738 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800739 break;
740
741 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
742 ar = (AsyncResult) msg.obj;
743 request = (MainThreadRequest) ar.userObj;
744 if (ar.exception == null && ar.result != null) {
745 request.result = ar.result; // Integer
746 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800747 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800748 if (ar.result == null) {
749 loge("getPreferredNetworkType: Empty response");
750 } else if (ar.exception instanceof CommandException) {
751 loge("getPreferredNetworkType: CommandException: " +
752 ar.exception);
753 } else {
754 loge("getPreferredNetworkType: Unknown exception");
755 }
756 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700757 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800758 break;
759
760 case CMD_SET_PREFERRED_NETWORK_TYPE:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
763 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700764 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800765 break;
766
767 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
768 handleNullReturnEvent(msg, "setPreferredNetworkType");
769 break;
770
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000771 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
772 request = (MainThreadRequest)msg.obj;
773 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800774 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000775 break;
776
777 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
778 ar = (AsyncResult)msg.obj;
779 request = (MainThreadRequest)ar.userObj;
780 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700781 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000782 break;
783
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800784 case CMD_SET_VOICEMAIL_NUMBER:
785 request = (MainThreadRequest) msg.obj;
786 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
787 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800788 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
789 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800790 break;
791
792 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
793 handleNullReturnEvent(msg, "setVoicemailNumber");
794 break;
795
Stuart Scott54788802015-03-30 13:18:01 -0700796 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
797 request = (MainThreadRequest) msg.obj;
798 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
799 request);
800 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
801 break;
802
803 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
804 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
805 break;
806
Shishir Agrawal302c8692015-06-19 13:49:39 -0700807 case CMD_PERFORM_NETWORK_SCAN:
808 request = (MainThreadRequest) msg.obj;
809 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
810 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
811 break;
812
813 case EVENT_PERFORM_NETWORK_SCAN_DONE:
814 ar = (AsyncResult) msg.obj;
815 request = (MainThreadRequest) ar.userObj;
816 CellNetworkScanResult cellScanResult;
817 if (ar.exception == null && ar.result != null) {
818 cellScanResult = new CellNetworkScanResult(
819 CellNetworkScanResult.STATUS_SUCCESS,
820 (List<OperatorInfo>) ar.result);
821 } else {
822 if (ar.result == null) {
823 loge("getCellNetworkScanResults: Empty response");
824 }
825 if (ar.exception != null) {
826 loge("getCellNetworkScanResults: Exception: " + ar.exception);
827 }
828 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
829 if (ar.exception instanceof CommandException) {
830 CommandException.Error error =
831 ((CommandException) (ar.exception)).getCommandError();
832 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
833 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
834 } else if (error == CommandException.Error.GENERIC_FAILURE) {
835 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
836 }
837 }
838 cellScanResult = new CellNetworkScanResult(errorCode, null);
839 }
840 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700841 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700842 break;
843
844 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
845 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700846 ManualNetworkSelectionArgument selArg =
847 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700848 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
849 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700850 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
851 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700852 break;
853
854 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700855 ar = (AsyncResult) msg.obj;
856 request = (MainThreadRequest) ar.userObj;
857 if (ar.exception == null) {
858 request.result = true;
859 } else {
860 request.result = false;
861 loge("setNetworkSelectionModeManual " + ar.exception);
862 }
863 notifyRequester(request);
864 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700865 break;
866
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700867 case CMD_GET_MODEM_ACTIVITY_INFO:
868 request = (MainThreadRequest) msg.obj;
869 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700870 if (defaultPhone != null) {
871 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
872 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700873 break;
874
875 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
876 ar = (AsyncResult) msg.obj;
877 request = (MainThreadRequest) ar.userObj;
878 if (ar.exception == null && ar.result != null) {
879 request.result = ar.result;
880 } else {
881 if (ar.result == null) {
882 loge("queryModemActivityInfo: Empty response");
883 } else if (ar.exception instanceof CommandException) {
884 loge("queryModemActivityInfo: CommandException: " +
885 ar.exception);
886 } else {
887 loge("queryModemActivityInfo: Unknown exception");
888 }
889 }
Amit Mahajand4766222016-01-28 15:28:28 -0800890 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
891 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800892 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800893 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700894 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700895 break;
896
Meng Wang1a7c35a2016-05-05 20:56:15 -0700897 case CMD_SET_ALLOWED_CARRIERS:
898 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800899 CarrierRestrictionRules argument =
900 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700901 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800902 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700903 break;
904
905 case EVENT_SET_ALLOWED_CARRIERS_DONE:
906 ar = (AsyncResult) msg.obj;
907 request = (MainThreadRequest) ar.userObj;
908 if (ar.exception == null && ar.result != null) {
909 request.result = ar.result;
910 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800911 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
912 if (ar.exception instanceof CommandException) {
913 loge("setAllowedCarriers: CommandException: " + ar.exception);
914 CommandException.Error error =
915 ((CommandException) (ar.exception)).getCommandError();
916 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
917 request.result =
918 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
919 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700920 } else {
921 loge("setAllowedCarriers: Unknown exception");
922 }
923 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700924 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700925 break;
926
927 case CMD_GET_ALLOWED_CARRIERS:
928 request = (MainThreadRequest) msg.obj;
929 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800930 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700931 break;
932
933 case EVENT_GET_ALLOWED_CARRIERS_DONE:
934 ar = (AsyncResult) msg.obj;
935 request = (MainThreadRequest) ar.userObj;
936 if (ar.exception == null && ar.result != null) {
937 request.result = ar.result;
938 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800939 request.result = new IllegalStateException(
940 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700941 if (ar.result == null) {
942 loge("getAllowedCarriers: Empty response");
943 } else if (ar.exception instanceof CommandException) {
944 loge("getAllowedCarriers: CommandException: " +
945 ar.exception);
946 } else {
947 loge("getAllowedCarriers: Unknown exception");
948 }
949 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700950 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700951 break;
952
Nathan Haroldb3014052017-01-25 15:57:32 -0800953 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
954 ar = (AsyncResult) msg.obj;
955 request = (MainThreadRequest) ar.userObj;
956 if (ar.exception == null && ar.result != null) {
957 request.result = ar.result;
958 } else {
959 request.result = new IllegalArgumentException(
960 "Failed to retrieve Forbidden Plmns");
961 if (ar.result == null) {
962 loge("getForbiddenPlmns: Empty response");
963 } else {
964 loge("getForbiddenPlmns: Unknown exception");
965 }
966 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700967 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800968 break;
969
970 case CMD_GET_FORBIDDEN_PLMNS:
971 request = (MainThreadRequest) msg.obj;
972 uiccCard = getUiccCardFromRequest(request);
973 if (uiccCard == null) {
974 loge("getForbiddenPlmns() UiccCard is null");
975 request.result = new IllegalArgumentException(
976 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700977 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800978 break;
979 }
980 Integer appType = (Integer) request.argument;
981 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
982 if (uiccApp == null) {
983 loge("getForbiddenPlmns() no app with specified type -- "
984 + appType);
985 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700986 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800987 break;
988 } else {
989 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
990 + " specified type -- " + appType);
991 }
992 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
993 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
994 onCompleted);
995 break;
996
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000997 case CMD_SWITCH_SLOTS:
998 request = (MainThreadRequest) msg.obj;
999 int[] physicalSlots = (int[]) request.argument;
1000 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1001 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1002 break;
1003
1004 case EVENT_SWITCH_SLOTS_DONE:
1005 ar = (AsyncResult) msg.obj;
1006 request = (MainThreadRequest) ar.userObj;
1007 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001008 notifyRequester(request);
1009 break;
1010 case CMD_GET_NETWORK_SELECTION_MODE:
1011 request = (MainThreadRequest) msg.obj;
1012 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1013 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1014 break;
1015
1016 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1017 ar = (AsyncResult) msg.obj;
1018 request = (MainThreadRequest) ar.userObj;
1019 if (ar.exception != null) {
1020 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1021 } else {
1022 int mode = ((int[]) ar.result)[0];
1023 if (mode == 0) {
1024 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1025 } else {
1026 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1027 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001028 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001029 notifyRequester(request);
1030 break;
1031 case CMD_GET_CDMA_ROAMING_MODE:
1032 request = (MainThreadRequest) msg.obj;
1033 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1034 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1035 break;
1036 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
1039 if (ar.exception != null) {
1040 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1041 } else {
1042 request.result = ((int[]) ar.result)[0];
1043 }
1044 notifyRequester(request);
1045 break;
1046 case CMD_SET_CDMA_ROAMING_MODE:
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1049 int mode = (int) request.argument;
1050 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1051 break;
1052 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1053 ar = (AsyncResult) msg.obj;
1054 request = (MainThreadRequest) ar.userObj;
1055 request.result = ar.exception == null;
1056 notifyRequester(request);
1057 break;
1058 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1059 request = (MainThreadRequest) msg.obj;
1060 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1061 int subscriptionMode = (int) request.argument;
1062 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1063 break;
1064 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1065 ar = (AsyncResult) msg.obj;
1066 request = (MainThreadRequest) ar.userObj;
1067 request.result = ar.exception == null;
1068 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001069 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001070 case CMD_GET_ALL_CELL_INFO:
1071 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001072 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001073 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001074 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001075 case EVENT_GET_ALL_CELL_INFO_DONE:
1076 ar = (AsyncResult) msg.obj;
1077 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001078 // If a timeout occurs, the response will be null
1079 request.result = (ar.exception == null && ar.result != null)
1080 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001081 synchronized (request) {
1082 request.notifyAll();
1083 }
1084 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 case CMD_REQUEST_CELL_INFO_UPDATE:
1086 request = (MainThreadRequest) msg.obj;
1087 request.phone.requestCellInfoUpdate(request.workSource,
1088 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1089 break;
1090 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1091 ar = (AsyncResult) msg.obj;
1092 request = (MainThreadRequest) ar.userObj;
1093 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1094 try {
1095 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001096 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001097 cb.onError(
1098 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1099 ar.exception.getClass().getName(),
1100 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001101 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001102 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001103 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001104 } else {
1105 // use the result as returned
1106 cb.onCellInfo((List<CellInfo>) ar.result);
1107 }
1108 } catch (RemoteException re) {
1109 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1110 }
1111 break;
1112 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001113 request = (MainThreadRequest) msg.obj;
1114 WorkSource ws = (WorkSource) request.argument;
1115 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001116 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001117 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001118 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001119 ar = (AsyncResult) msg.obj;
1120 request = (MainThreadRequest) ar.userObj;
1121 if (ar.exception == null) {
1122 request.result = ar.result;
1123 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001124 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001125 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001126 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001127 }
1128
1129 synchronized (request) {
1130 request.notifyAll();
1131 }
1132 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001133 case CMD_MODEM_REBOOT:
1134 request = (MainThreadRequest) msg.obj;
1135 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001136 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001137 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001138 case EVENT_CMD_MODEM_REBOOT_DONE:
1139 handleNullReturnEvent(msg, "rebootModem");
1140 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001141 case CMD_REQUEST_ENABLE_MODEM:
1142 request = (MainThreadRequest) msg.obj;
1143 boolean enable = (boolean) request.argument;
1144 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001145 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001146 PhoneConfigurationManager.getInstance()
1147 .enablePhone(request.phone, enable, onCompleted);
1148 break;
1149 case EVENT_ENABLE_MODEM_DONE:
1150 ar = (AsyncResult) msg.obj;
1151 request = (MainThreadRequest) ar.userObj;
1152 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001153 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001154 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001155 if ((boolean) request.result) {
1156 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1157 updateModemStateMetrics();
1158 } else {
1159 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1160 + ar.exception);
1161 }
1162 notifyRequester(request);
1163 break;
1164 case CMD_GET_MODEM_STATUS:
1165 request = (MainThreadRequest) msg.obj;
1166 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1167 PhoneConfigurationManager.getInstance()
1168 .getPhoneStatusFromModem(request.phone, onCompleted);
1169 break;
1170 case EVENT_GET_MODEM_STATUS_DONE:
1171 ar = (AsyncResult) msg.obj;
1172 request = (MainThreadRequest) ar.userObj;
1173 int id = request.phone.getPhoneId();
1174 if (ar.exception == null && ar.result != null) {
1175 request.result = ar.result;
1176 //update the cache as modem status has changed
1177 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1178 (boolean) request.result);
1179 } else {
1180 // Return true if modem status cannot be retrieved. For most cases,
1181 // modem status is on. And for older version modems, GET_MODEM_STATUS
1182 // and disable modem are not supported. Modem is always on.
1183 // TODO: this should be fixed in R to support a third
1184 // status UNKNOWN b/131631629
1185 request.result = true;
1186 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1187 + ar.exception);
1188 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001189 notifyRequester(request);
1190 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001191 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1192 request = (MainThreadRequest) msg.obj;
1193 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1194 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1195 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1196 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1197 break;
1198 }
1199 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1200 ar = (AsyncResult) msg.obj;
1201 request = (MainThreadRequest) ar.userObj;
1202 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1203 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1204 args.second.accept(ar.exception == null);
1205 notifyRequester(request);
1206 break;
1207 }
yincheng zhao2737e882019-09-06 17:06:54 -07001208 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1209 ar = (AsyncResult) msg.obj;
1210 request = (MainThreadRequest) ar.userObj;
1211 if (ar.exception == null && ar.result != null) {
1212 request.result = ar.result;
1213 } else {
1214 request.result = -1;
1215 loge("Failed to set Forbidden Plmns");
1216 if (ar.result == null) {
1217 loge("setForbidenPlmns: Empty response");
1218 } else if (ar.exception != null) {
1219 loge("setForbiddenPlmns: Exception: " + ar.exception);
1220 request.result = -1;
1221 } else {
1222 loge("setForbiddenPlmns: Unknown exception");
1223 }
1224 }
1225 notifyRequester(request);
1226 break;
1227 case CMD_SET_FORBIDDEN_PLMNS:
1228 request = (MainThreadRequest) msg.obj;
1229 uiccCard = getUiccCardFromRequest(request);
1230 if (uiccCard == null) {
1231 loge("setForbiddenPlmns: UiccCard is null");
1232 request.result = -1;
1233 notifyRequester(request);
1234 break;
1235 }
1236 Pair<Integer, List<String>> setFplmnsArgs =
1237 (Pair<Integer, List<String>>) request.argument;
1238 appType = setFplmnsArgs.first;
1239 List<String> fplmns = setFplmnsArgs.second;
1240 uiccApp = uiccCard.getApplicationByType(appType);
1241 if (uiccApp == null) {
1242 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1243 request.result = -1;
1244 loge("Failed to get UICC App");
1245 notifyRequester(request);
1246 } else {
1247 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1248 ((SIMRecords) uiccApp.getIccRecords())
1249 .setForbiddenPlmns(onCompleted, fplmns);
1250 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001251 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001252 case CMD_ERASE_MODEM_CONFIG:
1253 request = (MainThreadRequest) msg.obj;
1254 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1255 defaultPhone.eraseModemConfig(onCompleted);
1256 break;
1257 case EVENT_ERASE_MODEM_CONFIG_DONE:
1258 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001259 break;
zoey chene02881a2019-12-30 16:11:23 +08001260
1261 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1262 request = (MainThreadRequest) msg.obj;
1263 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1264 Pair<String, String> changed = (Pair<String, String>) request.argument;
1265 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1266 changed.first, changed.second, onCompleted);
1267 break;
1268 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1269 ar = (AsyncResult) msg.obj;
1270 request = (MainThreadRequest) ar.userObj;
1271 if (ar.exception == null) {
1272 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1273 } else {
1274 request.result = msg.arg1;
1275 }
1276 notifyRequester(request);
1277 break;
1278
1279 case CMD_SET_ICC_LOCK_ENABLED:
1280 request = (MainThreadRequest) msg.obj;
1281 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1282 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1283 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1284 enabled.first, enabled.second, onCompleted);
1285 break;
1286 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1287 ar = (AsyncResult) msg.obj;
1288 request = (MainThreadRequest) ar.userObj;
1289 if (ar.exception == null) {
1290 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1291 } else {
1292 request.result = msg.arg1;
1293 }
1294 notifyRequester(request);
1295 break;
1296
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001297 default:
1298 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1299 break;
1300 }
1301 }
Jake Hambye994d462014-02-03 13:10:13 -08001302
Pengquan Menga1bb6272018-09-06 09:59:22 -07001303 private void notifyRequester(MainThreadRequest request) {
1304 synchronized (request) {
1305 request.notifyAll();
1306 }
1307 }
1308
Jake Hambye994d462014-02-03 13:10:13 -08001309 private void handleNullReturnEvent(Message msg, String command) {
1310 AsyncResult ar = (AsyncResult) msg.obj;
1311 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1312 if (ar.exception == null) {
1313 request.result = true;
1314 } else {
1315 request.result = false;
1316 if (ar.exception instanceof CommandException) {
1317 loge(command + ": CommandException: " + ar.exception);
1318 } else {
1319 loge(command + ": Unknown exception");
1320 }
1321 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001322 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 }
1325
1326 /**
1327 * Posts the specified command to be executed on the main thread,
1328 * waits for the request to complete, and returns the result.
1329 * @see #sendRequestAsync
1330 */
1331 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001332 return sendRequest(
1333 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001334 }
1335
1336 /**
1337 * Posts the specified command to be executed on the main thread,
1338 * waits for the request to complete, and returns the result.
1339 * @see #sendRequestAsync
1340 */
1341 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1342 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001343 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001344 }
1345
1346 /**
1347 * Posts the specified command to be executed on the main thread,
1348 * waits for the request to complete, and returns the result.
1349 * @see #sendRequestAsync
1350 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001351 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001352 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001353 }
1354
1355 /**
1356 * Posts the specified command to be executed on the main thread,
1357 * waits for the request to complete, and returns the result.
1358 * @see #sendRequestAsync
1359 */
Nathan Harold92bed182018-10-12 18:16:49 -07001360 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1361 return sendRequest(command, argument, subId, null, workSource);
1362 }
1363
1364 /**
1365 * Posts the specified command to be executed on the main thread,
1366 * waits for the request to complete, and returns the result.
1367 * @see #sendRequestAsync
1368 */
1369 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1370 return sendRequest(
1371 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1372 }
1373
1374 /**
1375 * Posts the specified command to be executed on the main thread,
1376 * waits for the request to complete, and returns the result.
1377 * @see #sendRequestAsync
1378 */
1379 private Object sendRequest(
1380 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1382 throw new RuntimeException("This method will deadlock if called from the main thread.");
1383 }
1384
Nathan Harold92bed182018-10-12 18:16:49 -07001385 MainThreadRequest request = null;
1386 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1387 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1388 } else if (phone != null) {
1389 request = new MainThreadRequest(argument, phone, workSource);
1390 } else {
1391 request = new MainThreadRequest(argument, subId, workSource);
1392 }
1393
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 Message msg = mMainThreadHandler.obtainMessage(command, request);
1395 msg.sendToTarget();
1396
1397 // Wait for the request to complete
1398 synchronized (request) {
1399 while (request.result == null) {
1400 try {
1401 request.wait();
1402 } catch (InterruptedException e) {
1403 // Do nothing, go back and wait until the request is complete
1404 }
1405 }
1406 }
1407 return request.result;
1408 }
1409
1410 /**
1411 * Asynchronous ("fire and forget") version of sendRequest():
1412 * Posts the specified command to be executed on the main thread, and
1413 * returns immediately.
1414 * @see #sendRequest
1415 */
1416 private void sendRequestAsync(int command) {
1417 mMainThreadHandler.sendEmptyMessage(command);
1418 }
1419
1420 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001421 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001422 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001423 */
1424 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001425 sendRequestAsync(command, argument, null, null);
1426 }
1427
1428 /**
1429 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1430 * @see {@link #sendRequest(int,Object)}
1431 */
1432 private void sendRequestAsync(
1433 int command, Object argument, Phone phone, WorkSource workSource) {
1434 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001435 Message msg = mMainThreadHandler.obtainMessage(command, request);
1436 msg.sendToTarget();
1437 }
1438
1439 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440 * Initialize the singleton PhoneInterfaceManager instance.
1441 * This is only done once, at startup, from PhoneApp.onCreate().
1442 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001443 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001444 synchronized (PhoneInterfaceManager.class) {
1445 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001446 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001447 } else {
1448 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1449 }
1450 return sInstance;
1451 }
1452 }
1453
1454 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001455 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001457 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001458 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001459 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1461 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001462 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001463 mTelephonySharedPreferences =
1464 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001465 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001466 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001467
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468 publish();
1469 }
1470
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001471 private Phone getDefaultPhone() {
1472 Phone thePhone = getPhone(getDefaultSubscription());
1473 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1474 }
1475
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001476 private void publish() {
1477 if (DBG) log("publish: " + this);
1478
Peter Wangc035ce42020-01-08 21:00:22 -08001479 TelephonyFrameworkInitializer
1480 .getTelephonyServiceManager()
1481 .getTelephonyServiceRegisterer()
1482 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484
Stuart Scott584921c2015-01-15 17:10:34 -08001485 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001486 if (request.phone != null) {
1487 return request.phone;
1488 } else {
1489 return getPhoneFromSubId(request.subId);
1490 }
1491 }
1492
1493 private Phone getPhoneFromSubId(int subId) {
1494 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1495 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001496 }
1497
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001498 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1499 Phone phone = getPhoneFromRequest(request);
1500 return phone == null ? null :
1501 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1502 }
1503
Wink Saville36469e72014-06-11 15:17:00 -07001504 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001505 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001506 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508
Naina Nallurid63128d2019-09-17 14:10:30 -07001509 private void sendEraseModemConfig(Phone phone) {
1510 if (phone != null) {
1511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1512 mApp, phone.getSubId(), "eraseModemConfig");
1513 final long identity = Binder.clearCallingIdentity();
1514 try {
1515 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1516 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1517 } finally {
1518 Binder.restoreCallingIdentity(identity);
1519 }
1520 }
1521 }
1522
Peter Wang44b186e2020-01-13 23:33:09 -08001523 private boolean isImsAvailableOnDevice() {
1524 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1525 if (pm == null) {
1526 // For some reason package manger is not available.. This will fail internally anyway,
1527 // so do not throw error and allow.
1528 return true;
1529 }
1530 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1531 }
1532
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001534 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001535 }
1536
Wink Savilleb564aae2014-10-23 10:18:09 -07001537 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001538 if (DBG) log("dial: " + number);
1539 // No permission check needed here: This is just a wrapper around the
1540 // ACTION_DIAL intent, which is available to any app since it puts up
1541 // the UI before it does anything.
1542
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001543 final long identity = Binder.clearCallingIdentity();
1544 try {
1545 String url = createTelUrl(number);
1546 if (url == null) {
1547 return;
1548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001550 // PENDING: should we just silently fail if phone is offhook or ringing?
1551 PhoneConstants.State state = mCM.getState(subId);
1552 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1553 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1554 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1555 mApp.startActivity(intent);
1556 }
1557 } finally {
1558 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 }
1560 }
1561
1562 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001563 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001564 }
1565
Wink Savilleb564aae2014-10-23 10:18:09 -07001566 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 if (DBG) log("call: " + number);
1568
1569 // This is just a wrapper around the ACTION_CALL intent, but we still
1570 // need to do a permission check since we're calling startActivity()
1571 // from the context of the phone app.
1572 enforceCallPermission();
1573
Jordan Liu1617b712019-07-10 15:06:26 -07001574 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001575 != AppOpsManager.MODE_ALLOWED) {
1576 return;
1577 }
1578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001579 final long identity = Binder.clearCallingIdentity();
1580 try {
1581 String url = createTelUrl(number);
1582 if (url == null) {
1583 return;
1584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001585
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001586 boolean isValid = false;
1587 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1588 if (slist != null) {
1589 for (SubscriptionInfo subInfoRecord : slist) {
1590 if (subInfoRecord.getSubscriptionId() == subId) {
1591 isValid = true;
1592 break;
1593 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001594 }
Wink Saville08874612014-08-31 19:19:58 -07001595 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001596 if (!isValid) {
1597 return;
1598 }
Wink Saville08874612014-08-31 19:19:58 -07001599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001600 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1601 intent.putExtra(SUBSCRIPTION_KEY, subId);
1602 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1603 mApp.startActivity(intent);
1604 } finally {
1605 Binder.restoreCallingIdentity(identity);
1606 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001607 }
1608
Wink Savilleb564aae2014-10-23 10:18:09 -07001609 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001610 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001611 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1612 }
1613
Wink Savilleb564aae2014-10-23 10:18:09 -07001614 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001615 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001616 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1617 }
1618
Wink Savilleb564aae2014-10-23 10:18:09 -07001619 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001621
1622 final long identity = Binder.clearCallingIdentity();
1623 try {
1624 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1625 checkSimPin.start();
1626 return checkSimPin.unlockSim(null, pin);
1627 } finally {
1628 Binder.restoreCallingIdentity(identity);
1629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 }
1631
Wink Savilleb564aae2014-10-23 10:18:09 -07001632 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001633 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001634
1635 final long identity = Binder.clearCallingIdentity();
1636 try {
1637 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1638 checkSimPuk.start();
1639 return checkSimPuk.unlockSim(puk, pin);
1640 } finally {
1641 Binder.restoreCallingIdentity(identity);
1642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 }
1644
1645 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001646 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001647 * a synchronous one.
1648 */
1649 private static class UnlockSim extends Thread {
1650
1651 private final IccCard mSimCard;
1652
1653 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001654 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1655 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656
1657 // For replies from SimCard interface
1658 private Handler mHandler;
1659
1660 // For async handler to identify request type
1661 private static final int SUPPLY_PIN_COMPLETE = 100;
1662
1663 public UnlockSim(IccCard simCard) {
1664 mSimCard = simCard;
1665 }
1666
1667 @Override
1668 public void run() {
1669 Looper.prepare();
1670 synchronized (UnlockSim.this) {
1671 mHandler = new Handler() {
1672 @Override
1673 public void handleMessage(Message msg) {
1674 AsyncResult ar = (AsyncResult) msg.obj;
1675 switch (msg.what) {
1676 case SUPPLY_PIN_COMPLETE:
1677 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1678 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001679 mRetryCount = msg.arg1;
1680 if (ar.exception != null) {
1681 if (ar.exception instanceof CommandException &&
1682 ((CommandException)(ar.exception)).getCommandError()
1683 == CommandException.Error.PASSWORD_INCORRECT) {
1684 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1685 } else {
1686 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1687 }
1688 } else {
1689 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 mDone = true;
1692 UnlockSim.this.notifyAll();
1693 }
1694 break;
1695 }
1696 }
1697 };
1698 UnlockSim.this.notifyAll();
1699 }
1700 Looper.loop();
1701 }
1702
1703 /*
1704 * Use PIN or PUK to unlock SIM card
1705 *
1706 * If PUK is null, unlock SIM card with PIN
1707 *
1708 * If PUK is not null, unlock SIM card with PUK and set PIN code
1709 */
Wink Saville9de0f752013-10-22 19:04:03 -07001710 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711
1712 while (mHandler == null) {
1713 try {
1714 wait();
1715 } catch (InterruptedException e) {
1716 Thread.currentThread().interrupt();
1717 }
1718 }
1719 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1720
1721 if (puk == null) {
1722 mSimCard.supplyPin(pin, callback);
1723 } else {
1724 mSimCard.supplyPuk(puk, pin, callback);
1725 }
1726
1727 while (!mDone) {
1728 try {
1729 Log.d(LOG_TAG, "wait for done");
1730 wait();
1731 } catch (InterruptedException e) {
1732 // Restore the interrupted status
1733 Thread.currentThread().interrupt();
1734 }
1735 }
1736 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001737 int[] resultArray = new int[2];
1738 resultArray[0] = mResult;
1739 resultArray[1] = mRetryCount;
1740 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 }
1742 }
1743
1744 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001745 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001746
1747 }
1748
Wink Savilleb564aae2014-10-23 10:18:09 -07001749 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 // No permission check needed here: this call is harmless, and it's
1751 // needed for the ServiceState.requestStateUpdate() call (which is
1752 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 final Phone phone = getPhone(subId);
1756 if (phone != null) {
1757 phone.updateServiceLocation();
1758 }
1759 } finally {
1760 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001761 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 }
1763
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001764 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001765 @Override
1766 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001767 return isRadioOnWithFeature(callingPackage, null);
1768 }
1769
1770
1771 @Override
1772 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1773 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1774 callingFeatureId);
1775 }
1776
1777 @Deprecated
1778 @Override
1779 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1780 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001781 }
1782
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001783 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001784 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1785 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001786 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001787 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001788 return false;
1789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001790
1791 final long identity = Binder.clearCallingIdentity();
1792 try {
1793 return isRadioOnForSubscriber(subId);
1794 } finally {
1795 Binder.restoreCallingIdentity(identity);
1796 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001797 }
1798
1799 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001800 final long identity = Binder.clearCallingIdentity();
1801 try {
1802 final Phone phone = getPhone(subId);
1803 if (phone != null) {
1804 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1805 } else {
1806 return false;
1807 }
1808 } finally {
1809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 }
1812
1813 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001814 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 }
Wink Saville36469e72014-06-11 15:17:00 -07001816
Wink Savilleb564aae2014-10-23 10:18:09 -07001817 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001819
1820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 final Phone phone = getPhone(subId);
1823 if (phone != null) {
1824 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1825 }
1826 } finally {
1827 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001828 }
Wink Saville36469e72014-06-11 15:17:00 -07001829 }
1830
1831 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001832 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001833 }
1834
Wink Savilleb564aae2014-10-23 10:18:09 -07001835 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001836 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001837
1838 final long identity = Binder.clearCallingIdentity();
1839 try {
1840 final Phone phone = getPhone(subId);
1841 if (phone == null) {
1842 return false;
1843 }
1844 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1845 toggleRadioOnOffForSubscriber(subId);
1846 }
1847 return true;
1848 } finally {
1849 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001850 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 }
Wink Saville36469e72014-06-11 15:17:00 -07001852
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001853 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001854 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001855 /*
1856 * If any of the Radios are available, it will need to be
1857 * shutdown. So return true if any Radio is available.
1858 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001859 final long identity = Binder.clearCallingIdentity();
1860 try {
1861 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1862 Phone phone = PhoneFactory.getPhone(i);
1863 if (phone != null && phone.isRadioAvailable()) return true;
1864 }
1865 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1866 return false;
1867 } finally {
1868 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001869 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001870 }
1871
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001872 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001873 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001874 enforceModifyPermission();
1875
1876 final long identity = Binder.clearCallingIdentity();
1877 try {
1878 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1879 logv("Shutting down Phone " + i);
1880 shutdownRadioUsingPhoneId(i);
1881 }
1882 } finally {
1883 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001884 }
1885 }
1886
1887 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001888 Phone phone = PhoneFactory.getPhone(phoneId);
1889 if (phone != null && phone.isRadioAvailable()) {
1890 phone.shutdownRadio();
1891 }
1892 }
1893
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001895 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001896
1897 final long identity = Binder.clearCallingIdentity();
1898 try {
1899 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1900 if (defaultPhone != null) {
1901 defaultPhone.setRadioPower(turnOn);
1902 return true;
1903 } else {
1904 loge("There's no default phone.");
1905 return false;
1906 }
1907 } finally {
1908 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001909 }
Wink Saville36469e72014-06-11 15:17:00 -07001910 }
1911
Wink Savilleb564aae2014-10-23 10:18:09 -07001912 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001914
1915 final long identity = Binder.clearCallingIdentity();
1916 try {
1917 final Phone phone = getPhone(subId);
1918 if (phone != null) {
1919 phone.setRadioPower(turnOn);
1920 return true;
1921 } else {
1922 return false;
1923 }
1924 } finally {
1925 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001926 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001927 }
1928
Wink Saville36469e72014-06-11 15:17:00 -07001929 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001930 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 public boolean enableDataConnectivity() {
1932 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001933
1934 final long identity = Binder.clearCallingIdentity();
1935 try {
1936 int subId = mSubscriptionController.getDefaultDataSubId();
1937 final Phone phone = getPhone(subId);
1938 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001939 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001940 return true;
1941 } else {
1942 return false;
1943 }
1944 } finally {
1945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 }
1948
Wink Saville36469e72014-06-11 15:17:00 -07001949 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001950 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951 public boolean disableDataConnectivity() {
1952 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001953
1954 final long identity = Binder.clearCallingIdentity();
1955 try {
1956 int subId = mSubscriptionController.getDefaultDataSubId();
1957 final Phone phone = getPhone(subId);
1958 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001959 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001960 return true;
1961 } else {
1962 return false;
1963 }
1964 } finally {
1965 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 }
1968
Sanket Padawe356d7632015-06-22 14:03:32 -07001969 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001970 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001971 final long identity = Binder.clearCallingIdentity();
1972 try {
1973 final Phone phone = getPhone(subId);
1974 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001975 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001976 } else {
1977 return false;
1978 }
1979 } finally {
1980 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 }
1983
1984 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001985 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001986 }
1987
pkanwarae03a6b2016-11-06 20:37:09 -08001988 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001989 enforceCallPermission();
1990
1991 final long identity = Binder.clearCallingIdentity();
1992 try {
1993 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1994 return;
1995 }
1996 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1997 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1998 } finally {
1999 Binder.restoreCallingIdentity(identity);
2000 }
pkanwar32d516d2016-10-14 19:37:38 -07002001 };
2002
Wink Savilleb564aae2014-10-23 10:18:09 -07002003 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002004 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002005
2006 final long identity = Binder.clearCallingIdentity();
2007 try {
2008 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2009 return false;
2010 }
2011 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2012 } finally {
2013 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002014 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 }
2016
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002018 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002019 }
2020
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002021 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002022 final long identity = Binder.clearCallingIdentity();
2023 try {
2024 Phone phone = PhoneFactory.getPhone(slotIndex);
2025 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2026 PhoneConstantConversions.convertCallState(phone.getState());
2027 } finally {
2028 Binder.restoreCallingIdentity(identity);
2029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 }
2031
Sanket Padawe356d7632015-06-22 14:03:32 -07002032 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002033 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002034 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2035 }
2036
2037 @Override
2038 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002039 final long identity = Binder.clearCallingIdentity();
2040 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002041 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002042 if (phone != null) {
2043 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2044 } else {
2045 return PhoneConstantConversions.convertDataState(
2046 PhoneConstants.DataState.DISCONNECTED);
2047 }
2048 } finally {
2049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 }
2052
Sanket Padawe356d7632015-06-22 14:03:32 -07002053 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002054 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002055 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2056 }
2057
2058 @Override
2059 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002060 final long identity = Binder.clearCallingIdentity();
2061 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002062 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002063 if (phone != null) {
2064 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2065 } else {
2066 return TelephonyManager.DATA_ACTIVITY_NONE;
2067 }
2068 } finally {
2069 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002070 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 }
2072
2073 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002074 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002075 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002076 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002077
2078 LocationAccessPolicy.LocationPermissionResult locationResult =
2079 LocationAccessPolicy.checkLocationPermission(mApp,
2080 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2081 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002082 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002083 .setCallingPid(Binder.getCallingPid())
2084 .setCallingUid(Binder.getCallingUid())
2085 .setMethod("getCellLocation")
2086 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2087 .build());
2088 switch (locationResult) {
2089 case DENIED_HARD:
2090 throw new SecurityException("Not allowed to access cell location");
2091 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002092 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2093 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 }
2095
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002096 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002097 final long identity = Binder.clearCallingIdentity();
2098 try {
2099 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002100 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002101 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002102 } finally {
2103 Binder.restoreCallingIdentity(identity);
2104 }
Svetoslav64fad262015-04-14 14:35:21 -07002105 }
2106
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002108 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2109 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002110 if (!TextUtils.isEmpty(callingPackage)) {
2111 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002112 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2113 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002114 return "";
2115 }
2116 }
2117
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002118 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2119 // registered cell info, so return a NULL country instead.
2120 final long identity = Binder.clearCallingIdentity();
2121 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002122 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2123 // Get default phone in this case.
2124 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2125 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002126 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002127 // Todo: fix this when we can get the actual cellular network info when the device
2128 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002129 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002130 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2131 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002132 return "";
2133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002134 Phone phone = PhoneFactory.getPhone(phoneId);
2135 if (phone != null) {
2136 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002137 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002138 if (sst != null) {
2139 LocaleTracker lt = sst.getLocaleTracker();
2140 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002141 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2142 return lt.getCurrentCountry();
2143 } else if (emergencyNumberTracker != null) {
2144 return emergencyNumberTracker.getEmergencyCountryIso();
2145 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002146 }
2147 }
2148 }
2149 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002150 } finally {
2151 Binder.restoreCallingIdentity(identity);
2152 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002153 }
2154
2155 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002157 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002158 }
2159
Sanket Padawe356d7632015-06-22 14:03:32 -07002160 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002161 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 mApp.enforceCallingOrSelfPermission(
2163 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002164
2165 final long identity = Binder.clearCallingIdentity();
2166 try {
2167 final Phone phone = getPhone(subId);
2168 if (phone != null) {
2169 phone.enableLocationUpdates();
2170 }
2171 } finally {
2172 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002173 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174 }
2175
2176 @Override
2177 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002178 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002179 }
2180
Sanket Padawe356d7632015-06-22 14:03:32 -07002181 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002182 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 mApp.enforceCallingOrSelfPermission(
2184 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002185
2186 final long identity = Binder.clearCallingIdentity();
2187 try {
2188 final Phone phone = getPhone(subId);
2189 if (phone != null) {
2190 phone.disableLocationUpdates();
2191 }
2192 } finally {
2193 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 }
2196
Nathan Harold31d7ff32018-10-15 20:20:30 -07002197 /**
2198 * Returns the target SDK version number for a given package name.
2199 *
Nathan Haroldec184742019-07-10 17:04:16 -07002200 * This call MUST be invoked before clearing the calling UID.
2201 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002202 * @return target SDK if the package is found or INT_MAX.
2203 */
2204 private int getTargetSdk(String packageName) {
2205 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002206 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002207 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002208 if (ai != null) return ai.targetSdkVersion;
2209 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002210 loge("Failed to get package info for pkg="
2211 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002212 }
2213 return Integer.MAX_VALUE;
2214 }
2215
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 @Override
2217 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002218 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2219 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002220 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002221 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2222 throw new SecurityException(
2223 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2224 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002225
Jordan Liu1617b712019-07-10 15:06:26 -07002226 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2228 return null;
2229 }
Svetoslav64fad262015-04-14 14:35:21 -07002230
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002231 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002233 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002234 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235
Nathan Haroldf180aac2018-06-01 18:43:55 -07002236 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2237 for (CellInfo ci : info) {
2238 if (ci instanceof CellInfoGsm) {
2239 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2240 } else if (ci instanceof CellInfoWcdma) {
2241 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002244 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 }
2246
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002247 private List<CellInfo> getCachedCellInfo() {
2248 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2249 for (Phone phone : PhoneFactory.getPhones()) {
2250 List<CellInfo> info = phone.getAllCellInfo();
2251 if (info != null) cellInfos.addAll(info);
2252 }
2253 return cellInfos;
2254 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255
2256 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002257 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002258 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002259 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002260
2261 LocationAccessPolicy.LocationPermissionResult locationResult =
2262 LocationAccessPolicy.checkLocationPermission(mApp,
2263 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2264 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002265 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002266 .setCallingPid(Binder.getCallingPid())
2267 .setCallingUid(Binder.getCallingUid())
2268 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002269 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002270 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2271 .build());
2272 switch (locationResult) {
2273 case DENIED_HARD:
2274 throw new SecurityException("Not allowed to access cell info");
2275 case DENIED_SOFT:
2276 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 }
2278
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002279 final int targetSdk = getTargetSdk(callingPackage);
2280 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2281 return getCachedCellInfo();
2282 }
2283
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002284 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002285 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286 final long identity = Binder.clearCallingIdentity();
2287 try {
2288 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2289 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002290 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002291 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292 if (info != null) cellInfos.addAll(info);
2293 }
2294 return cellInfos;
2295 } finally {
2296 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 }
2298 }
2299
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002300 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002301 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2302 String callingFeatureId) {
2303 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2304 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002305 }
2306
2307 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002308 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2309 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002310 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002311 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002312 }
2313
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002314 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2315 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002316 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002317 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002318
2319 LocationAccessPolicy.LocationPermissionResult locationResult =
2320 LocationAccessPolicy.checkLocationPermission(mApp,
2321 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2322 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002323 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002324 .setCallingPid(Binder.getCallingPid())
2325 .setCallingUid(Binder.getCallingUid())
2326 .setMethod("requestCellInfoUpdate")
2327 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2328 .build());
2329 switch (locationResult) {
2330 case DENIED_HARD:
2331 throw new SecurityException("Not allowed to access cell info");
2332 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002333 try {
2334 cb.onCellInfo(new ArrayList<CellInfo>());
2335 } catch (RemoteException re) {
2336 // Drop without consequences
2337 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002338 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002339 }
2340
Nathan Harolda939a962019-05-09 10:13:47 -07002341
2342 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002343 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2344
2345 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2346 }
2347
2348 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002350 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002351 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002352
2353 final long identity = Binder.clearCallingIdentity();
2354 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002355 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002356 } finally {
2357 Binder.restoreCallingIdentity(identity);
2358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 }
2360
Shishir Agrawala9f32182016-04-12 12:00:16 -07002361 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002362 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002363 Phone phone = PhoneFactory.getPhone(slotIndex);
2364 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002365 return null;
2366 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002367 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002368 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002369 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002370 return null;
2371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002372
2373 final long identity = Binder.clearCallingIdentity();
2374 try {
2375 return phone.getImei();
2376 } finally {
2377 Binder.restoreCallingIdentity(identity);
2378 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002379 }
2380
2381 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002382 public String getTypeAllocationCodeForSlot(int slotIndex) {
2383 Phone phone = PhoneFactory.getPhone(slotIndex);
2384 String tac = null;
2385 if (phone != null) {
2386 String imei = phone.getImei();
2387 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2388 }
2389 return tac;
2390 }
2391
2392 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002393 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002394 Phone phone = PhoneFactory.getPhone(slotIndex);
2395 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002396 return null;
2397 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002398
Jeff Davidson913390f2018-02-23 17:11:49 -08002399 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002400 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002401 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002402 return null;
2403 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002404
2405 final long identity = Binder.clearCallingIdentity();
2406 try {
2407 return phone.getMeid();
2408 } finally {
2409 Binder.restoreCallingIdentity(identity);
2410 }
Jack Yu2af8d712017-03-15 17:14:14 -07002411 }
2412
2413 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002414 public String getManufacturerCodeForSlot(int slotIndex) {
2415 Phone phone = PhoneFactory.getPhone(slotIndex);
2416 String manufacturerCode = null;
2417 if (phone != null) {
2418 String meid = phone.getMeid();
2419 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2420 }
2421 return manufacturerCode;
2422 }
2423
2424 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002425 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2426 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002427 Phone phone = PhoneFactory.getPhone(slotIndex);
2428 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002429 return null;
2430 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002431 int subId = phone.getSubId();
2432 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002433 mApp, subId, callingPackage, callingFeatureId,
2434 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002435 return null;
2436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437
2438 final long identity = Binder.clearCallingIdentity();
2439 try {
2440 return phone.getDeviceSvn();
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
2443 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002444 }
2445
fionaxu43304da2017-11-27 22:51:16 -08002446 @Override
2447 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448 final long identity = Binder.clearCallingIdentity();
2449 try {
2450 final Phone phone = getPhone(subId);
2451 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2452 } finally {
2453 Binder.restoreCallingIdentity(identity);
2454 }
fionaxu43304da2017-11-27 22:51:16 -08002455 }
2456
2457 @Override
2458 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 final long identity = Binder.clearCallingIdentity();
2460 try {
2461 final Phone phone = getPhone(subId);
2462 return phone == null ? null : phone.getCarrierName();
2463 } finally {
2464 Binder.restoreCallingIdentity(identity);
2465 }
fionaxu43304da2017-11-27 22:51:16 -08002466 }
2467
calvinpanffe225e2018-11-01 19:43:06 +08002468 @Override
chen xu0026ca62019-03-06 15:28:50 -08002469 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002470 final long identity = Binder.clearCallingIdentity();
2471 try {
2472 final Phone phone = getPhone(subId);
2473 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002474 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002475 } finally {
2476 Binder.restoreCallingIdentity(identity);
2477 }
2478 }
2479
2480 @Override
chen xu0026ca62019-03-06 15:28:50 -08002481 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002482 final long identity = Binder.clearCallingIdentity();
2483 try {
2484 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002485 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002486 } finally {
2487 Binder.restoreCallingIdentity(identity);
2488 }
2489 }
2490
chen xu651eec72018-11-11 19:03:44 -08002491 @Override
chen xu864e11c2018-12-06 22:10:03 -08002492 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2493 if (!isSubscriptionMccMnc) {
2494 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2495 }
chen xu651eec72018-11-11 19:03:44 -08002496 final Phone phone = PhoneFactory.getPhone(slotIndex);
2497 if (phone == null) {
2498 return TelephonyManager.UNKNOWN_CARRIER_ID;
2499 }
2500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2503 } finally {
2504 Binder.restoreCallingIdentity(identity);
2505 }
2506 }
2507
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002508 //
2509 // Internal helper methods.
2510 //
2511
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002512 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2514 *
2515 * @throws SecurityException if the caller does not have the required permission
2516 */
2517 private void enforceModifyPermission() {
2518 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2519 }
2520
Shuo Qiancd19c462020-01-16 20:51:11 -08002521 /**
2522 * Make sure the caller is system.
2523 *
2524 * @throws SecurityException if the caller is not system.
2525 */
2526 private void enforceSystemCaller() {
2527 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2528 throw new SecurityException("Caller must be system");
2529 }
2530 }
2531
Shuo Qian3b6ee772019-11-13 17:43:31 -08002532 private void enforceActiveEmergencySessionPermission() {
2533 mApp.enforceCallingOrSelfPermission(
2534 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2535 }
2536
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537 /**
2538 * Make sure the caller has the CALL_PHONE permission.
2539 *
2540 * @throws SecurityException if the caller does not have the required permission
2541 */
2542 private void enforceCallPermission() {
2543 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2544 }
2545
paulhu5a773602019-08-23 19:17:33 +08002546 private void enforceSettingsPermission() {
2547 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002548 }
2549
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002550 private String createTelUrl(String number) {
2551 if (TextUtils.isEmpty(number)) {
2552 return null;
2553 }
2554
Jake Hambye994d462014-02-03 13:10:13 -08002555 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 }
2557
Ihab Awadf9e92732013-12-05 18:02:52 -08002558 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002559 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2560 }
2561
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002562 private static void logv(String msg) {
2563 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2564 }
2565
Ihab Awadf9e92732013-12-05 18:02:52 -08002566 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2568 }
2569
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002570 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002572 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002573 }
2574
Sanket Padawe356d7632015-06-22 14:03:32 -07002575 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002576 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 final Phone phone = PhoneFactory.getPhone(slotIndex);
2580 if (phone == null) {
2581 return PhoneConstants.PHONE_TYPE_NONE;
2582 } else {
2583 return phone.getPhoneType();
2584 }
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002587 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002588 }
2589
2590 /**
2591 * Returns the CDMA ERI icon index to display
2592 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002593 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002594 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2595 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2596 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002597 }
2598
Sanket Padawe356d7632015-06-22 14:03:32 -07002599 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002600 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2601 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002602 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002603 mApp, subId, callingPackage, callingFeatureId,
2604 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002605 return -1;
2606 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607
2608 final long identity = Binder.clearCallingIdentity();
2609 try {
2610 final Phone phone = getPhone(subId);
2611 if (phone != null) {
2612 return phone.getCdmaEriIconIndex();
2613 } else {
2614 return -1;
2615 }
2616 } finally {
2617 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 }
2620
2621 /**
2622 * Returns the CDMA ERI icon mode,
2623 * 0 - ON
2624 * 1 - FLASHING
2625 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002626 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002627 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2628 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2629 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002630 }
2631
Sanket Padawe356d7632015-06-22 14:03:32 -07002632 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002633 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2634 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002636 mApp, subId, callingPackage, callingFeatureId,
2637 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002638 return -1;
2639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640
2641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 final Phone phone = getPhone(subId);
2644 if (phone != null) {
2645 return phone.getCdmaEriIconMode();
2646 } else {
2647 return -1;
2648 }
2649 } finally {
2650 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 }
2653
2654 /**
2655 * Returns the CDMA ERI text,
2656 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002657 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002658 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2659 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2660 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002661 }
2662
Sanket Padawe356d7632015-06-22 14:03:32 -07002663 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002664 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2665 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002666 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002667 mApp, subId, callingPackage, callingFeatureId,
2668 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002669 return null;
2670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671
2672 final long identity = Binder.clearCallingIdentity();
2673 try {
2674 final Phone phone = getPhone(subId);
2675 if (phone != null) {
2676 return phone.getCdmaEriText();
2677 } else {
2678 return null;
2679 }
2680 } finally {
2681 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002682 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 }
2684
2685 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002686 * Returns the CDMA MDN.
2687 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002688 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002689 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2691 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692
2693 final long identity = Binder.clearCallingIdentity();
2694 try {
2695 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002696 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697 return phone.getLine1Number();
2698 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002699 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700 return null;
2701 }
2702 } finally {
2703 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002704 }
2705 }
2706
2707 /**
2708 * Returns the CDMA MIN.
2709 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002710 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002711 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2713 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714
2715 final long identity = Binder.clearCallingIdentity();
2716 try {
2717 final Phone phone = getPhone(subId);
2718 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2719 return phone.getCdmaMin();
2720 } else {
2721 return null;
2722 }
2723 } finally {
2724 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002725 }
2726 }
2727
Hall Liud892bec2018-11-30 14:51:45 -08002728 @Override
2729 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2730 INumberVerificationCallback callback, String callingPackage) {
2731 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2732 != PERMISSION_GRANTED) {
2733 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2734 }
2735 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2736
2737 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2738 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2739 throw new SecurityException("Calling package must be configured in the device config");
2740 }
2741
2742 if (range == null) {
2743 throw new NullPointerException("Range must be non-null");
2744 }
2745
2746 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002747 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002748
2749 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2750 }
2751
Junda Liuca05d5d2014-08-14 22:36:34 -07002752 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002753 * Returns true if CDMA provisioning needs to run.
2754 */
2755 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756 final long identity = Binder.clearCallingIdentity();
2757 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002758 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759 } finally {
2760 Binder.restoreCallingIdentity(identity);
2761 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002762 }
2763
2764 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002765 * Sets the voice mail number of a given subId.
2766 */
2767 @Override
2768 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002769 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2770 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771
2772 final long identity = Binder.clearCallingIdentity();
2773 try {
2774 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2775 new Pair<String, String>(alphaTag, number), new Integer(subId));
2776 return success;
2777 } finally {
2778 Binder.restoreCallingIdentity(identity);
2779 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002780 }
2781
Ta-wei Yen87c49842016-05-13 21:19:52 -07002782 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002783 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2784 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002785 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2786 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002787 if (!TextUtils.equals(callingPackage, systemDialer)) {
2788 throw new SecurityException("caller must be system dialer");
2789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790
2791 final long identity = Binder.clearCallingIdentity();
2792 try {
2793 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2794 if (phoneAccountHandle == null) {
2795 return null;
2796 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002797 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798 } finally {
2799 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002800 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002801 }
2802
2803 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002804 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2805 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002806 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002808 mApp, subId, callingPackage, callingFeatureId,
2809 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002810 return null;
2811 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002812
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002813 final long identity = Binder.clearCallingIdentity();
2814 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002815 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002816 } finally {
2817 Binder.restoreCallingIdentity(identity);
2818 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002819 }
2820
2821 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002822 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2823 VisualVoicemailSmsFilterSettings settings) {
2824 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825
2826 final long identity = Binder.clearCallingIdentity();
2827 try {
2828 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002829 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830 } finally {
2831 Binder.restoreCallingIdentity(identity);
2832 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002833 }
2834
2835 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002836 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2837 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838
2839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002842 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002843 } finally {
2844 Binder.restoreCallingIdentity(identity);
2845 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002846 }
2847
2848 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002849 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2850 String callingPackage, int subId) {
2851 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852
2853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002856 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857 } finally {
2858 Binder.restoreCallingIdentity(identity);
2859 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002860 }
2861
2862 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002863 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002864 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865
2866 final long identity = Binder.clearCallingIdentity();
2867 try {
2868 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002869 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002870 } finally {
2871 Binder.restoreCallingIdentity(identity);
2872 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002873 }
2874
2875 @Override
2876 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2877 String number, int port, String text, PendingIntent sentIntent) {
2878 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002879 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002880 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002881 SmsController smsController = PhoneFactory.getSmsController();
2882 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2883 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002884 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002885
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002886 /**
fionaxu0152e512016-11-14 13:36:14 -08002887 * Sets the voice activation state of a given subId.
2888 */
2889 @Override
2890 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2892 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002893
2894 final long identity = Binder.clearCallingIdentity();
2895 try {
2896 final Phone phone = getPhone(subId);
2897 if (phone != null) {
2898 phone.setVoiceActivationState(activationState);
2899 } else {
2900 loge("setVoiceActivationState fails with invalid subId: " + subId);
2901 }
2902 } finally {
2903 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002904 }
2905 }
2906
2907 /**
2908 * Sets the data activation state of a given subId.
2909 */
2910 @Override
2911 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2913 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002914
2915 final long identity = Binder.clearCallingIdentity();
2916 try {
2917 final Phone phone = getPhone(subId);
2918 if (phone != null) {
2919 phone.setDataActivationState(activationState);
2920 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002921 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 }
2923 } finally {
2924 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002925 }
2926 }
2927
2928 /**
2929 * Returns the voice activation state of a given subId.
2930 */
2931 @Override
2932 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002933 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934
fionaxu0152e512016-11-14 13:36:14 -08002935 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 if (phone != null) {
2939 return phone.getVoiceActivationState();
2940 } else {
2941 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2942 }
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002945 }
2946 }
2947
2948 /**
2949 * Returns the data activation state of a given subId.
2950 */
2951 @Override
2952 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002953 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954
fionaxu0152e512016-11-14 13:36:14 -08002955 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956 final long identity = Binder.clearCallingIdentity();
2957 try {
2958 if (phone != null) {
2959 return phone.getDataActivationState();
2960 } else {
2961 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2962 }
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002965 }
2966 }
2967
2968 /**
Wink Saville36469e72014-06-11 15:17:00 -07002969 * Returns the unread count of voicemails for a subId
2970 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002971 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002972 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2973 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002974 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002975 mApp, subId, callingPackage, callingFeatureId,
2976 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002977 return 0;
2978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 final Phone phone = getPhone(subId);
2982 if (phone != null) {
2983 return phone.getVoiceMessageCount();
2984 } else {
2985 return 0;
2986 }
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002990 }
2991
2992 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002993 * returns true, if the device is in a state where both voice and data
2994 * are supported simultaneously. This can change based on location or network condition.
2995 */
2996 @Override
2997 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998 final long identity = Binder.clearCallingIdentity();
2999 try {
3000 final Phone phone = getPhone(subId);
3001 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003005 }
3006
3007 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003008 * Send the dialer code if called from the current default dialer or the caller has
3009 * carrier privilege.
3010 * @param inputCode The dialer code to send
3011 */
3012 @Override
3013 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003014 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003016 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3017 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003018 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003019 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003020 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003021 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022
3023 final long identity = Binder.clearCallingIdentity();
3024 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003025 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 } finally {
3027 Binder.restoreCallingIdentity(identity);
3028 }
fionaxu235cc5e2017-03-06 22:25:57 -08003029 }
3030
Pengquan Menga1bb6272018-09-06 09:59:22 -07003031 @Override
3032 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003033 TelephonyPermissions
3034 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3035 mApp, subId, "getNetworkSelectionMode");
3036 final long identity = Binder.clearCallingIdentity();
3037 try {
3038 if (!isActiveSubscription(subId)) {
3039 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3040 }
3041 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3042 } finally {
3043 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003044 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003045 }
3046
Brad Ebinger35c841c2018-10-01 10:40:55 -07003047 @Override
Sarah Chin0605abf2019-12-06 10:24:18 -08003048 public PhoneCapability getPhoneCapability(int subId, String callingPackage,
3049 String callingFeatureId) {
3050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3051 mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) {
3052 return null;
3053 }
3054 final long identity = Binder.clearCallingIdentity();
3055 try {
3056 return mPhoneConfigurationManager.getStaticPhoneCapability();
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
3059 }
3060 }
3061
3062 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003063 public boolean isInEmergencySmsMode() {
3064 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3065 final long identity = Binder.clearCallingIdentity();
3066 try {
3067 for (Phone phone : PhoneFactory.getPhones()) {
3068 if (phone.isInEmergencySmsMode()) {
3069 return true;
3070 }
3071 }
3072 } finally {
3073 Binder.restoreCallingIdentity(identity);
3074 }
3075 return false;
3076 }
3077
shilu366312e2019-12-17 09:28:10 -08003078 /**
3079 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3080 * @param subId The subscription to use to check the configuration.
3081 * @param c The callback that will be used to send the result.
3082 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003083 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003084 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3085 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003086 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003087 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003088
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003089 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3090 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3091 "IMS not available on device.");
3092 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003093 final long token = Binder.clearCallingIdentity();
3094 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003095 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003096 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003097 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003098 } catch (ImsException e) {
3099 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003100 } finally {
3101 Binder.restoreCallingIdentity(token);
3102 }
3103 }
3104
shilu366312e2019-12-17 09:28:10 -08003105 /**
3106 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3107 * @param subId The subscription to use to check the configuration.
3108 * @param c The callback that will be used to send the result.
3109 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003110 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003111 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003112 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003113 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003114 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3115 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3116 }
Meng Wangafbc5852019-09-19 17:37:13 -07003117 final long token = Binder.clearCallingIdentity();
3118 try {
3119 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3120 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3121 .removeRegistrationCallbackForSubscription(c, subId);
3122 } catch (ImsException e) {
3123 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3124 + "is inactive, ignoring unregister.");
3125 // If the subscription is no longer active, just return, since the callback
3126 // will already have been removed internally.
3127 } finally {
3128 Binder.restoreCallingIdentity(token);
3129 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003130 }
3131
Brad Ebingera34a6c22019-10-22 17:36:18 -07003132 /**
3133 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3134 */
3135 @Override
3136 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3137 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3138 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3139 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3140 "IMS not available on device.");
3141 }
3142 final long token = Binder.clearCallingIdentity();
3143 try {
3144 Phone phone = getPhone(subId);
3145 if (phone == null) {
3146 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3147 + subId + "'");
3148 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3149 }
3150 phone.getImsRegistrationState(regState -> {
3151 try {
3152 consumer.accept((regState == null)
3153 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3154 } catch (RemoteException e) {
3155 // Ignore if the remote process is no longer available to call back.
3156 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3157 }
3158 });
3159 } finally {
3160 Binder.restoreCallingIdentity(token);
3161 }
3162 }
3163
3164 /**
3165 * Get the transport type for the IMS service registration state.
3166 */
3167 @Override
3168 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003169 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebingera34a6c22019-10-22 17:36:18 -07003170 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3171 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3172 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3173 "IMS not available on device.");
3174 }
3175 final long token = Binder.clearCallingIdentity();
3176 try {
3177 Phone phone = getPhone(subId);
3178 if (phone == null) {
3179 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3180 + subId + "'");
3181 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3182 }
3183 phone.getImsRegistrationTech(regTech -> {
3184 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3185 int regTechConverted = (regTech == null)
3186 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3187 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3188 regTechConverted);
3189 try {
3190 consumer.accept(regTechConverted);
3191 } catch (RemoteException e) {
3192 // Ignore if the remote process is no longer available to call back.
3193 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3194 }
3195 });
3196 } finally {
3197 Binder.restoreCallingIdentity(token);
3198 }
3199 }
3200
shilu366312e2019-12-17 09:28:10 -08003201 /**
3202 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3203 * @param subId The subscription to use to check the configuration.
3204 * @param c The callback that will be used to send the result.
3205 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003206 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003207 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3208 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003209 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003210 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003211 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3212 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3213 "IMS not available on device.");
3214 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003215 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3216 final long token = Binder.clearCallingIdentity();
3217 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003218 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003219 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003220 } catch (ImsException e) {
3221 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 } finally {
3223 Binder.restoreCallingIdentity(token);
3224 }
3225 }
3226
shilu366312e2019-12-17 09:28:10 -08003227 /**
3228 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3229 * @param subId The subscription to use to check the configuration.
3230 * @param c The callback that will be used to send the result.
3231 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003232 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003233 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003234 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003235 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003236 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3237 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3238 }
Meng Wangafbc5852019-09-19 17:37:13 -07003239
3240 final long token = Binder.clearCallingIdentity();
3241 try {
3242 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3243 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003244 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003245 } catch (ImsException e) {
3246 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3247 + "is inactive, ignoring unregister.");
3248 // If the subscription is no longer active, just return, since the callback
3249 // will already have been removed internally.
3250 } finally {
3251 Binder.restoreCallingIdentity(token);
3252 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003253 }
3254
3255 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003256 public boolean isCapable(int subId, int capability, int regTech) {
3257 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003258 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3259 final long token = Binder.clearCallingIdentity();
3260 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003261 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003262 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003263 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003264 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3265 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003266 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003267 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3268 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003269 } finally {
3270 Binder.restoreCallingIdentity(token);
3271 }
3272 }
3273
3274 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003275 public boolean isAvailable(int subId, int capability, int regTech) {
3276 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003277 final long token = Binder.clearCallingIdentity();
3278 try {
3279 Phone phone = getPhone(subId);
3280 if (phone == null) return false;
3281 return phone.isImsCapabilityAvailable(capability, regTech);
3282 } finally {
3283 Binder.restoreCallingIdentity(token);
3284 }
3285 }
3286
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003287 /**
3288 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3289 * subscription.
3290 * @param subId The subscription to use to check the configuration.
3291 * @param callback The callback that will be used to send the result.
3292 * @param capability The MmTelFeature capability that will be used to send the result.
3293 * @param transportType The transport type of the MmTelFeature capability.
3294 */
3295 @Override
3296 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3297 int transportType) {
3298 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3299 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3300 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3301 "IMS not available on device.");
3302 }
3303 final long token = Binder.clearCallingIdentity();
3304 try {
3305 int slotId = getSlotIndex(subId);
3306 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3307 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3308 + subId + "'");
3309 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3310 }
3311 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3312 transportType, aBoolean -> {
3313 try {
3314 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3315 } catch (RemoteException e) {
3316 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3317 + "running. Ignore");
3318 }
3319 });
3320 } finally {
3321 Binder.restoreCallingIdentity(token);
3322 }
3323 }
3324
shilu366312e2019-12-17 09:28:10 -08003325 /**
3326 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3327 * @param subId The subscription to use to check the configuration.
3328 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003329 @Override
3330 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003331 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3332 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3333
Brad Ebinger35c841c2018-10-01 10:40:55 -07003334 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3335 final long token = Binder.clearCallingIdentity();
3336 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003337 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003338 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003339 } catch (ImsException e) {
3340 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003341 } finally {
3342 Binder.restoreCallingIdentity(token);
3343 }
3344 }
3345
3346 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003347 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003349 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003350 final long identity = Binder.clearCallingIdentity();
3351 try {
3352 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003353 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003354 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003355 } catch (ImsException e) {
3356 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003357 } finally {
3358 Binder.restoreCallingIdentity(identity);
3359 }
3360 }
3361
shilu366312e2019-12-17 09:28:10 -08003362 /**
3363 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3364 * @param subId The subscription to use to check the configuration.
3365 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003367 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003368 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003369 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003370 final long identity = Binder.clearCallingIdentity();
3371 try {
3372 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003373 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3374 } catch (ImsException e) {
3375 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003376 } finally {
3377 Binder.restoreCallingIdentity(identity);
3378 }
3379 }
3380
3381 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003382 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003384 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003388 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003389 } catch (ImsException e) {
3390 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
3394 }
3395
shilu366312e2019-12-17 09:28:10 -08003396 /**
3397 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3398 * @param subId The subscription to use to check the configuration.
3399 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003400 @Override
3401 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003402 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003403 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3404 final long identity = Binder.clearCallingIdentity();
3405 try {
3406 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003407 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003408 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003409 } catch (ImsException e) {
3410 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003411 } finally {
3412 Binder.restoreCallingIdentity(identity);
3413 }
3414 }
3415
3416 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003417 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003419 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003423 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003424 } catch (ImsException e) {
3425 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 } finally {
3427 Binder.restoreCallingIdentity(identity);
3428 }
3429 }
3430
shilu366312e2019-12-17 09:28:10 -08003431 /**
3432 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3433 * @param subId The subscription to use to check the configuration.
3434 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003435 @Override
3436 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003437 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003438 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3439 final long identity = Binder.clearCallingIdentity();
3440 try {
3441 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003442 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003443 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003444 } catch (ImsException e) {
3445 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003446 } finally {
3447 Binder.restoreCallingIdentity(identity);
3448 }
3449 }
3450
3451 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003452 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003454 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003455 final long identity = Binder.clearCallingIdentity();
3456 try {
3457 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003458 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003459 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003460 } catch (ImsException e) {
3461 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003462 } finally {
3463 Binder.restoreCallingIdentity(identity);
3464 }
3465 }
3466
3467 @Override
3468 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3470 "setVoWiFiNonPersistent");
3471 final long identity = Binder.clearCallingIdentity();
3472 try {
3473 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003474 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003475 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003476 } catch (ImsException e) {
3477 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003478 } finally {
3479 Binder.restoreCallingIdentity(identity);
3480 }
3481 }
3482
shilu366312e2019-12-17 09:28:10 -08003483 /**
3484 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3485 * @param subId The subscription to use to check the configuration.
3486 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003487 @Override
3488 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003489 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003490 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3491 final long identity = Binder.clearCallingIdentity();
3492 try {
3493 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003494 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003495 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003496 } catch (ImsException e) {
3497 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003498 } finally {
3499 Binder.restoreCallingIdentity(identity);
3500 }
3501 }
3502
3503 @Override
3504 public void setVoWiFiModeSetting(int subId, int mode) {
3505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3506 "setVoWiFiModeSetting");
3507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003510 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003511 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003512 } catch (ImsException e) {
3513 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003514 } finally {
3515 Binder.restoreCallingIdentity(identity);
3516 }
3517 }
3518
3519 @Override
3520 public int getVoWiFiRoamingModeSetting(int subId) {
3521 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3522 final long identity = Binder.clearCallingIdentity();
3523 try {
3524 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003525 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003526 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003527 } catch (ImsException e) {
3528 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003529 } finally {
3530 Binder.restoreCallingIdentity(identity);
3531 }
3532 }
3533
3534 @Override
3535 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3537 "setVoWiFiRoamingModeSetting");
3538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003541 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003542 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003543 } catch (ImsException e) {
3544 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003545 } finally {
3546 Binder.restoreCallingIdentity(identity);
3547 }
3548 }
3549
3550 @Override
3551 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3553 "setRttCapabilityEnabled");
3554 final long identity = Binder.clearCallingIdentity();
3555 try {
3556 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003557 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3558 } catch (ImsException e) {
3559 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003560 } finally {
3561 Binder.restoreCallingIdentity(identity);
3562 }
3563 }
3564
shilu366312e2019-12-17 09:28:10 -08003565 /**
3566 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3567 * @param subId The subscription to use to check the configuration.
3568 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003569 @Override
3570 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003571 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003576 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003577 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003578 } catch (ImsException e) {
3579 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003580 } finally {
3581 Binder.restoreCallingIdentity(identity);
3582 }
3583 }
3584
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003585 @Override
3586 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3587 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3588 final long identity = Binder.clearCallingIdentity();
3589 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003590 if (!isImsAvailableOnDevice()) {
3591 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3592 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003593 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003594 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003595 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003596 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003597 } catch (ImsException e) {
3598 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003599 } finally {
3600 Binder.restoreCallingIdentity(identity);
3601 }
3602 }
3603
3604 @Override
3605 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3606 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3607 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003608 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3609 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3610 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003611 try {
3612 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003613 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003614 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003615 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003616 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3617 + "is inactive, ignoring unregister.");
3618 // If the subscription is no longer active, just return, since the callback will already
3619 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003620 } finally {
3621 Binder.restoreCallingIdentity(identity);
3622 }
3623 }
3624
allenwtsu99c623b2020-01-03 18:24:23 +08003625
3626 private void checkModifyPhoneStatePermission(int subId, String message) {
3627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3628 message);
3629 }
3630
3631 private boolean isImsProvisioningRequired(int subId, int capability,
3632 boolean isMmtelCapability) {
3633 Phone phone = getPhone(subId);
3634 if (phone == null) {
3635 loge("phone instance null for subid " + subId);
3636 return false;
3637 }
3638 if (isMmtelCapability) {
3639 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3640 return false;
3641 }
3642 } else {
3643 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3644 return false;
3645 }
3646 }
3647 return true;
3648 }
3649
3650 @Override
3651 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3652 boolean isProvisioned) {
3653 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3654
3655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3658 if (!isImsProvisioningRequired(subId, capability, false)) {
3659 return;
3660 }
3661
3662 // this capability requires provisioning, route to the correct API.
3663 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3664 switch (capability) {
3665 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3666 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3667 ims.setEabProvisioned(isProvisioned);
3668 break;
3669 default: {
3670 throw new IllegalArgumentException("Tried to set provisioning for "
3671 + "rcs capability '" + capability + "', which does not require "
3672 + "provisioning.");
3673 }
3674 }
3675 } finally {
3676 Binder.restoreCallingIdentity(identity);
3677 }
3678
3679 }
3680
3681
3682 @Override
3683 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3684 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3688 if (!isImsProvisioningRequired(subId, capability, false)) {
3689 return true;
3690 }
3691
3692 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3693 switch (capability) {
3694 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3695 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3696 return ims.isEabProvisionedOnDevice();
3697
3698 default: {
3699 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3700 + "capability '" + capability + "', which does not require "
3701 + "provisioning.");
3702 }
3703 }
3704
3705 } finally {
3706 Binder.restoreCallingIdentity(identity);
3707 }
3708 }
3709
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003710 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003711 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3712 boolean isProvisioned) {
3713 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3714 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3715 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3716 }
allenwtsu99c623b2020-01-03 18:24:23 +08003717 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003718 final long identity = Binder.clearCallingIdentity();
3719 try {
3720 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003721 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003722 return;
3723 }
3724
3725 // this capability requires provisioning, route to the correct API.
3726 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3727 switch (capability) {
3728 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3729 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3730 ims.setVolteProvisioned(isProvisioned);
3731 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3732 ims.setWfcProvisioned(isProvisioned);
3733 }
3734 break;
3735 }
3736 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3737 // There is currently no difference in VT provisioning type.
3738 ims.setVtProvisioned(isProvisioned);
3739 break;
3740 }
3741 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3742 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3743 // change the capability of the feature instead if needed.
3744 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3745 == isProvisioned) {
3746 // No change in provisioning.
3747 return;
3748 }
3749 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3750 try {
3751 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003752 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003753 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3754 + ", Exception" + e.getMessage());
3755 }
3756 break;
3757 }
3758 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003759 throw new IllegalArgumentException("Tried to set provisioning for "
3760 + "MmTel capability '" + capability + "', which does not require "
3761 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003762 }
3763 }
3764
3765 } finally {
3766 Binder.restoreCallingIdentity(identity);
3767 }
3768 }
3769
3770 @Override
3771 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3772 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3773 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3774 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3775 }
3776 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3777 final long identity = Binder.clearCallingIdentity();
3778 try {
3779 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003780 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003781 return true;
3782 }
3783
3784 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3785 switch (capability) {
3786 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3787 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3788 return ims.isVolteProvisionedOnDevice();
3789 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3790 return ims.isWfcProvisionedOnDevice();
3791 }
3792 // This should never happen, since we are checking tech above to make sure it
3793 // is either LTE or IWLAN.
3794 throw new IllegalArgumentException("Invalid radio technology for voice "
3795 + "capability.");
3796 }
3797 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3798 // There is currently no difference in VT provisioning type.
3799 return ims.isVtProvisionedOnDevice();
3800 }
3801 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3802 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3803 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3804 }
3805 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003806 throw new IllegalArgumentException(
3807 "Tried to get provisioning for MmTel capability '" + capability
3808 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003809 }
3810 }
3811
3812 } finally {
3813 Binder.restoreCallingIdentity(identity);
3814 }
3815 }
3816
3817 @Override
3818 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3819 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3820 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3821 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3822 }
3823 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3824 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3825 return (provisionedBits & capability) > 0;
3826 }
3827
3828 @Override
3829 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3830 boolean isProvisioned) {
3831 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3832 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3833 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3834 }
3835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3836 "setProvisioningStatusForCapability");
3837 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3838 // If the current provisioning status for capability already matches isProvisioned,
3839 // do nothing.
3840 if (((provisionedBits & capability) > 0) == isProvisioned) {
3841 return;
3842 }
3843 if (isProvisioned) {
3844 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3845 } else {
3846 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3847 }
3848 }
3849
3850 /**
3851 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3852 * technology. The bitfield should mirror the bitfield defined by
3853 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3854 */
3855 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3856 String key = getMmTelProvisioningKey(subId, tech);
3857 // Default is no capabilities are provisioned.
3858 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3859 }
3860
3861 /**
3862 * Sets the MmTel capability provisioning bitfield (defined by
3863 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3864 * technology specified.
3865 *
3866 * Note: This is a synchronous command and should not be called on UI thread.
3867 */
3868 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3869 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3870 String key = getMmTelProvisioningKey(subId, tech);
3871 editor.putInt(key, newField);
3872 editor.commit();
3873 }
3874
3875 private static String getMmTelProvisioningKey(int subId, int tech) {
3876 // resulting key is provision_ims_mmtel_{subId}_{tech}
3877 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3878 }
3879
3880 /**
3881 * Query CarrierConfig to see if the specified capability requires provisioning for the
3882 * carrier associated with the subscription id.
3883 */
3884 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3885 int capability) {
3886 CarrierConfigManager configManager = new CarrierConfigManager(context);
3887 PersistableBundle c = configManager.getConfigForSubId(subId);
3888 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003889 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003890 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3891 false);
3892 boolean requireVoiceVtProvisioning = c.getBoolean(
3893 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3894
3895 // First check to make sure that the capability requires provisioning.
3896 switch (capability) {
3897 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3898 // intentional fallthrough
3899 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3900 if (requireVoiceVtProvisioning) {
3901 // Voice and Video requires provisioning
3902 return true;
3903 }
3904 break;
3905 }
3906 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3907 if (requireUtProvisioning) {
3908 // UT requires provisioning
3909 return true;
3910 }
3911 break;
3912 }
3913 }
3914 return false;
3915 }
3916
allenwtsu99c623b2020-01-03 18:24:23 +08003917 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3918 int capability) {
3919 CarrierConfigManager configManager = new CarrierConfigManager(context);
3920 PersistableBundle c = configManager.getConfigForSubId(subId);
3921
3922 boolean requireRcsProvisioning = c.getBoolean(
3923 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3924
3925 // First check to make sure that the capability requires provisioning.
3926 switch (capability) {
3927 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3928 // intentional fallthrough
3929 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3930 if (requireRcsProvisioning) {
3931 // OPTION or PRESENCE requires provisioning
3932 return true;
3933 }
3934 break;
3935 }
3936 }
3937 return false;
3938 }
3939
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003940 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003941 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003942 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3943 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3944 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003945 enforceReadPrivilegedPermission("getImsProvisioningInt");
3946 final long identity = Binder.clearCallingIdentity();
3947 try {
3948 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003949 int slotId = getSlotIndex(subId);
3950 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3951 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3952 + subId + "' for key:" + key);
3953 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3954 }
3955 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003956 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003957 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3958 + subId + "' for key:" + key);
3959 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003960 } finally {
3961 Binder.restoreCallingIdentity(identity);
3962 }
3963 }
3964
3965 @Override
3966 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003967 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3968 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3969 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003970 enforceReadPrivilegedPermission("getImsProvisioningString");
3971 final long identity = Binder.clearCallingIdentity();
3972 try {
3973 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003974 int slotId = getSlotIndex(subId);
3975 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3976 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3977 + subId + "' for key:" + key);
3978 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3979 }
3980 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003981 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003982 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3983 + subId + "' for key:" + key);
3984 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003985 } finally {
3986 Binder.restoreCallingIdentity(identity);
3987 }
3988 }
3989
3990 @Override
3991 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003992 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3993 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3994 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3996 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003997 final long identity = Binder.clearCallingIdentity();
3998 try {
3999 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004000 int slotId = getSlotIndex(subId);
4001 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4002 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4003 + subId + "' for key:" + key);
4004 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4005 }
4006 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004007 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004008 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4009 + "' for key:" + key);
4010 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
4014 }
4015
4016 @Override
4017 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004018 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4019 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4020 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4022 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004023 final long identity = Binder.clearCallingIdentity();
4024 try {
4025 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004026 int slotId = getSlotIndex(subId);
4027 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4028 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4029 + subId + "' for key:" + key);
4030 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4031 }
4032 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004033 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004034 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4035 + "' for key:" + key);
4036 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004037 } finally {
4038 Binder.restoreCallingIdentity(identity);
4039 }
4040 }
4041
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004042 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 int slotId = SubscriptionManager.getSlotIndex(subId);
4044 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004045 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4046 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004047 }
4048 return slotId;
4049 }
4050
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004051 private int getSlotIndex(int subId) {
4052 int slotId = SubscriptionManager.getSlotIndex(subId);
4053 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4054 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4055 }
4056 return slotId;
4057 }
4058
Wink Saville36469e72014-06-11 15:17:00 -07004059 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004060 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004061 */
4062 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004063 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4064 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004065 final int targetSdk = getTargetSdk(callingPackage);
4066 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004067 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004068 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004069 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004070 mApp, subId, callingPackage, callingFeatureId,
4071 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004072 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4073 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004074
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004075 final long identity = Binder.clearCallingIdentity();
4076 try {
4077 final Phone phone = getPhone(subId);
4078 if (phone != null) {
4079 return phone.getServiceState().getDataNetworkType();
4080 } else {
4081 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4082 }
4083 } finally {
4084 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004085 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004086 }
4087
4088 /**
4089 * Returns the data network type
4090 */
4091 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004092 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4093 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4094 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004095 }
4096
4097 /**
4098 * Returns the data network type for a subId
4099 */
4100 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004101 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4102 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004103 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004104 mApp, subId, callingPackage, callingFeatureId,
4105 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004106 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4107 }
4108
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004109 final long identity = Binder.clearCallingIdentity();
4110 try {
4111 final Phone phone = getPhone(subId);
4112 if (phone != null) {
4113 return phone.getServiceState().getDataNetworkType();
4114 } else {
4115 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4116 }
4117 } finally {
4118 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004120 }
4121
4122 /**
Wink Saville36469e72014-06-11 15:17:00 -07004123 * Returns the Voice network type for a subId
4124 */
4125 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004126 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4127 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004129 mApp, subId, callingPackage, callingFeatureId,
4130 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004131 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4132 }
4133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004134 final long identity = Binder.clearCallingIdentity();
4135 try {
4136 final Phone phone = getPhone(subId);
4137 if (phone != null) {
4138 return phone.getServiceState().getVoiceNetworkType();
4139 } else {
4140 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4141 }
4142 } finally {
4143 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004144 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004145 }
4146
4147 /**
4148 * @return true if a ICC card is present
4149 */
4150 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004151 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004152 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4153 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004154 }
4155
4156 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004157 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004158 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004159 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004160 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004161 final long identity = Binder.clearCallingIdentity();
4162 try {
4163 final Phone phone = PhoneFactory.getPhone(slotIndex);
4164 if (phone != null) {
4165 return phone.getIccCard().hasIccCard();
4166 } else {
4167 return false;
4168 }
4169 } finally {
4170 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004172 }
4173
4174 /**
4175 * Return if the current radio is LTE on CDMA. This
4176 * is a tri-state return value as for a period of time
4177 * the mode may be unknown.
4178 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004179 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004180 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004181 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004182 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004183 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004184 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4185 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4186 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004187 }
4188
Sanket Padawe356d7632015-06-22 14:03:32 -07004189 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004190 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4191 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004192 try {
4193 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4194 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004195 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4196 }
4197
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004198 final long identity = Binder.clearCallingIdentity();
4199 try {
4200 final Phone phone = getPhone(subId);
4201 if (phone == null) {
4202 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4203 } else {
4204 return phone.getLteOnCdmaMode();
4205 }
4206 } finally {
4207 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004208 }
Wink Saville36469e72014-06-11 15:17:00 -07004209 }
4210
Wink Saville36469e72014-06-11 15:17:00 -07004211 /**
4212 * {@hide}
4213 * Returns Default subId, 0 in the case of single standby.
4214 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004215 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004216 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004217 }
4218
Shishir Agrawala9f32182016-04-12 12:00:16 -07004219 private int getSlotForDefaultSubscription() {
4220 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4221 }
4222
Wink Savilleb564aae2014-10-23 10:18:09 -07004223 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004224 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004225 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004226
Pengquan Menge92a50d2018-09-21 15:54:48 -07004227 private boolean isActiveSubscription(int subId) {
4228 return mSubscriptionController.isActiveSubId(subId);
4229 }
4230
Ihab Awadf2177b72013-11-25 13:33:23 -08004231 /**
4232 * @see android.telephony.TelephonyManager.WifiCallingChoices
4233 */
4234 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004235 final long identity = Binder.clearCallingIdentity();
4236 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004237 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4239 getWhenToMakeWifiCallsDefaultPreference());
4240 } finally {
4241 Binder.restoreCallingIdentity(identity);
4242 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004243 }
4244
4245 /**
4246 * @see android.telephony.TelephonyManager.WifiCallingChoices
4247 */
4248 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004249 final long identity = Binder.clearCallingIdentity();
4250 try {
4251 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004252 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4254 } finally {
4255 Binder.restoreCallingIdentity(identity);
4256 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004257 }
4258
Sailesh Nepald1e68152013-12-12 19:08:02 -08004259 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004260 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004261 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004262 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004263
Jordan Liu4c733742019-02-28 12:03:40 -08004264 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4265 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4266 if (phoneId == -1) {
4267 throw new IllegalArgumentException("Given slot index: " + slotIndex
4268 + " does not correspond to an active phone");
4269 }
4270 return PhoneFactory.getPhone(phoneId);
4271 }
4272
Shishir Agrawal566b7612013-10-28 14:41:00 -07004273 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004274 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4275 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4277 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004279 if (DBG) {
4280 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4281 }
4282 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4283 p2);
4284 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004285
Jordan Liu4c733742019-02-28 12:03:40 -08004286
4287 @Override
4288 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4289 int slotIndex, String callingPackage, String aid, int p2) {
4290 enforceModifyPermission();
4291 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4292 if (DBG) {
4293 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4294 }
4295 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4296 callingPackage, aid, p2);
4297 }
4298
4299 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4300 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004301 final long identity = Binder.clearCallingIdentity();
4302 try {
4303 if (TextUtils.equals(ISDR_AID, aid)) {
4304 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004305 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4306 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307 if (bestComponent == null
4308 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4309 loge("The calling package is not allowed to access ISD-R.");
4310 throw new SecurityException(
4311 "The calling package is not allowed to access ISD-R.");
4312 }
Derek Tan740e1672017-06-27 14:56:27 -07004313 }
Derek Tan740e1672017-06-27 14:56:27 -07004314
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004315 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004316 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4317 null /* workSource */);
4318 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004319 return response;
4320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004323 }
4324
4325 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004326 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4328 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004329 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4330 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4331 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004332
Jordan Liu4c733742019-02-28 12:03:40 -08004333 @Override
4334 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4335 enforceModifyPermission();
4336 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4337 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4338 channel);
4339 }
4340
4341 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004342 final long identity = Binder.clearCallingIdentity();
4343 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004344 if (channel < 0) {
4345 return false;
4346 }
Jordan Liu4c733742019-02-28 12:03:40 -08004347 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4348 null /* workSource */);
4349 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350 return success;
4351 } finally {
4352 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004353 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004354 }
4355
4356 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004357 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004358 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4360 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004361 if (DBG) {
4362 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4363 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4364 + p3 + " data=" + data);
4365 }
4366 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4367 command, p1, p2, p3, data);
4368 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004369
Jordan Liu4c733742019-02-28 12:03:40 -08004370 @Override
4371 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4372 int command, int p1, int p2, int p3, String data) {
4373 enforceModifyPermission();
4374 if (DBG) {
4375 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4376 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4377 + p3 + " data=" + data);
4378 }
4379 return iccTransmitApduLogicalChannelWithPermission(
4380 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4381 data);
4382 }
4383
4384 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4385 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004386 final long identity = Binder.clearCallingIdentity();
4387 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004388 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004389 return "";
4390 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004391
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004392 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004393 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4394 null /* workSource */);
4395 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397 // Append the returned status code to the end of the response payload.
4398 String s = Integer.toHexString(
4399 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4400 if (response.payload != null) {
4401 s = IccUtils.bytesToHexString(response.payload) + s;
4402 }
4403 return s;
4404 } finally {
4405 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004406 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004407 }
Jake Hambye994d462014-02-03 13:10:13 -08004408
Evan Charltonc66da362014-05-16 14:06:40 -07004409 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004410 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4411 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4413 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004414 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004415 if (DBG) {
4416 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4417 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4418 }
4419 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4420 cla, command, p1, p2, p3, data);
4421 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004422
Jordan Liu4c733742019-02-28 12:03:40 -08004423 @Override
4424 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4425 int command, int p1, int p2, int p3, String data) {
4426 enforceModifyPermission();
4427 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4428 if (DBG) {
4429 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4430 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4431 + " data=" + data);
4432 }
4433
4434 return iccTransmitApduBasicChannelWithPermission(
4435 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4436 p2, p3, data);
4437 }
4438
4439 // open APDU basic channel assuming the caller has sufficient permissions
4440 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4441 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 final long identity = Binder.clearCallingIdentity();
4443 try {
4444 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4445 && TextUtils.equals(ISDR_AID, data)) {
4446 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004447 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4448 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449 if (bestComponent == null
4450 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4451 loge("The calling package is not allowed to select ISD-R.");
4452 throw new SecurityException(
4453 "The calling package is not allowed to select ISD-R.");
4454 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004455 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004458 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4459 null /* workSource */);
4460 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004462 // Append the returned status code to the end of the response payload.
4463 String s = Integer.toHexString(
4464 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4465 if (response.payload != null) {
4466 s = IccUtils.bytesToHexString(response.payload) + s;
4467 }
4468 return s;
4469 } finally {
4470 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004471 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004472 }
4473
4474 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004475 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004476 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4478 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480 final long identity = Binder.clearCallingIdentity();
4481 try {
4482 if (DBG) {
4483 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4484 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4485 }
4486
4487 IccIoResult response =
4488 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4489 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4490 subId);
4491
4492 if (DBG) {
4493 log("Exchange SIM_IO [R]" + response);
4494 }
4495
4496 byte[] result = null;
4497 int length = 2;
4498 if (response.payload != null) {
4499 length = 2 + response.payload.length;
4500 result = new byte[length];
4501 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4502 } else {
4503 result = new byte[length];
4504 }
4505
4506 result[length - 1] = (byte) response.sw2;
4507 result[length - 2] = (byte) response.sw1;
4508 return result;
4509 } finally {
4510 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004511 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004512 }
4513
Nathan Haroldb3014052017-01-25 15:57:32 -08004514 /**
4515 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4516 * on a particular subscription
4517 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004518 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4519 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004520 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004521 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004522 return null;
4523 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004524
4525 final long identity = Binder.clearCallingIdentity();
4526 try {
4527 if (appType != TelephonyManager.APPTYPE_USIM
4528 && appType != TelephonyManager.APPTYPE_SIM) {
4529 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4530 return null;
4531 }
4532 Object response = sendRequest(
4533 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4534 if (response instanceof String[]) {
4535 return (String[]) response;
4536 }
yincheng zhao2737e882019-09-06 17:06:54 -07004537 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004538 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004539 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 } finally {
4541 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004542 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004543 }
4544
yincheng zhao2737e882019-09-06 17:06:54 -07004545 /**
4546 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4547 * subscription.
4548 *
4549 * @param subId the id of the subscription.
4550 * @param appType the uicc app type, must be USIM or SIM.
4551 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4552 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004553 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004554 * @return number of fplmns that is successfully written to the SIM.
4555 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004556 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4557 String callingFeatureId) {
4558 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4559 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004560 if (DBG) logv("no permissions for setForbiddenplmns");
4561 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4562 }
4563 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4564 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4565 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4566 }
4567 if (fplmns == null) {
4568 throw new IllegalArgumentException("Fplmn List provided is null");
4569 }
4570 for (String fplmn : fplmns) {
4571 if (!CellIdentity.isValidPlmn(fplmn)) {
4572 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4573 }
4574 }
4575 final long identity = Binder.clearCallingIdentity();
4576 try {
4577 Object response = sendRequest(
4578 CMD_SET_FORBIDDEN_PLMNS,
4579 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4580 subId);
4581 return (int) response;
4582 } finally {
4583 Binder.restoreCallingIdentity(identity);
4584 }
4585 }
4586
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004587 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004588 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4590 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592 final long identity = Binder.clearCallingIdentity();
4593 try {
4594 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4595 if (response.payload == null) {
4596 return "";
4597 }
Evan Charltonc66da362014-05-16 14:06:40 -07004598
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004599 // Append the returned status code to the end of the response payload.
4600 String s = Integer.toHexString(
4601 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4602 s = IccUtils.bytesToHexString(response.payload) + s;
4603 return s;
4604 } finally {
4605 Binder.restoreCallingIdentity(identity);
4606 }
Evan Charltonc66da362014-05-16 14:06:40 -07004607 }
4608
Jake Hambye994d462014-02-03 13:10:13 -08004609 /**
4610 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4611 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4612 *
4613 * @param itemID the ID of the item to read
4614 * @return the NV item as a String, or null on error.
4615 */
4616 @Override
4617 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004618 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4620 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004621
4622 final long identity = Binder.clearCallingIdentity();
4623 try {
4624 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004625 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004626 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4627 return value;
4628 } finally {
4629 Binder.restoreCallingIdentity(identity);
4630 }
Jake Hambye994d462014-02-03 13:10:13 -08004631 }
4632
4633 /**
4634 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4635 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4636 *
4637 * @param itemID the ID of the item to read
4638 * @param itemValue the value to write, as a String
4639 * @return true on success; false on any failure
4640 */
4641 @Override
4642 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004643 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4645 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646
4647 final long identity = Binder.clearCallingIdentity();
4648 try {
4649 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4650 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004651 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004652 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4653 return success;
4654 } finally {
4655 Binder.restoreCallingIdentity(identity);
4656 }
Jake Hambye994d462014-02-03 13:10:13 -08004657 }
4658
4659 /**
4660 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4661 * Used for device configuration by some CDMA operators.
4662 *
4663 * @param preferredRoamingList byte array containing the new PRL
4664 * @return true on success; false on any failure
4665 */
4666 @Override
4667 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4669 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004670
4671 final long identity = Binder.clearCallingIdentity();
4672 try {
4673 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4674 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4675 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4676 return success;
4677 } finally {
4678 Binder.restoreCallingIdentity(identity);
4679 }
Jake Hambye994d462014-02-03 13:10:13 -08004680 }
4681
4682 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004683 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004684 * Used for device configuration by some CDMA operators.
4685 *
chen xu6dac5ab2018-10-26 17:39:23 -07004686 * @param slotIndex - device slot.
4687 *
Jake Hambye994d462014-02-03 13:10:13 -08004688 * @return true on success; false on any failure
4689 */
4690 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004691 public boolean resetModemConfig(int slotIndex) {
4692 Phone phone = PhoneFactory.getPhone(slotIndex);
4693 if (phone != null) {
4694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4695 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004696
chen xu6dac5ab2018-10-26 17:39:23 -07004697 final long identity = Binder.clearCallingIdentity();
4698 try {
4699 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4700 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4701 return success;
4702 } finally {
4703 Binder.restoreCallingIdentity(identity);
4704 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 }
chen xu6dac5ab2018-10-26 17:39:23 -07004706 return false;
4707 }
4708
4709 /**
4710 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4711 *
4712 * @param slotIndex - device slot.
4713 *
4714 * @return true on success; false on any failure
4715 */
4716 @Override
4717 public boolean rebootModem(int slotIndex) {
4718 Phone phone = PhoneFactory.getPhone(slotIndex);
4719 if (phone != null) {
4720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4721 mApp, phone.getSubId(), "rebootModem");
4722
4723 final long identity = Binder.clearCallingIdentity();
4724 try {
4725 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4726 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4727 return success;
4728 } finally {
4729 Binder.restoreCallingIdentity(identity);
4730 }
4731 }
4732 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004733 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004734
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004735 public String[] getPcscfAddress(String apnType, String callingPackage,
4736 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004737 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4739 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004740 return new String[0];
4741 }
4742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004743 final long identity = Binder.clearCallingIdentity();
4744 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004745 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004746 } finally {
4747 Binder.restoreCallingIdentity(identity);
4748 }
Wink Saville36469e72014-06-11 15:17:00 -07004749 }
4750
Brad Ebinger51f743a2017-01-23 13:50:20 -08004751 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004752 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4753 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004754 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004755 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004757
4758 final long identity = Binder.clearCallingIdentity();
4759 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004760 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004761 // may happen if the device does not support IMS.
4762 return;
4763 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004764 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765 } finally {
4766 Binder.restoreCallingIdentity(identity);
4767 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004768 }
4769
4770 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004771 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4772 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004773 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004774 public void disableIms(int slotId) {
4775 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776
4777 final long identity = Binder.clearCallingIdentity();
4778 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004779 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004780 // may happen if the device does not support IMS.
4781 return;
4782 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004783 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 } finally {
4785 Binder.restoreCallingIdentity(identity);
4786 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004787 }
4788
4789 /**
4790 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4791 * feature or {@link null} if the service is not available. If the feature is available, the
4792 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4793 */
4794 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004795 IImsServiceFeatureCallback callback) {
4796 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004797
4798 final long identity = Binder.clearCallingIdentity();
4799 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004800 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004801 // may happen if the device does not support IMS.
4802 return null;
4803 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004804 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004805 } finally {
4806 Binder.restoreCallingIdentity(identity);
4807 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004808 }
4809
4810 /**
4811 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4812 * feature during emergency calling or {@link null} if the service is not available. If the
4813 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4814 * listener for feature updates.
4815 */
4816 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4817 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818
4819 final long identity = Binder.clearCallingIdentity();
4820 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004821 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004822 // may happen if the device does not support IMS.
4823 return null;
4824 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004825 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004826 } finally {
4827 Binder.restoreCallingIdentity(identity);
4828 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004829 }
4830
Brad Ebinger5f64b052017-12-14 14:26:15 -08004831 /**
4832 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004833 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004834 */
4835 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4836 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004837
4838 final long identity = Binder.clearCallingIdentity();
4839 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004840 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004841 // may happen if the device does not support IMS.
4842 return null;
4843 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004844 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004845 } finally {
4846 Binder.restoreCallingIdentity(identity);
4847 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004848 }
4849
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004850 /**
4851 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004852 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004853 */
4854 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4855 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004856
4857 final long identity = Binder.clearCallingIdentity();
4858 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004859 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004860 // may happen if the device does not support IMS.
4861 return null;
4862 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004863 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004864 } finally {
4865 Binder.restoreCallingIdentity(identity);
4866 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004867 }
4868
Brad Ebinger884c07b2018-02-15 16:17:40 -08004869 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004870 * Sets the ImsService Package Name that Telephony will bind to.
4871 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004872 * @param slotIndex the slot ID that the ImsService should bind for.
4873 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004874 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004875 * @param featureTypes An integer array of feature types associated with a packageName.
4876 * @param packageName The name of the package that the current configuration will be replaced
4877 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004878 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004879 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004880 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4881 int[] featureTypes, String packageName) {
4882 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4883 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4885 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004886 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 final long identity = Binder.clearCallingIdentity();
4889 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004890 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004891 // may happen if the device does not support IMS.
4892 return false;
4893 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004894 Map<Integer, String> featureConfig = new HashMap<>();
4895 for (int featureType : featureTypes) {
4896 featureConfig.put(featureType, packageName);
4897 }
4898 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4899 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900 } finally {
4901 Binder.restoreCallingIdentity(identity);
4902 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004903 }
4904
4905 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004906 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004907 *
4908 * @param slotId The slot that the ImsService is associated with.
4909 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4910 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004911 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004912 * @return the package name of the ImsService configuration.
4913 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004914 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4915 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004916 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004917 TelephonyPermissions
4918 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4919 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4920 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004922 final long identity = Binder.clearCallingIdentity();
4923 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004924 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004925 // may happen if the device does not support IMS.
4926 return "";
4927 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004928 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004929 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4930 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 } finally {
4932 Binder.restoreCallingIdentity(identity);
4933 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004934 }
4935
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004936 /**
4937 * Get the MmTelFeature state associated with the requested subscription id.
4938 * @param subId The subscription that the MmTelFeature is associated with.
4939 * @param callback A callback with an integer containing the
4940 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4941 */
4942 @Override
4943 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4944 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4945 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4946 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4947 "IMS not available on device.");
4948 }
4949 final long token = Binder.clearCallingIdentity();
4950 try {
4951 int slotId = getSlotIndex(subId);
4952 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4953 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4954 + subId + "'");
4955 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4956 }
4957 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4958 try {
4959 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4960 } catch (RemoteException e) {
4961 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4962 + "Ignore");
4963 }
4964 });
4965 } finally {
4966 Binder.restoreCallingIdentity(token);
4967 }
4968 }
4969
Wink Saville36469e72014-06-11 15:17:00 -07004970 public void setImsRegistrationState(boolean registered) {
4971 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972
4973 final long identity = Binder.clearCallingIdentity();
4974 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004975 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004976 } finally {
4977 Binder.restoreCallingIdentity(identity);
4978 }
Wink Saville36469e72014-06-11 15:17:00 -07004979 }
4980
4981 /**
Stuart Scott54788802015-03-30 13:18:01 -07004982 * Set the network selection mode to automatic.
4983 *
4984 */
4985 @Override
4986 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4988 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989
4990 final long identity = Binder.clearCallingIdentity();
4991 try {
shilufc958392020-01-20 11:36:01 -08004992 if (!isActiveSubscription(subId)) {
4993 return;
4994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4996 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4997 } finally {
4998 Binder.restoreCallingIdentity(identity);
4999 }
Stuart Scott54788802015-03-30 13:18:01 -07005000 }
5001
Pengquan Mengea84e042018-09-20 14:57:26 -07005002 /**
5003 * Ask the radio to connect to the input network and change selection mode to manual.
5004 *
5005 * @param subId the id of the subscription.
5006 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5007 * the operator to attach to.
5008 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5009 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5010 * normal network selection next time.
5011 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005012 */
5013 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005014 public boolean setNetworkSelectionModeManual(
5015 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5017 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005018
5019 if (!isActiveSubscription(subId)) {
5020 return false;
5021 }
5022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023 final long identity = Binder.clearCallingIdentity();
5024 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005025 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005026 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005027 if (DBG) {
5028 log("setNetworkSelectionModeManual: subId: " + subId
5029 + " operator: " + operatorInfo);
5030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5032 } finally {
5033 Binder.restoreCallingIdentity(identity);
5034 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005035 }
5036
5037 /**
5038 * Scans for available networks.
5039 */
5040 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005041 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5042 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5044 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005045 LocationAccessPolicy.LocationPermissionResult locationResult =
5046 LocationAccessPolicy.checkLocationPermission(mApp,
5047 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5048 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005049 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005050 .setCallingPid(Binder.getCallingPid())
5051 .setCallingUid(Binder.getCallingUid())
5052 .setMethod("getCellNetworkScanResults")
5053 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5054 .build());
5055 switch (locationResult) {
5056 case DENIED_HARD:
5057 throw new SecurityException("Not allowed to access scan results -- location");
5058 case DENIED_SOFT:
5059 return null;
5060 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005061
Pengquan Menga1bb6272018-09-06 09:59:22 -07005062 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063 try {
5064 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005065 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067 } finally {
5068 Binder.restoreCallingIdentity(identity);
5069 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005070 }
5071
5072 /**
yinxub1bed742017-04-17 11:45:04 -07005073 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005074 *
yinxub1bed742017-04-17 11:45:04 -07005075 * @param subId id of the subscription
5076 * @param request contains the radio access networks with bands/channels to scan
5077 * @param messenger callback messenger for scan results or errors
5078 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005079 * @return the id of the requested scan which can be used to stop the scan.
5080 */
5081 @Override
5082 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005083 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5085 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005086 LocationAccessPolicy.LocationPermissionResult locationResult =
5087 LocationAccessPolicy.checkLocationPermission(mApp,
5088 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5089 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005090 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005091 .setCallingPid(Binder.getCallingPid())
5092 .setCallingUid(Binder.getCallingUid())
5093 .setMethod("requestNetworkScan")
5094 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5095 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005096 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005097 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005098 if (e != null) {
5099 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5100 throw e;
5101 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005102 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005103 return TelephonyScanManager.INVALID_SCAN_ID;
5104 }
5105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106 }
Hall Liu912dfd32019-04-25 14:02:26 -07005107 int callingUid = Binder.getCallingUid();
5108 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005109 final long identity = Binder.clearCallingIdentity();
5110 try {
5111 return mNetworkScanRequestTracker.startNetworkScan(
5112 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005113 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005114 } finally {
5115 Binder.restoreCallingIdentity(identity);
5116 }
yinxu504e1392017-04-12 16:03:22 -07005117 }
5118
Hall Liub2ac8ef2019-02-28 15:56:23 -08005119 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005120 NetworkScanRequest request, int subId) {
5121 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5122 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5123 boolean hasNetworkScanPermission =
5124 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5125 == PERMISSION_GRANTED;
5126
5127 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5128 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5129 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005130 }
5131
5132 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5133 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005134 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5135 return new SecurityException("Specific channels must not be"
5136 + " scanned without location access.");
5137 }
5138 }
5139 }
5140
Hall Liub2ac8ef2019-02-28 15:56:23 -08005141 return null;
5142 }
5143
yinxu504e1392017-04-12 16:03:22 -07005144 /**
5145 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005146 *
5147 * @param subId id of the subscription
5148 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005149 */
5150 @Override
5151 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5153 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154
Hall Liu912dfd32019-04-25 14:02:26 -07005155 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156 final long identity = Binder.clearCallingIdentity();
5157 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005158 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 } finally {
5160 Binder.restoreCallingIdentity(identity);
5161 }
yinxu504e1392017-04-12 16:03:22 -07005162 }
5163
5164 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005165 * Get the calculated preferred network type.
5166 * Used for debugging incorrect network type.
5167 *
5168 * @return the preferred network type, defined in RILConstants.java.
5169 */
5170 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005171 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005172 final Phone defaultPhone = getDefaultPhone();
5173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005174 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005175 return RILConstants.PREFERRED_NETWORK_MODE;
5176 }
5177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178 final long identity = Binder.clearCallingIdentity();
5179 try {
5180 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005181 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005182 } finally {
5183 Binder.restoreCallingIdentity(identity);
5184 }
Junda Liu84d15a22014-07-02 11:21:04 -07005185 }
5186
5187 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005188 * Get the preferred network type.
5189 * Used for device configuration by some CDMA operators.
5190 *
5191 * @return the preferred network type, defined in RILConstants.java.
5192 */
5193 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005194 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005195 TelephonyPermissions
5196 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5197 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198
5199 final long identity = Binder.clearCallingIdentity();
5200 try {
5201 if (DBG) log("getPreferredNetworkType");
5202 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5203 int networkType = (result != null ? result[0] : -1);
5204 if (DBG) log("getPreferredNetworkType: " + networkType);
5205 return networkType;
5206 } finally {
5207 Binder.restoreCallingIdentity(identity);
5208 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005209 }
5210
5211 /**
5212 * Set the preferred network type.
5213 * Used for device configuration by some CDMA operators.
5214 *
5215 * @param networkType the preferred network type, defined in RILConstants.java.
5216 * @return true on success; false on any failure.
5217 */
5218 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005219 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5221 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005222
5223 final long identity = Binder.clearCallingIdentity();
5224 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005225 Settings.Global.putInt(mApp.getContentResolver(),
5226 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5227 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 } finally {
5229 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005230 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005231 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005232
5233 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005234 * Get the allowed network types that store in the telephony provider.
5235 *
5236 * @param subId the id of the subscription.
5237 * @return allowedNetworkTypes the allowed network types.
5238 */
5239 @Override
5240 public long getAllowedNetworkTypes(int subId) {
5241 TelephonyPermissions
5242 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5243 mApp, subId, "getAllowedNetworkTypes");
5244
5245 final long identity = Binder.clearCallingIdentity();
5246 try {
5247 return SubscriptionManager.getLongSubscriptionProperty(
5248 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
5252 }
5253
5254 /**
5255 * Set the allowed network types.
5256 *
5257 * @param subId the id of the subscription.
5258 * @param allowedNetworkTypes the allowed network types.
5259 * @return true on success; false on any failure.
5260 */
5261 @Override
5262 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5264 mApp, subId, "setAllowedNetworkTypes");
5265 final long identity = Binder.clearCallingIdentity();
5266 try {
5267 SubscriptionManager.setSubscriptionProperty(subId,
5268 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5269 String.valueOf(allowedNetworkTypes));
5270 return setPreferredNetworkTypesInternal(subId);
5271 } finally {
5272 Binder.restoreCallingIdentity(identity);
5273 }
5274 }
5275
5276 private boolean setPreferredNetworkTypesInternal(int subId) {
5277 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5278 Settings.Global.getInt(mApp.getContentResolver(),
5279 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5280 RILConstants.PREFERRED_NETWORK_MODE));
5281 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5282 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5283 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5284 (int) (networkTypeBitMask & allowedNetworkTypes));
5285
5286 if (DBG) {
5287 log("setPreferredNetworkTypesInternal: subId " + subId
5288 + " networkTypes " + networkTypeBitMask
5289 + " allowedNetworkTypes " + allowedNetworkTypes
5290 + " networkMode " + networkMode);
5291 }
5292
5293 Boolean success = (Boolean) sendRequest(
5294 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5295 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5296 return success;
5297 }
5298
5299 /**
Miaoa84611c2019-03-15 09:21:10 +08005300 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005301 *
Miaoa84611c2019-03-15 09:21:10 +08005302 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005303 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005304 * @hide
5305 */
5306 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005307 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005308 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005310 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 try {
Miaoa84611c2019-03-15 09:21:10 +08005312 if (phone != null) {
5313 return phone.hasMatchedTetherApnSetting();
5314 } else {
5315 return false;
5316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005317 } finally {
5318 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005319 }
Junda Liu475951f2014-11-07 16:45:03 -08005320 }
5321
5322 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005323 * Set mobile data enabled
5324 * Used by the user through settings etc to turn on/off mobile data
5325 *
5326 * @param enable {@code true} turn turn data on, else {@code false}
5327 */
5328 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005329 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5331 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332
5333 final long identity = Binder.clearCallingIdentity();
5334 try {
5335 int phoneId = mSubscriptionController.getPhoneId(subId);
5336 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5337 Phone phone = PhoneFactory.getPhone(phoneId);
5338 if (phone != null) {
5339 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005340 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005342 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343 }
5344 } finally {
5345 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005346 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005347 }
5348
5349 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005350 * Enable or disable always reporting signal strength changes from radio.
5351 *
5352 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5353 */
5354 @Override
5355 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5356 enforceModifyPermission();
5357 enforceSystemCaller();
5358
5359 final long identity = Binder.clearCallingIdentity();
5360 final Phone phone = getPhone(subId);
5361 try {
5362 if (phone != null) {
5363 if (DBG) {
5364 log("setAlwaysReportSignalStrength: subId=" + subId
5365 + " isEnable=" + isEnable);
5366 }
5367 phone.setAlwaysReportSignalStrength(isEnable);
5368 } else {
5369 loge("setAlwaysReportSignalStrength: no phone found for subId="
5370 + subId);
5371 }
5372 } finally {
5373 Binder.restoreCallingIdentity(identity);
5374 }
5375 }
5376
5377 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005378 * Get the user enabled state of Mobile Data.
5379 *
5380 * TODO: remove and use isUserDataEnabled.
5381 * This can't be removed now because some vendor codes
5382 * calls through ITelephony directly while they should
5383 * use TelephonyManager.
5384 *
5385 * @return true on enabled
5386 */
5387 @Override
5388 public boolean getDataEnabled(int subId) {
5389 return isUserDataEnabled(subId);
5390 }
5391
5392 /**
5393 * Get whether mobile data is enabled per user setting.
5394 *
5395 * There are other factors deciding whether mobile data is actually enabled, but they are
5396 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005397 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005398 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005399 *
5400 * @return {@code true} if data is enabled else {@code false}
5401 */
5402 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005403 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005404 try {
5405 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5406 null);
5407 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5409 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411
5412 final long identity = Binder.clearCallingIdentity();
5413 try {
5414 int phoneId = mSubscriptionController.getPhoneId(subId);
5415 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5416 Phone phone = PhoneFactory.getPhone(phoneId);
5417 if (phone != null) {
5418 boolean retVal = phone.isUserDataEnabled();
5419 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5420 return retVal;
5421 } else {
5422 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5423 return false;
5424 }
5425 } finally {
5426 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005427 }
5428 }
5429
5430 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005431 * Checks if the device is capable of mobile data by considering whether whether the
5432 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5433 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005434 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005435 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005436 */
5437 @Override
5438 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005439 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440
5441 final long identity = Binder.clearCallingIdentity();
5442 try {
5443 int phoneId = mSubscriptionController.getPhoneId(subId);
5444 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5445 Phone phone = PhoneFactory.getPhone(phoneId);
5446 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005447 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5449 return retVal;
5450 } else {
5451 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5452 return false;
5453 }
5454 } finally {
5455 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005456 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005457 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005458
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005459 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5460 Phone phone) {
5461 //load access rules from carrier configs, and check those as well: b/139133814
5462 SubscriptionController subController = SubscriptionController.getInstance();
5463 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5464 || subController == null) return privilegeFromSim;
5465
5466 int uid = Binder.getCallingUid();
5467 PackageManager pkgMgr = phone.getContext().getPackageManager();
5468 String[] packages = pkgMgr.getPackagesForUid(uid);
5469
5470 final long identity = Binder.clearCallingIdentity();
5471 try {
5472 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5473 SubscriptionManager subManager = (SubscriptionManager)
5474 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5475 for (String pkg : packages) {
5476 if (subManager.canManageSubscription(subInfo, pkg)) {
5477 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5478 }
5479 }
5480 return privilegeFromSim;
5481 } finally {
5482 Binder.restoreCallingIdentity(identity);
5483 }
5484 }
5485
5486 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5487 String pkgName) {
5488 //load access rules from carrier configs, and check those as well: b/139133814
5489 SubscriptionController subController = SubscriptionController.getInstance();
5490 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5491 || subController == null) return privilegeFromSim;
5492
5493 final long identity = Binder.clearCallingIdentity();
5494 try {
5495 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5496 SubscriptionManager subManager = (SubscriptionManager)
5497 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5498 return subManager.canManageSubscription(subInfo, pkgName)
5499 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5500 } finally {
5501 Binder.restoreCallingIdentity(identity);
5502 }
5503 }
5504
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005505 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005506 public int getCarrierPrivilegeStatus(int subId) {
5507 final Phone phone = getPhone(subId);
5508 if (phone == null) {
5509 loge("getCarrierPrivilegeStatus: Invalid subId");
5510 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5511 }
5512 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005513 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005514 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005515 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5516 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005517
5518 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5519 card.getCarrierPrivilegeStatusForCurrentTransaction(
5520 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005521 }
Junda Liu29340342014-07-10 15:23:27 -07005522
5523 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005524 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005525 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005526 final Phone phone = getPhone(subId);
5527 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005528 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005529 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5530 }
5531 UiccProfile profile =
5532 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5533 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005534 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005535 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5536 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005537 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005538 profile.getCarrierPrivilegeStatusForUid(
5539 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005540 }
5541
5542 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005543 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5544 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005545 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005546 }
5547
5548 int phoneId = SubscriptionManager.getPhoneId(subId);
5549 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005550 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005551 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005552 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5553 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005554 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5555 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5556 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005557 }
5558
5559 @Override
5560 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005561 if (TextUtils.isEmpty(pkgName))
5562 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005563 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5564 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5565 UiccCard card = UiccController.getInstance().getUiccCard(i);
5566 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005567 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005568 continue;
5569 }
5570
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005571 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5572 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5573 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005574 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5575 break;
5576 }
5577 }
5578
5579 return result;
Junda Liu29340342014-07-10 15:23:27 -07005580 }
Derek Tan89e89d42014-07-08 17:00:10 -07005581
5582 @Override
Junda Liue64de782015-04-16 17:19:16 -07005583 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5584 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5585 loge("phoneId " + phoneId + " is not valid.");
5586 return null;
5587 }
5588 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005589 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005590 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005591 return null ;
5592 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005593 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005594 }
5595
Amith Yamasani6e118872016-02-19 12:53:51 -08005596 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005597 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005598 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005599 List<String> privilegedPackages = new ArrayList<>();
5600 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005601 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5602 // has UICC in that slot.
5603 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005604 if (card.hasCarrierPrivilegeRules()) {
5605 if (packages == null) {
5606 // Only check packages in user 0 for now
5607 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005608 PackageManager.MATCH_DISABLED_COMPONENTS
5609 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005610 | PackageManager.GET_SIGNING_CERTIFICATES,
5611 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005612 }
5613 for (int p = packages.size() - 1; p >= 0; p--) {
5614 PackageInfo pkgInfo = packages.get(p);
5615 if (pkgInfo != null && pkgInfo.packageName != null
5616 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005617 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005618 privilegedPackages.add(pkgInfo.packageName);
5619 }
5620 }
5621 }
5622 }
5623 return privilegedPackages;
5624 }
5625
chen xuf7e9fe82019-05-09 19:31:02 -07005626 @Override
5627 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005628 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5629
5630 final long identity = Binder.clearCallingIdentity();
5631
chen xuf7e9fe82019-05-09 19:31:02 -07005632 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005633 try {
5634 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5635 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5636 }
5637 } finally {
5638 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005639 }
5640 return privilegedPackages;
5641 }
5642
Wink Savilleb564aae2014-10-23 10:18:09 -07005643 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005644 final Phone phone = getPhone(subId);
5645 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005646 if (card == null) {
5647 loge("getIccId: No UICC");
5648 return null;
5649 }
5650 String iccId = card.getIccId();
5651 if (TextUtils.isEmpty(iccId)) {
5652 loge("getIccId: ICC ID is null or empty.");
5653 return null;
5654 }
5655 return iccId;
5656 }
5657
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005658 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005659 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5660 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005661 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005662 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005663
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 final long identity = Binder.clearCallingIdentity();
5665 try {
5666 final String iccId = getIccId(subId);
5667 final Phone phone = getPhone(subId);
5668 if (phone == null) {
5669 return false;
5670 }
5671 final String subscriberId = phone.getSubscriberId();
5672
5673 if (DBG_MERGE) {
5674 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5675 + subscriberId + " to " + number);
5676 }
5677
5678 if (TextUtils.isEmpty(iccId)) {
5679 return false;
5680 }
5681
5682 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5683
5684 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5685 if (alphaTag == null) {
5686 editor.remove(alphaTagPrefKey);
5687 } else {
5688 editor.putString(alphaTagPrefKey, alphaTag);
5689 }
5690
5691 // Record both the line number and IMSI for this ICCID, since we need to
5692 // track all merged IMSIs based on line number
5693 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5694 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5695 if (number == null) {
5696 editor.remove(numberPrefKey);
5697 editor.remove(subscriberPrefKey);
5698 } else {
5699 editor.putString(numberPrefKey, number);
5700 editor.putString(subscriberPrefKey, subscriberId);
5701 }
5702
5703 editor.commit();
5704 return true;
5705 } finally {
5706 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005707 }
Derek Tan7226c842014-07-02 17:42:23 -07005708 }
5709
5710 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005711 public String getLine1NumberForDisplay(int subId, String callingPackage,
5712 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005713 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005714 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005715 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005716 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005717 return null;
5718 }
Derek Tan97ebb422014-09-05 16:55:38 -07005719
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 final long identity = Binder.clearCallingIdentity();
5721 try {
5722 String iccId = getIccId(subId);
5723 if (iccId != null) {
5724 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5725 if (DBG_MERGE) {
5726 log("getLine1NumberForDisplay returning "
5727 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5728 }
5729 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005730 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5732 return null;
5733 } finally {
5734 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005735 }
Derek Tan7226c842014-07-02 17:42:23 -07005736 }
5737
5738 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005739 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5740 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005741 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005742 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005743 return null;
5744 }
Derek Tan97ebb422014-09-05 16:55:38 -07005745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746 final long identity = Binder.clearCallingIdentity();
5747 try {
5748 String iccId = getIccId(subId);
5749 if (iccId != null) {
5750 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5751 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5752 }
5753 return null;
5754 } finally {
5755 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005756 }
Derek Tan7226c842014-07-02 17:42:23 -07005757 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005758
5759 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005760 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5761 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005762 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5763 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005765 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005766 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005767 return null;
5768 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005769
Jordan Liub49b04b2019-05-06 14:45:15 -07005770 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5771 // the process, where TelephonyManager was instantiated.
5772 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005773 final long identity = Binder.clearCallingIdentity();
5774 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005775 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 final TelephonyManager tele = TelephonyManager.from(context);
5777 final SubscriptionManager sub = SubscriptionManager.from(context);
5778
5779 // Figure out what subscribers are currently active
5780 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781
Jordan Liub49b04b2019-05-06 14:45:15 -07005782 // Only consider subs which match the current subId
5783 // This logic can be simplified. See b/131189269 for progress.
5784 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005785 activeSubscriberIds.add(tele.getSubscriberId(subId));
5786 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787
5788 // First pass, find a number override for an active subscriber
5789 String mergeNumber = null;
5790 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5791 for (String key : prefs.keySet()) {
5792 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5793 final String subscriberId = (String) prefs.get(key);
5794 if (activeSubscriberIds.contains(subscriberId)) {
5795 final String iccId = key.substring(
5796 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5797 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5798 mergeNumber = (String) prefs.get(numberKey);
5799 if (DBG_MERGE) {
5800 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5801 + " for active subscriber " + subscriberId);
5802 }
5803 if (!TextUtils.isEmpty(mergeNumber)) {
5804 break;
5805 }
5806 }
5807 }
5808 }
5809
5810 // Shortcut when no active merged subscribers
5811 if (TextUtils.isEmpty(mergeNumber)) {
5812 return null;
5813 }
5814
5815 // Second pass, find all subscribers under that line override
5816 final ArraySet<String> result = new ArraySet<>();
5817 for (String key : prefs.keySet()) {
5818 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5819 final String number = (String) prefs.get(key);
5820 if (mergeNumber.equals(number)) {
5821 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5822 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5823 final String subscriberId = (String) prefs.get(subscriberKey);
5824 if (!TextUtils.isEmpty(subscriberId)) {
5825 result.add(subscriberId);
5826 }
5827 }
5828 }
5829 }
5830
5831 final String[] resultArray = result.toArray(new String[result.size()]);
5832 Arrays.sort(resultArray);
5833 if (DBG_MERGE) {
5834 Slog.d(LOG_TAG,
5835 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5836 }
5837 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005838 } finally {
5839 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005840 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005841 }
5842
5843 @Override
zoey chen38003472019-12-13 17:16:31 +08005844 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5845 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005846
5847 final long identity = Binder.clearCallingIdentity();
5848 try {
5849 final TelephonyManager telephonyManager = mApp.getSystemService(
5850 TelephonyManager.class);
5851 String subscriberId = telephonyManager.getSubscriberId(subId);
5852 if (subscriberId == null) {
5853 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005854 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005855 + subId);
5856 }
5857 return null;
5858 }
5859
5860 final SubscriptionInfo info = SubscriptionController.getInstance()
5861 .getSubscriptionInfo(subId);
5862 final ParcelUuid groupUuid = info.getGroupUuid();
5863 // If it doesn't belong to any group, return just subscriberId of itself.
5864 if (groupUuid == null) {
5865 return new String[]{subscriberId};
5866 }
5867
5868 // Get all subscriberIds from the group.
5869 final List<String> mergedSubscriberIds = new ArrayList<>();
5870 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005871 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5872 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005873 for (SubscriptionInfo subInfo : groupInfos) {
5874 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5875 if (subscriberId != null) {
5876 mergedSubscriberIds.add(subscriberId);
5877 }
5878 }
5879
5880 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5881 } finally {
5882 Binder.restoreCallingIdentity(identity);
5883
5884 }
5885 }
5886
5887 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005888 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005889 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005890 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891
5892 final long identity = Binder.clearCallingIdentity();
5893 try {
5894 final Phone phone = getPhone(subId);
5895 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5896 } finally {
5897 Binder.restoreCallingIdentity(identity);
5898 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005899 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005900
5901 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005902 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005903 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5904 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005905 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5906 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005907
5908 final long identity = Binder.clearCallingIdentity();
5909 try {
5910 final Phone phone = getPhone(subId);
5911 if (phone == null) {
5912 return false;
5913 }
5914 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5915 cdmaNonRoamingList);
5916 } finally {
5917 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005918 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005919 }
5920
5921 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005922 @Deprecated
5923 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5924 enforceModifyPermission();
5925
5926 int returnValue = 0;
5927 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005928 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005929 if(result.exception == null) {
5930 if (result.result != null) {
5931 byte[] responseData = (byte[])(result.result);
5932 if(responseData.length > oemResp.length) {
5933 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5934 responseData.length + "bytes. Buffer Size is " +
5935 oemResp.length + "bytes.");
5936 }
5937 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5938 returnValue = responseData.length;
5939 }
5940 } else {
5941 CommandException ex = (CommandException) result.exception;
5942 returnValue = ex.getCommandError().ordinal();
5943 if(returnValue > 0) returnValue *= -1;
5944 }
5945 } catch (RuntimeException e) {
5946 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5947 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5948 if(returnValue > 0) returnValue *= -1;
5949 }
5950
5951 return returnValue;
5952 }
5953
5954 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005955 public void setRadioCapability(RadioAccessFamily[] rafs) {
5956 try {
5957 ProxyController.getInstance().setRadioCapability(rafs);
5958 } catch (RuntimeException e) {
5959 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5960 }
5961 }
5962
5963 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005964 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005965 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005966 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005967 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005968 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 final long identity = Binder.clearCallingIdentity();
5971 try {
chen xub97461a2018-10-26 14:17:57 -07005972 TelephonyPermissions
5973 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5974 mApp, phone.getSubId(), "getRadioAccessFamily");
5975 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 } finally {
5977 Binder.restoreCallingIdentity(identity);
5978 }
chen xub97461a2018-10-26 14:17:57 -07005979 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005980 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005981
5982 @Override
5983 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005984 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005985 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986
5987 final long identity = Binder.clearCallingIdentity();
5988 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005989 ImsManager.getInstance(defaultPhone.getContext(),
5990 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 } finally {
5992 Binder.restoreCallingIdentity(identity);
5993 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005994 }
5995
5996 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005997 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005998 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005999 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6000 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006001 return false;
6002 }
Svet Ganovb320e182015-04-16 12:30:10 -07006003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 final long identity = Binder.clearCallingIdentity();
6005 try {
6006 // Check the user preference and the system-level IMS setting. Even if the user has
6007 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6008 // In the long run, we may instead need to check if there exists a connection service
6009 // which can support video calling.
6010 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006011 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 return imsManager.isVtEnabledByPlatform()
6013 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6014 && imsManager.isVtEnabledByUser();
6015 } finally {
6016 Binder.restoreCallingIdentity(identity);
6017 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006018 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006019
Andrew Leea1239f22015-03-02 17:44:07 -08006020 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006021 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6022 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006023 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006024 mApp, subId, callingPackage, callingFeatureId,
6025 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006026 return false;
6027 }
6028
6029 final long identity = Binder.clearCallingIdentity();
6030 try {
6031 CarrierConfigManager configManager =
6032 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006033 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6035 } finally {
6036 Binder.restoreCallingIdentity(identity);
6037 }
Andrew Leea1239f22015-03-02 17:44:07 -08006038 }
6039
6040 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006041 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006043 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 return false;
6045 }
6046
6047 final long identity = Binder.clearCallingIdentity();
6048 try {
6049 CarrierConfigManager configManager =
6050 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006051 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6053 } finally {
6054 Binder.restoreCallingIdentity(identity);
6055 }
Andrew Leea1239f22015-03-02 17:44:07 -08006056 }
6057
Andrew Lee9431b832015-03-09 18:46:45 -07006058 @Override
6059 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006060 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006061 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006062 }
6063
6064 @Override
6065 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066 final long identity = Binder.clearCallingIdentity();
6067 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006068 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069 } finally {
6070 Binder.restoreCallingIdentity(identity);
6071 }
Andrew Lee9431b832015-03-09 18:46:45 -07006072 }
6073
Hall Liuf6668912018-10-31 17:05:23 -07006074 /**
6075 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6076 * support for the feature and device firmware support.
6077 *
6078 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6079 */
6080 @Override
6081 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006083 final Phone phone = getPhone(subscriptionId);
6084 if (phone == null) {
6085 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6086 return false;
6087 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006089 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6091 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006092 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093 return isCarrierSupported && isDeviceSupported;
6094 } finally {
6095 Binder.restoreCallingIdentity(identity);
6096 }
Hall Liu98187582018-01-22 19:15:32 -08006097 }
6098
Hall Liuf6668912018-10-31 17:05:23 -07006099 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006100 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6101 * RTT setting, will return true if the device and carrier both support RTT.
6102 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006103 */
6104 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006105 final long identity = Binder.clearCallingIdentity();
6106 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006107 boolean isRttSupported = isRttSupported(subscriptionId);
6108 boolean isUserRttSettingOn = Settings.Secure.getInt(
6109 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6110 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6111 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6112 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 } finally {
6114 Binder.restoreCallingIdentity(identity);
6115 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006116 }
6117
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006118 @Deprecated
6119 @Override
6120 public String getDeviceId(String callingPackage) {
6121 return getDeviceIdWithFeature(callingPackage, null);
6122 }
6123
Sanket Padawe7310cc72015-01-14 09:53:20 -08006124 /**
6125 * Returns the unique device ID of phone, for example, the IMEI for
6126 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6127 *
6128 * <p>Requires Permission:
6129 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6130 */
6131 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006132 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006133 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006134 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006135 return null;
6136 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006137 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006138 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006139 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006140 return null;
6141 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142
6143 final long identity = Binder.clearCallingIdentity();
6144 try {
6145 return phone.getDeviceId();
6146 } finally {
6147 Binder.restoreCallingIdentity(identity);
6148 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006149 }
6150
Ping Sunc67b7c22016-03-02 19:16:45 +08006151 /**
6152 * {@hide}
6153 * Returns the IMS Registration Status on a particular subid
6154 *
6155 * @param subId
6156 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006157 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006158 Phone phone = getPhone(subId);
6159 if (phone != null) {
6160 return phone.isImsRegistered();
6161 } else {
6162 return false;
6163 }
6164 }
6165
Santos Cordon7a1885b2015-02-03 11:15:19 -08006166 @Override
6167 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 final long identity = Binder.clearCallingIdentity();
6169 try {
6170 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6171 } finally {
6172 Binder.restoreCallingIdentity(identity);
6173 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006174 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006175
Tyler Gunnf70ed162019-04-03 15:28:53 -07006176 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006177 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006178 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006180 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006181 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6182 }
6183 final long identity = Binder.clearCallingIdentity();
6184 try {
6185 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6186 } finally {
6187 Binder.restoreCallingIdentity(identity);
6188 }
6189 }
6190
6191 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006192 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6193 final long identity = Binder.clearCallingIdentity();
6194 try {
6195 Phone phone = getPhone(subscriptionId);
6196 if (phone == null) {
6197 return null;
6198 }
6199 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6200 } finally {
6201 Binder.restoreCallingIdentity(identity);
6202 }
6203 }
6204
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006205 /**
6206 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006207 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006208 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006209 final long identity = Binder.clearCallingIdentity();
6210 try {
6211 Phone phone = getPhone(subId);
6212 if (phone != null) {
6213 return phone.isWifiCallingEnabled();
6214 } else {
6215 return false;
6216 }
6217 } finally {
6218 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006219 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006220 }
6221
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006222 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006223 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006224 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006225 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226 final long identity = Binder.clearCallingIdentity();
6227 try {
6228 Phone phone = getPhone(subId);
6229 if (phone != null) {
6230 return phone.isVideoEnabled();
6231 } else {
6232 return false;
6233 }
6234 } finally {
6235 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006236 }
6237 }
6238
6239 /**
6240 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6241 * defined in {@link ImsRegistrationImplBase}.
6242 */
6243 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006244 final long identity = Binder.clearCallingIdentity();
6245 try {
6246 Phone phone = getPhone(subId);
6247 if (phone != null) {
6248 return phone.getImsRegistrationTech();
6249 } else {
6250 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6251 }
6252 } finally {
6253 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006254 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006255 }
6256
Stuart Scott8eef64f2015-04-08 15:13:54 -07006257 @Override
6258 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006259 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006260 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6261 return;
6262 }
6263
Svet Ganovcc087f82015-05-12 20:35:54 -07006264 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006265
Svet Ganovcc087f82015-05-12 20:35:54 -07006266 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006267 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6268 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006269 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006270 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006271 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006272 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6273 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006274 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006275 // There has been issues when Sms raw table somehow stores orphan
6276 // fragments. They lead to garbled message when new fragments come
6277 // in and combined with those stale ones. In case this happens again,
6278 // user can reset all network settings which will clean up this table.
6279 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006280 // Clean up IMS settings as well here.
6281 int slotId = getSlotIndex(subId);
6282 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6283 ImsManager.getInstance(mApp, slotId).factoryReset();
6284 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006285
6286 // Erase modem config if erase modem on network setting is enabled.
6287 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6288 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6289 if (configValue != null && Boolean.parseBoolean(configValue)) {
6290 sendEraseModemConfig(getDefaultPhone());
6291 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006292 } finally {
6293 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006294 }
6295 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006296
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006297 private void cleanUpSmsRawTable(Context context) {
6298 ContentResolver resolver = context.getContentResolver();
6299 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6300 resolver.delete(uri, null, null);
6301 }
6302
Narayan Kamath1c496c22015-04-16 14:40:19 +01006303 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006304 public String getSimLocaleForSubscriber(int subId) {
6305 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6306 final Phone phone = getPhone(subId);
6307 if (phone == null) {
6308 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006309 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 final long identity = Binder.clearCallingIdentity();
6312 try {
chen xu5d3637b2019-01-21 23:31:38 -08006313 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006314 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006315 if (info == null) {
6316 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6317 return null;
6318 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319 // Try and fetch the locale from the carrier properties or from the SIM language
6320 // preferences (EF-PL and EF-LI)...
6321 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006322 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006323 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6324 if (localeFromDefaultSim != null) {
6325 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6326 if (DBG) log("Using locale from subId: " + subId + " locale: "
6327 + localeFromDefaultSim);
6328 return localeFromDefaultSim.toLanguageTag();
6329 } else {
6330 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006331 }
6332 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334 // The SIM language preferences only store a language (e.g. fr = French), not an
6335 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6336 // the SIM and carrier preferences does not include a country we add the country
6337 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006338 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006339 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006340 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006341 return mccLocale.toLanguageTag();
6342 }
6343
6344 if (DBG) log("No locale found - returning null");
6345 return null;
6346 } finally {
6347 Binder.restoreCallingIdentity(identity);
6348 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006349 }
6350
6351 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006352 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6353 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006354 }
6355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356 /**
6357 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6358 */
6359 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006360 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6361 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006362 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006363
Chenjie Yu1ba97252018-01-11 18:16:20 -08006364 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006365 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006366
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006367 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006368 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6369 * representing the state of the modem.
6370 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006371 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6372 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006373 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006374 */
6375 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006376 public void requestModemActivityInfo(ResultReceiver result) {
6377 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006378 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379
6380 final long identity = Binder.clearCallingIdentity();
6381 try {
6382 ModemActivityInfo ret = null;
6383 synchronized (mLastModemActivityInfo) {
6384 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6385 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006386 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006387 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006389 int[] txTimeMs = info.getTransmitTimeMillis();
6390 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006391 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006392 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006393 }
6394 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006395 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6396 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397 mLastModemActivityInfo.setIdleTimeMillis(
6398 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006399 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6400 mLastModemActivityInfo.setReceiveTimeMillis(
6401 info.getReceiveTimeMillis() + mLastModemActivityInfo
6402 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006403 }
Chen Xud78231e2019-09-10 18:49:52 -07006404
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6406 mLastModemActivityInfo.getSleepTimeMillis(),
6407 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006408 mLastModemActivityInfo.getTransmitTimeMillis(),
6409 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 Bundle bundle = new Bundle();
6412 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6413 result.send(0, bundle);
6414 } finally {
6415 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006416 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006417 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006418
Siddharth Rayb8114062018-06-17 15:02:38 -07006419 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6420 // less than total activity duration.
6421 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6422 if (info == null) {
6423 return false;
6424 }
6425 int activityDurationMs =
6426 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6427 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006428 int[] txTimeMs = info.getTransmitTimeMillis();
6429 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6430 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006431 }
6432 return (info.isValid()
6433 && (info.getSleepTimeMillis() <= activityDurationMs)
6434 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006435 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006436 && (totalTxTimeMs <= activityDurationMs));
6437 }
6438
Jack Yu85bd38a2015-11-09 11:34:32 -08006439 /**
6440 * {@hide}
6441 * Returns the service state information on specified subscription.
6442 */
6443 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006444 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6445 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006446 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006447 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006448 return null;
6449 }
6450
Hall Liuf19c44f2018-11-27 14:38:17 -08006451 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6452 LocationAccessPolicy.checkLocationPermission(mApp,
6453 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6454 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006455 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006456 .setCallingPid(Binder.getCallingPid())
6457 .setCallingUid(Binder.getCallingUid())
6458 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006459 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006460 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6461 .build());
6462
6463 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6464 LocationAccessPolicy.checkLocationPermission(mApp,
6465 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6466 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006467 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006468 .setCallingPid(Binder.getCallingPid())
6469 .setCallingUid(Binder.getCallingUid())
6470 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006471 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006472 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6473 .build());
6474 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6475 boolean hasFinePermission =
6476 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6477 boolean hasCoarsePermission =
6478 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 final long identity = Binder.clearCallingIdentity();
6481 try {
6482 final Phone phone = getPhone(subId);
6483 if (phone == null) {
6484 return null;
6485 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006486
Hall Liuf19c44f2018-11-27 14:38:17 -08006487 ServiceState ss = phone.getServiceState();
6488
6489 // Scrub out the location info in ServiceState depending on what level of access
6490 // the caller has.
6491 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006492 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6493 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006494 } finally {
6495 Binder.restoreCallingIdentity(identity);
6496 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006497 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006498
6499 /**
6500 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6501 *
6502 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6503 * voicemail ringtone.
6504 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6505 * PhoneAccount.
6506 */
6507 @Override
6508 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006509 final long identity = Binder.clearCallingIdentity();
6510 try {
6511 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6512 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006513 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006515
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006516 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6517 } finally {
6518 Binder.restoreCallingIdentity(identity);
6519 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006520 }
6521
6522 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006523 * Sets the per-account voicemail ringtone.
6524 *
6525 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6526 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6527 *
6528 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6529 * voicemail ringtone.
6530 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6531 * PhoneAccount.
6532 */
6533 @Override
6534 public void setVoicemailRingtoneUri(String callingPackage,
6535 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006536 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006537 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006538 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6539 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6541 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6542 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544
6545 final long identity = Binder.clearCallingIdentity();
6546 try {
6547 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6548 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006549 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550 }
6551 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6552 } finally {
6553 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006554 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006555 }
6556
6557 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006558 * Returns whether vibration is set for voicemail notification in Phone settings.
6559 *
6560 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6561 * voicemail vibration setting.
6562 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6563 */
6564 @Override
6565 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006566 final long identity = Binder.clearCallingIdentity();
6567 try {
6568 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6569 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006570 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006571 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6574 } finally {
6575 Binder.restoreCallingIdentity(identity);
6576 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006577 }
6578
Youhan Wange64578a2016-05-02 15:32:42 -07006579 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006580 * Sets the per-account voicemail vibration.
6581 *
6582 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6583 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6584 *
6585 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6586 * voicemail vibration setting.
6587 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6588 * specific PhoneAccount.
6589 */
6590 @Override
6591 public void setVoicemailVibrationEnabled(String callingPackage,
6592 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006593 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006595 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6596 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6598 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6599 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006600 }
6601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 final long identity = Binder.clearCallingIdentity();
6603 try {
6604 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6605 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006606 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607 }
6608 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6609 } finally {
6610 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006611 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006612 }
6613
6614 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006615 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6616 *
6617 * @throws SecurityException if the caller does not have the required permission
6618 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006619 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006620 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006621 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006622 }
6623
6624 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006625 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6626 * permission.
6627 *
6628 * @throws SecurityException if the caller does not have the required permission
6629 */
6630 private void enforceSendSmsPermission() {
6631 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6632 }
6633
6634 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006635 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006636 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006637 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006638 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006639 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006640 final long identity = Binder.clearCallingIdentity();
6641 try {
6642 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006643 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006644 if (componentName == null) {
6645 throw new SecurityException(
6646 "Caller not current active visual voicemail package[null]");
6647 }
6648 String vvmPackage = componentName.getPackageName();
6649 if (!callingPackage.equals(vvmPackage)) {
6650 throw new SecurityException("Caller not current active visual voicemail package["
6651 + vvmPackage + "]");
6652 }
6653 } finally {
6654 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006655 }
6656 }
6657
6658 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006659 * Return the application ID for the app type.
6660 *
6661 * @param subId the subscription ID that this request applies to.
6662 * @param appType the uicc app type.
6663 * @return Application ID for specificied app type, or null if no uicc.
6664 */
6665 @Override
6666 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006667 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006668 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669
6670 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006671 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006672 if (phone == null) {
6673 return null;
6674 }
6675 String aid = null;
6676 try {
6677 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6678 .getApplicationByType(appType).getAid();
6679 } catch (Exception e) {
6680 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6681 }
6682 return aid;
6683 } finally {
6684 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006685 }
Youhan Wange64578a2016-05-02 15:32:42 -07006686 }
6687
Youhan Wang4001d252016-05-11 10:29:41 -07006688 /**
6689 * Return the Electronic Serial Number.
6690 *
6691 * @param subId the subscription ID that this request applies to.
6692 * @return ESN or null if error.
6693 */
6694 @Override
6695 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006696 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006697 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006698
6699 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006700 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701 if (phone == null) {
6702 return null;
6703 }
6704 String esn = null;
6705 try {
6706 esn = phone.getEsn();
6707 } catch (Exception e) {
6708 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6709 }
6710 return esn;
6711 } finally {
6712 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006713 }
Youhan Wang4001d252016-05-11 10:29:41 -07006714 }
6715
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006716 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006717 * Return the Preferred Roaming List Version.
6718 *
6719 * @param subId the subscription ID that this request applies to.
6720 * @return PRLVersion or null if error.
6721 */
6722 @Override
6723 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006724 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006725 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006726
6727 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006728 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006729 if (phone == null) {
6730 return null;
6731 }
6732 String cdmaPrlVersion = null;
6733 try {
6734 cdmaPrlVersion = phone.getCdmaPrlVersion();
6735 } catch (Exception e) {
6736 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6737 }
6738 return cdmaPrlVersion;
6739 } finally {
6740 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006741 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006742 }
6743
6744 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006745 * Get snapshot of Telephony histograms
6746 * @return List of Telephony histograms
6747 * @hide
6748 */
6749 @Override
6750 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6752 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006753
6754 final long identity = Binder.clearCallingIdentity();
6755 try {
6756 return RIL.getTelephonyRILTimingHistograms();
6757 } finally {
6758 Binder.restoreCallingIdentity(identity);
6759 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006760 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006761
6762 /**
6763 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006764 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6765 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006766 * Require system privileges. In the future we may add this to carrier APIs.
6767 *
Michele Berionne482f8202018-11-27 18:57:59 -08006768 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006769 */
6770 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006771 @TelephonyManager.SetCarrierRestrictionResult
6772 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006773 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006774 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006775
Michele Berionne482f8202018-11-27 18:57:59 -08006776 if (carrierRestrictionRules == null) {
6777 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006778 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006779
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780 final long identity = Binder.clearCallingIdentity();
6781 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006782 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006783 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006787 }
6788
6789 /**
6790 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006791 * Get the allowed carrier list and the excluded carrier list, including the priority between
6792 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006793 * Require system privileges. In the future we may add this to carrier APIs.
6794 *
Michele Berionne482f8202018-11-27 18:57:59 -08006795 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006796 */
6797 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006798 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006799 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006800 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801
6802 final long identity = Binder.clearCallingIdentity();
6803 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006804 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6805 if (response instanceof CarrierRestrictionRules) {
6806 return (CarrierRestrictionRules) response;
6807 }
6808 // Response is an Exception of some kind,
6809 // which is signalled to the user as a NULL retval
6810 return null;
6811 } catch (Exception e) {
6812 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6813 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006814 } finally {
6815 Binder.restoreCallingIdentity(identity);
6816 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006817 }
6818
fionaxu59545b42016-05-25 15:53:37 -07006819 /**
6820 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6821 * @param subId the subscription ID that this action applies to.
6822 * @param enabled control enable or disable metered apns.
6823 * {@hide}
6824 */
6825 @Override
6826 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6827 enforceModifyPermission();
6828 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829
6830 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006831 if (phone == null) {
6832 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6833 return;
6834 }
6835 try {
6836 phone.carrierActionSetMeteredApnsEnabled(enabled);
6837 } catch (Exception e) {
6838 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006839 } finally {
6840 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006841 }
6842 }
6843
6844 /**
6845 * Action set from carrier signalling broadcast receivers to enable/disable radio
6846 * @param subId the subscription ID that this action applies to.
6847 * @param enabled control enable or disable radio.
6848 * {@hide}
6849 */
6850 @Override
6851 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6852 enforceModifyPermission();
6853 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006854
6855 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006856 if (phone == null) {
6857 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6858 return;
6859 }
6860 try {
6861 phone.carrierActionSetRadioEnabled(enabled);
6862 } catch (Exception e) {
6863 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006864 } finally {
6865 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006866 }
6867 }
6868
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006869 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006870 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6871 * network status based on which carrier apps could apply actions accordingly,
6872 * enable/disable default url handler for example.
6873 *
6874 * @param subId the subscription ID that this action applies to.
6875 * @param report control start/stop reporting the default network status.
6876 * {@hide}
6877 */
6878 @Override
6879 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6880 enforceModifyPermission();
6881 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006882
6883 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006884 if (phone == null) {
6885 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6886 return;
6887 }
6888 try {
6889 phone.carrierActionReportDefaultNetworkStatus(report);
6890 } catch (Exception e) {
6891 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006892 } finally {
6893 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006894 }
6895 }
6896
6897 /**
fionaxud9622282017-07-17 17:51:30 -07006898 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6899 * @param subId the subscription ID that this action applies to.
6900 * {@hide}
6901 */
6902 @Override
6903 public void carrierActionResetAll(int subId) {
6904 enforceModifyPermission();
6905 final Phone phone = getPhone(subId);
6906 if (phone == null) {
6907 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6908 return;
6909 }
6910 try {
6911 phone.carrierActionResetAll();
6912 } catch (Exception e) {
6913 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6914 }
6915 }
6916
6917 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006918 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6919 * bug report is being generated.
6920 */
6921 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006922 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006923 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6924 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006925 writer.println("Permission Denial: can't dump Phone from pid="
6926 + Binder.getCallingPid()
6927 + ", uid=" + Binder.getCallingUid()
6928 + "without permission "
6929 + android.Manifest.permission.DUMP);
6930 return;
6931 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006932 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006933 }
Jack Yueb89b242016-06-22 13:27:47 -07006934
Brad Ebingerdac2f002018-04-03 15:17:52 -07006935 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006936 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6937 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6938 @NonNull String[] args) {
6939 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6940 this, in.getFileDescriptor(), out.getFileDescriptor(),
6941 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006942 }
6943
Jack Yueb89b242016-06-22 13:27:47 -07006944 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006945 * Get aggregated video call data usage since boot.
6946 *
6947 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6948 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006949 * {@hide}
6950 */
6951 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006952 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006953 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6954 null);
6955
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006956 final long identity = Binder.clearCallingIdentity();
6957 try {
6958 // NetworkStatsService keeps tracking the active network interface and identity. It
6959 // records the delta with the corresponding network identity.
6960 // We just return the total video call data usage snapshot since boot.
6961 Phone phone = getPhone(subId);
6962 if (phone != null) {
6963 return phone.getVtDataUsage(perUidStats);
6964 }
6965 return null;
6966 } finally {
6967 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006968 }
Jack Yueb89b242016-06-22 13:27:47 -07006969 }
Jack Yu75ab2952016-07-08 14:29:33 -07006970
6971 /**
6972 * Policy control of data connection. Usually used when data limit is passed.
6973 * @param enabled True if enabling the data, otherwise disabling.
6974 * @param subId Subscription index
6975 * {@hide}
6976 */
6977 @Override
6978 public void setPolicyDataEnabled(boolean enabled, int subId) {
6979 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006980
6981 final long identity = Binder.clearCallingIdentity();
6982 try {
6983 Phone phone = getPhone(subId);
6984 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006985 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986 }
6987 } finally {
6988 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006989 }
6990 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006991
6992 /**
6993 * Get Client request stats
6994 * @return List of Client Request Stats
6995 * @hide
6996 */
6997 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006998 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6999 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007000 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007001 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007002 return null;
7003 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007004 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007005
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007006 final long identity = Binder.clearCallingIdentity();
7007 try {
7008 if (phone != null) {
7009 return phone.getClientRequestStats();
7010 }
7011
7012 return null;
7013 } finally {
7014 Binder.restoreCallingIdentity(identity);
7015 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007016 }
7017
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007018 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007019 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007020 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007021 }
Jack Yueb4124c2017-02-16 15:32:43 -08007022
7023 /**
Grace Chen70990072017-03-24 17:21:30 -07007024 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007025 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007026 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007027 * @param state State of SIM (power down, power up, pass through)
7028 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7029 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7030 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007031 *
7032 **/
7033 @Override
Grace Chen70990072017-03-24 17:21:30 -07007034 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007035 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007036 Phone phone = PhoneFactory.getPhone(slotIndex);
7037
vagdeviaf9a5b92018-08-15 16:01:53 -07007038 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7039
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 final long identity = Binder.clearCallingIdentity();
7041 try {
7042 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007043 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044 }
7045 } finally {
7046 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007047 }
7048 }
Shuo Qiandd210312017-04-12 22:11:33 +00007049
Tyler Gunn65d45c22017-06-05 11:22:26 -07007050 private boolean isUssdApiAllowed(int subId) {
7051 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007052 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007053 if (configManager == null) {
7054 return false;
7055 }
7056 PersistableBundle pb = configManager.getConfigForSubId(subId);
7057 if (pb == null) {
7058 return false;
7059 }
7060 return pb.getBoolean(
7061 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7062 }
7063
Shuo Qiandd210312017-04-12 22:11:33 +00007064 /**
7065 * Check if phone is in emergency callback mode
7066 * @return true if phone is in emergency callback mode
7067 * @param subId sub id
7068 */
goneil9c5f4872017-12-05 14:07:56 -08007069 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007070 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007071 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007072 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073
7074 final long identity = Binder.clearCallingIdentity();
7075 try {
7076 if (phone != null) {
7077 return phone.isInEcm();
7078 } else {
7079 return false;
7080 }
7081 } finally {
7082 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007083 }
7084 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007085
7086 /**
7087 * Get the current signal strength information for the given subscription.
7088 * Because this information is not updated when the device is in a low power state
7089 * it should not be relied-upon to be current.
7090 * @param subId Subscription index
7091 * @return the most recent cached signal strength info from the modem
7092 */
7093 @Override
7094 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095 final long identity = Binder.clearCallingIdentity();
7096 try {
7097 Phone p = getPhone(subId);
7098 if (p == null) {
7099 return null;
7100 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007102 return p.getSignalStrength();
7103 } finally {
7104 Binder.restoreCallingIdentity(identity);
7105 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007106 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007107
Pengquan Meng77b7f132018-08-22 14:49:57 -07007108 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007109 * Get the current modem radio state for the given slot.
7110 * @param slotIndex slot index.
7111 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007112 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007113 * @return the current radio power state from the modem
7114 */
7115 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007116 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007117 Phone phone = PhoneFactory.getPhone(slotIndex);
7118 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7120 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007121 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7122 }
7123
7124 final long identity = Binder.clearCallingIdentity();
7125 try {
7126 return phone.getRadioPowerState();
7127 } finally {
7128 Binder.restoreCallingIdentity(identity);
7129 }
7130 }
7131 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7132 }
7133
7134 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007135 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7136 *
7137 * <p>Requires one of the following permissions:
7138 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7139 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7140 * privileges.
7141 *
7142 * @param subId subscription id
7143 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7144 * {@code false}.
7145 */
7146 @Override
7147 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007148 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7149 null /* message */);
7150
Pengquan Menga1bb6272018-09-06 09:59:22 -07007151 boolean isEnabled = false;
7152 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007153 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007154 Phone phone = getPhone(subId);
7155 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007156 } catch (Exception e) {
7157 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7158 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007159 } finally {
7160 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007161 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007162 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007163 }
7164
7165
7166 /**
7167 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7168 *
7169 * <p> Requires permission:
7170 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7171 * privileges.
7172 *
7173 * @param subId subscription id
7174 * @param isEnabled {@code true} means enable, {@code false} means disable.
7175 */
7176 @Override
7177 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007178 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7179 mApp, subId, "setDataRoamingEnabled");
7180
Pengquan Menga1bb6272018-09-06 09:59:22 -07007181 final long identity = Binder.clearCallingIdentity();
7182 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007183 Phone phone = getPhone(subId);
7184 if (phone != null) {
7185 phone.setDataRoamingEnabled(isEnabled);
7186 }
7187 } finally {
7188 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007189 }
7190 }
7191
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007192 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007193 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007194 TelephonyPermissions
7195 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007196 mApp, subId, "isManualNetworkSelectionAllowed");
7197
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007198 boolean isAllowed = true;
7199 final long identity = Binder.clearCallingIdentity();
7200 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007201 Phone phone = getPhone(subId);
7202 if (phone != null) {
7203 isAllowed = phone.isCspPlmnEnabled();
7204 }
7205 } finally {
7206 Binder.restoreCallingIdentity(identity);
7207 }
7208 return isAllowed;
7209 }
7210
7211 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007212 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007213 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007214 try {
7215 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007216 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007217 } catch (SecurityException e) {
7218 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7219 // has carrier privileges on an active UICC
7220 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7221 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007222 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007223 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007224 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007225
7226 final long identity = Binder.clearCallingIdentity();
7227 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007228 UiccController uiccController = UiccController.getInstance();
7229 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007230 if (hasReadPermission) {
7231 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007232 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007233
7234 // Remove private info if the caller doesn't have access
7235 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7236 for (UiccCardInfo cardInfo : cardInfos) {
7237 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7238 // is available
7239 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7240 if (card == null || card.getUiccProfile() == null) {
7241 // assume no access if the card or profile is unavailable
7242 filteredInfos.add(cardInfo.getUnprivileged());
7243 continue;
7244 }
7245 UiccProfile profile = card.getUiccProfile();
7246 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7247 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7248 filteredInfos.add(cardInfo);
7249 } else {
7250 filteredInfos.add(cardInfo.getUnprivileged());
7251 }
7252 }
7253 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007254 } finally {
7255 Binder.restoreCallingIdentity(identity);
7256 }
7257 }
7258
7259 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007260 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007261 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007263 final long identity = Binder.clearCallingIdentity();
7264 try {
7265 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7266 if (slots == null) {
7267 Rlog.i(LOG_TAG, "slots is null.");
7268 return null;
7269 }
7270
7271 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7272 for (int i = 0; i < slots.length; i++) {
7273 UiccSlot slot = slots[i];
7274 if (slot == null) {
7275 continue;
7276 }
7277
Jordan Liu7be7e652019-05-06 18:55:02 +00007278 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007279 UiccCard card = slot.getUiccCard();
7280 if (card != null) {
7281 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007282 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007283 cardId = slot.getEid();
7284 if (TextUtils.isEmpty(cardId)) {
7285 cardId = slot.getIccId();
7286 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007287 }
7288
Jordan Liu857451f2019-05-09 16:35:35 -07007289 if (cardId != null) {
7290 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7291 // if cardId is an EID, it's all digits so this is fine
7292 cardId = IccUtils.stripTrailingFs(cardId);
7293 }
7294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007295 int cardState = 0;
7296 switch (slot.getCardState()) {
7297 case CARDSTATE_ABSENT:
7298 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7299 break;
7300 case CARDSTATE_PRESENT:
7301 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7302 break;
7303 case CARDSTATE_ERROR:
7304 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7305 break;
7306 case CARDSTATE_RESTRICTED:
7307 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7308 break;
7309 default:
7310 break;
7311
7312 }
7313
7314 infos[i] = new UiccSlotInfo(
7315 slot.isActive(),
7316 slot.isEuicc(),
7317 cardId,
7318 cardState,
7319 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007320 slot.isExtendedApduSupported(),
7321 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007322 }
7323 return infos;
7324 } finally {
7325 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007326 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007327 }
7328
7329 @Override
7330 public boolean switchSlots(int[] physicalSlots) {
7331 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007332
7333 final long identity = Binder.clearCallingIdentity();
7334 try {
7335 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7336 } finally {
7337 Binder.restoreCallingIdentity(identity);
7338 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007339 }
Jack Yu4c988042018-02-27 15:30:01 -08007340
7341 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007342 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007343 final long identity = Binder.clearCallingIdentity();
7344 try {
7345 return UiccController.getInstance().getCardIdForDefaultEuicc();
7346 } finally {
7347 Binder.restoreCallingIdentity(identity);
7348 }
7349 }
7350
7351 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007352 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7353 enforceModifyPermission();
7354 final Phone phone = getPhone(subId);
7355 if (phone == null) {
7356 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7357 return;
7358 }
7359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360 final long identity = Binder.clearCallingIdentity();
7361 try {
7362 phone.setRadioIndicationUpdateMode(filters, mode);
7363 } finally {
7364 Binder.restoreCallingIdentity(identity);
7365 }
Jack Yu4c988042018-02-27 15:30:01 -08007366 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007367
7368 /**
goneil47ffb6e2018-04-06 15:40:58 -07007369 * A test API to reload the UICC profile.
7370 *
7371 * <p>Requires that the calling app has permission
7372 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7373 * @hide
7374 */
7375 @Override
7376 public void refreshUiccProfile(int subId) {
7377 enforceModifyPermission();
7378
7379 final long identity = Binder.clearCallingIdentity();
7380 try {
7381 Phone phone = getPhone(subId);
7382 if (phone == null) {
7383 return;
7384 }
7385 UiccCard uiccCard = phone.getUiccCard();
7386 if (uiccCard == null) {
7387 return;
7388 }
7389 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7390 if (uiccProfile == null) {
7391 return;
7392 }
7393 uiccProfile.refresh();
7394 } finally {
7395 Binder.restoreCallingIdentity(identity);
7396 }
7397 }
7398
7399 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007400 * Returns false if the mobile data is disabled by default, otherwise return true.
7401 */
7402 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007403 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007404 }
7405
7406 /**
7407 * Returns true if the data roaming is enabled by default, i.e the system property
7408 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7409 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7410 */
7411 private boolean getDefaultDataRoamingEnabled(int subId) {
7412 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007413 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007414 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007415 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7416 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7417 return isDataRoamingEnabled;
7418 }
7419
7420 /**
7421 * Returns the default network type for the given {@code subId}, if the default network type is
7422 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7423 */
7424 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007425 List<Integer> list = TelephonyProperties.default_network();
7426 int phoneId = mSubscriptionController.getPhoneId(subId);
7427 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7428 return list.get(phoneId);
7429 }
7430 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007431 }
fionaxua13278b2018-03-21 00:08:13 -07007432
7433 @Override
7434 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007435 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007436 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437
7438 final long identity = Binder.clearCallingIdentity();
7439 try {
7440 final Phone phone = getPhone(subId);
7441 if (phone == null) {
7442 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7443 return;
7444 }
chen xueaba88a2019-03-15 13:15:10 -07007445 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7446 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 } finally {
7448 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007449 }
fionaxua13278b2018-03-21 00:08:13 -07007450 }
7451
7452 @Override
7453 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007454 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007455
7456 final long identity = Binder.clearCallingIdentity();
7457 try {
7458 final Phone phone = getPhone(subId);
7459 if (phone == null) {
7460 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7461 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7462 }
7463 return phone.getCarrierIdListVersion();
7464 } finally {
7465 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007466 }
fionaxua13278b2018-03-21 00:08:13 -07007467 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007468
7469 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007470 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7471 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007473 mApp, subId, callingPackage, callingFeatureId,
7474 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007475 return -1;
7476 }
7477
7478 final long identity = Binder.clearCallingIdentity();
7479 try {
7480 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7481 } finally {
7482 Binder.restoreCallingIdentity(identity);
7483 }
7484 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007485
7486 @Override
7487 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007488 TelephonyPermissions
7489 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007490 mApp, subId, "getCdmaRoamingMode");
7491
7492 final long identity = Binder.clearCallingIdentity();
7493 try {
7494 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7495 } finally {
7496 Binder.restoreCallingIdentity(identity);
7497 }
7498 }
7499
7500 @Override
7501 public boolean setCdmaRoamingMode(int subId, int mode) {
7502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7503 mApp, subId, "setCdmaRoamingMode");
7504
7505 final long identity = Binder.clearCallingIdentity();
7506 try {
7507 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7508 } finally {
7509 Binder.restoreCallingIdentity(identity);
7510 }
7511 }
7512
7513 @Override
7514 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7516 mApp, subId, "setCdmaSubscriptionMode");
7517
7518 final long identity = Binder.clearCallingIdentity();
7519 try {
7520 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7521 } finally {
7522 Binder.restoreCallingIdentity(identity);
7523 }
7524 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007525
sqianc5eccab2018-10-19 18:46:41 -07007526 @Override
sqian8c685422019-02-22 15:55:18 -08007527 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007528 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007530 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7531 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007532 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7533 }
7534 final long identity = Binder.clearCallingIdentity();
7535 try {
sqian854d44b2018-12-12 16:48:18 -08007536 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7537 for (Phone phone: PhoneFactory.getPhones()) {
7538 if (phone.getEmergencyNumberTracker() != null
7539 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7540 emergencyNumberListInternal.put(
7541 phone.getSubId(),
7542 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7543 }
sqian11b7a0e2018-12-05 18:48:28 -08007544 }
sqian854d44b2018-12-12 16:48:18 -08007545 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007546 } finally {
7547 Binder.restoreCallingIdentity(identity);
7548 }
sqianc5eccab2018-10-19 18:46:41 -07007549 }
7550
7551 @Override
sqian8c685422019-02-22 15:55:18 -08007552 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007553 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007554 if (!exactMatch) {
7555 TelephonyPermissions
7556 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007557 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007558 }
7559 final long identity = Binder.clearCallingIdentity();
7560 try {
sqian854d44b2018-12-12 16:48:18 -08007561 for (Phone phone: PhoneFactory.getPhones()) {
7562 if (phone.getEmergencyNumberTracker() != null
7563 && phone.getEmergencyNumberTracker() != null) {
7564 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7565 number, exactMatch)) {
7566 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007567 }
7568 }
sqian11b7a0e2018-12-05 18:48:28 -08007569 }
7570 return false;
7571 } finally {
7572 Binder.restoreCallingIdentity(identity);
7573 }
7574 }
7575
sqianf4ca7ed2019-01-15 18:32:07 -08007576 /**
7577 * Update emergency number list for test mode.
7578 */
7579 @Override
7580 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7581 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7582 "updateEmergencyNumberListTestMode");
7583
7584 final long identity = Binder.clearCallingIdentity();
7585 try {
7586 for (Phone phone: PhoneFactory.getPhones()) {
7587 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7588 if (tracker != null) {
7589 tracker.executeEmergencyNumberTestModeCommand(action, num);
7590 }
7591 }
7592 } finally {
7593 Binder.restoreCallingIdentity(identity);
7594 }
7595 }
7596
7597 /**
7598 * Get the full emergency number list for test mode.
7599 */
7600 @Override
7601 public List<String> getEmergencyNumberListTestMode() {
7602 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7603 "getEmergencyNumberListTestMode");
7604
7605 final long identity = Binder.clearCallingIdentity();
7606 try {
7607 Set<String> emergencyNumbers = new HashSet<>();
7608 for (Phone phone: PhoneFactory.getPhones()) {
7609 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7610 if (tracker != null) {
7611 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7612 emergencyNumbers.add(num.getNumber());
7613 }
7614 }
7615 }
7616 return new ArrayList<>(emergencyNumbers);
7617 } finally {
7618 Binder.restoreCallingIdentity(identity);
7619 }
7620 }
7621
chen xud6b45bd2018-10-30 22:27:10 -07007622 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007623 public int getEmergencyNumberDbVersion(int subId) {
7624 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7625
7626 final long identity = Binder.clearCallingIdentity();
7627 try {
7628 final Phone phone = getPhone(subId);
7629 if (phone == null) {
7630 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7631 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7632 }
7633 return phone.getEmergencyNumberDbVersion();
7634 } finally {
7635 Binder.restoreCallingIdentity(identity);
7636 }
7637 }
7638
7639 @Override
7640 public void notifyOtaEmergencyNumberDbInstalled() {
7641 enforceModifyPermission();
7642
7643 final long identity = Binder.clearCallingIdentity();
7644 try {
7645 for (Phone phone: PhoneFactory.getPhones()) {
7646 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7647 if (tracker != null) {
7648 tracker.updateOtaEmergencyNumberDatabase();
7649 }
7650 }
7651 } finally {
7652 Binder.restoreCallingIdentity(identity);
7653 }
7654 }
7655
7656 @Override
7657 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7658 enforceActiveEmergencySessionPermission();
7659
7660 final long identity = Binder.clearCallingIdentity();
7661 try {
7662 for (Phone phone: PhoneFactory.getPhones()) {
7663 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7664 if (tracker != null) {
7665 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7666 }
7667 }
7668 } finally {
7669 Binder.restoreCallingIdentity(identity);
7670 }
7671 }
7672
7673 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007674 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7675 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7676 Phone phone = getPhone(subId);
7677 if (phone == null) {
7678 return null;
7679 }
7680 final long identity = Binder.clearCallingIdentity();
7681 try {
7682 UiccProfile profile = UiccController.getInstance()
7683 .getUiccProfileForPhone(phone.getPhoneId());
7684 if (profile != null) {
7685 return profile.getCertsFromCarrierPrivilegeAccessRules();
7686 }
7687 } finally {
7688 Binder.restoreCallingIdentity(identity);
7689 }
7690 return null;
7691 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007692
7693 /**
7694 * Enable or disable a modem stack.
7695 */
7696 @Override
7697 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7698 enforceModifyPermission();
7699
7700 final long identity = Binder.clearCallingIdentity();
7701 try {
7702 Phone phone = PhoneFactory.getPhone(slotIndex);
7703 if (phone == null) {
7704 return false;
7705 } else {
7706 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7707 }
7708 } finally {
7709 Binder.restoreCallingIdentity(identity);
7710 }
7711 }
Michelecea4cf22018-12-21 15:00:11 -08007712
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007713 /**
7714 * Whether a modem stack is enabled or not.
7715 */
7716 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007717 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7718 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007719 Phone phone = PhoneFactory.getPhone(slotIndex);
7720 if (phone == null) return false;
7721
7722 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007723 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7724 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007725 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7726 }
7727
7728 final long identity = Binder.clearCallingIdentity();
7729 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007730 try {
7731 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7732 } catch (NoSuchElementException ex) {
7733 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7734 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007735 } finally {
7736 Binder.restoreCallingIdentity(identity);
7737 }
7738 }
7739
Michelecea4cf22018-12-21 15:00:11 -08007740 @Override
Michele0ea7d782019-03-19 14:58:42 -07007741 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007742 enforceModifyPermission();
7743
7744 final long identity = Binder.clearCallingIdentity();
7745 try {
7746 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007747 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007748 .commit();
7749 } finally {
7750 Binder.restoreCallingIdentity(identity);
7751 }
7752 }
7753
7754 @Override
Michele0ea7d782019-03-19 14:58:42 -07007755 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007756 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007758 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7759 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007760 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007761 }
Michelecea4cf22018-12-21 15:00:11 -08007762
7763 final long identity = Binder.clearCallingIdentity();
7764 try {
Michele0ea7d782019-03-19 14:58:42 -07007765 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007766 } finally {
7767 Binder.restoreCallingIdentity(identity);
7768 }
7769 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007770
Michele0ea7d782019-03-19 14:58:42 -07007771 @TelephonyManager.IsMultiSimSupportedResult
7772 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007773 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7774 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7775 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007776 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7777 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007778 }
7779 // Check if the hardware supports multisim functionality. If usage of multisim is not
7780 // supported by the modem, indicate that it is restricted.
7781 PhoneCapability staticCapability =
7782 mPhoneConfigurationManager.getStaticPhoneCapability();
7783 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007784 loge("isMultiSimSupportedInternal: no static configuration available");
7785 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007786 }
Sarah Chin0605abf2019-12-06 10:24:18 -08007787 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007788 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7789 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007790 }
7791 // Check if support of multiple SIMs is restricted by carrier
7792 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007793 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007794 }
7795
Michele0ea7d782019-03-19 14:58:42 -07007796 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007797 }
7798
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007799 /**
7800 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007801 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7802 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7803 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007804 * @param numOfSims number of active sims we want to switch to
7805 */
7806 @Override
7807 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007808 if (numOfSims == 1) {
7809 enforceModifyPermission();
7810 } else {
7811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7812 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7813 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007814 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007815
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007816 try {
Michele30b57b22019-03-01 12:01:14 -08007817 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007818 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007819 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7820 return;
7821 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007822 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7823 } finally {
7824 Binder.restoreCallingIdentity(identity);
7825 }
7826 }
7827
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007828 @Override
7829 public boolean isApplicationOnUicc(int subId, int appType) {
7830 enforceReadPrivilegedPermission("isApplicationOnUicc");
7831 Phone phone = getPhone(subId);
7832 if (phone == null) {
7833 return false;
7834 }
7835 final long identity = Binder.clearCallingIdentity();
7836 try {
7837 UiccCard uiccCard = phone.getUiccCard();
7838 if (uiccCard == null) {
7839 return false;
7840 }
7841 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7842 if (uiccProfile == null) {
7843 return false;
7844 }
7845 if (TelephonyManager.APPTYPE_SIM <= appType
7846 && appType <= TelephonyManager.APPTYPE_ISIM) {
7847 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7848 }
7849 return false;
7850 } finally {
7851 Binder.restoreCallingIdentity(identity);
7852 }
7853 }
7854
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007855 /**
chen xub4baa772019-04-03 10:23:41 -07007856 * Get whether making changes to modem configurations will trigger reboot.
7857 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007858 */
7859 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007860 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7861 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007862 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007863 mApp, subId, callingPackage, callingFeatureId,
7864 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007865 return false;
7866 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007867 final long identity = Binder.clearCallingIdentity();
7868 try {
7869 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7870 } finally {
7871 Binder.restoreCallingIdentity(identity);
7872 }
7873 }
7874
Nathan Harold29f5f052019-02-15 13:41:57 -08007875 private void updateModemStateMetrics() {
7876 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7877 // TODO: check the state for each modem if the api is ready.
7878 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7879 }
7880
Pengquan Meng3889a572019-01-23 11:16:29 -08007881 @Override
7882 public int[] getSlotsMapping() {
7883 enforceReadPrivilegedPermission("getSlotsMapping");
7884
7885 final long identity = Binder.clearCallingIdentity();
7886 try {
7887 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7888 // All logical slots should have a mapping to a physical slot.
7889 int[] logicalSlotsMapping = new int[phoneCount];
7890 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7891 for (int i = 0; i < slotInfos.length; i++) {
7892 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7893 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7894 }
7895 }
7896 return logicalSlotsMapping;
7897 } finally {
7898 Binder.restoreCallingIdentity(identity);
7899 }
7900 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007901
7902 /**
7903 * Get the IRadio HAL Version
7904 */
7905 @Override
7906 public int getRadioHalVersion() {
7907 Phone phone = getDefaultPhone();
7908 if (phone == null) return -1;
7909 HalVersion hv = phone.getHalVersion();
7910 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7911 return hv.major * 100 + hv.minor;
7912 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007913
7914 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007915 * Get the current calling package name.
7916 * @return the current calling package name
7917 */
7918 @Override
7919 public String getCurrentPackageName() {
7920 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
7921 }
7922
7923 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007924 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7925 * corresponding network requests on a subId.
7926 *
7927 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007928 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007929 * 2) APN is un-metered for this subscription, or
7930 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007931 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007932 *
7933 * @return whether data is allowed for a apn type.
7934 *
7935 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007936 */
7937 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007938 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007939 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7940 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007941
7942 // Now that all security checks passes, perform the operation as ourselves.
7943 final long identity = Binder.clearCallingIdentity();
7944 try {
7945 Phone phone = getPhone(subId);
7946 if (phone == null) return false;
7947
Jack Yu41407ee2019-05-13 16:54:09 -07007948 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007949 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7950 } finally {
7951 Binder.restoreCallingIdentity(identity);
7952 }
7953 }
7954
7955 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007956 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007957 enforceReadPrivilegedPermission("isApnMetered");
7958
7959 // Now that all security checks passes, perform the operation as ourselves.
7960 final long identity = Binder.clearCallingIdentity();
7961 try {
7962 Phone phone = getPhone(subId);
7963 if (phone == null) return true; // By default return true.
7964
Jack Yu41407ee2019-05-13 16:54:09 -07007965 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007966 } finally {
7967 Binder.restoreCallingIdentity(identity);
7968 }
7969 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007970
7971 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08007972 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
7973 int subscriptionId, IBooleanConsumer resultCallback) {
7974 enforceModifyPermission();
7975 long token = Binder.clearCallingIdentity();
7976 try {
7977 Phone phone = getPhone(subscriptionId);
7978 if (phone == null) {
7979 try {
7980 if (resultCallback != null) {
7981 resultCallback.accept(false);
7982 }
7983 } catch (RemoteException e) {
7984 // ignore
7985 }
7986 return;
7987 }
7988 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
7989 Pair.create(specifiers, (x) -> {
7990 try {
7991 if (resultCallback != null) {
7992 resultCallback.accept(x);
7993 }
7994 } catch (RemoteException e) {
7995 // ignore
7996 }
7997 });
7998 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
7999 } finally {
8000 Binder.restoreCallingIdentity(token);
8001 }
8002 }
8003
8004 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008005 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8006 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8007 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8008 if (iccRecords == null) {
8009 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8010 return false;
8011 }
8012 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8013 }
8014
8015 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008016 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008017 if (callingPackage == null) {
8018 callingPackage = getCurrentPackageName();
8019 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008020 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8021 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8022 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8023 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8024 }
8025 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8026 Intent intent = new Intent();
8027 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8028 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8029 // Bring up choose default SMS subscription dialog right now
8030 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8031 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8032 mApp.startActivity(intent);
8033 }
chen xud5ca2d52019-05-28 15:20:57 -07008034
8035 @Override
8036 public String getMmsUAProfUrl(int subId) {
8037 //TODO investigate if this API should require proper permission check in R b/133791609
8038 final long identity = Binder.clearCallingIdentity();
8039 try {
8040 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8041 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8042 } finally {
8043 Binder.restoreCallingIdentity(identity);
8044 }
8045 }
8046
8047 @Override
8048 public String getMmsUserAgent(int subId) {
8049 //TODO investigate if this API should require proper permission check in R b/133791609
8050 final long identity = Binder.clearCallingIdentity();
8051 try {
8052 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8053 .getString(com.android.internal.R.string.config_mms_user_agent);
8054 } finally {
8055 Binder.restoreCallingIdentity(identity);
8056 }
8057 }
Jack Yub07d4972019-05-28 16:12:25 -07008058
8059 @Override
8060 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8061 enforceModifyPermission();
8062
8063 // Now that all security checks passes, perform the operation as ourselves.
8064 final long identity = Binder.clearCallingIdentity();
8065 try {
8066 Phone phone = getPhone(subId);
8067 if (phone == null) return false;
8068
8069 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8070 } finally {
8071 Binder.restoreCallingIdentity(identity);
8072 }
8073 }
8074
8075 @Override
8076 public boolean isDataAllowedInVoiceCall(int subId) {
8077 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8078
8079 // Now that all security checks passes, perform the operation as ourselves.
8080 final long identity = Binder.clearCallingIdentity();
8081 try {
8082 Phone phone = getPhone(subId);
8083 if (phone == null) return false;
8084
8085 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8086 } finally {
8087 Binder.restoreCallingIdentity(identity);
8088 }
8089 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008090
changbettyd5c246e2019-12-24 15:40:37 +08008091 @Override
8092 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8093 enforceModifyPermission();
8094
8095 // Now that all security checks passes, perform the operation as ourselves.
8096 final long identity = Binder.clearCallingIdentity();
8097 try {
8098 Phone phone = getPhone(subId);
8099 if (phone == null) return false;
8100
8101 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8102 } finally {
8103 Binder.restoreCallingIdentity(identity);
8104 }
8105 }
8106
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008107 /**
8108 * Updates whether conference event pacakge handling is enabled.
8109 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8110 * otherwise.
8111 */
8112 @Override
8113 public void setCepEnabled(boolean isCepEnabled) {
8114 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8115
8116 final long identity = Binder.clearCallingIdentity();
8117 try {
8118 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8119 for (Phone phone : PhoneFactory.getPhones()) {
8120 Phone defaultPhone = phone.getImsPhone();
8121 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8122 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8123 ImsPhoneCallTracker imsPhoneCallTracker =
8124 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8125 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8126 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8127 + imsPhone.getMsisdn());
8128 }
8129 }
8130 } finally {
8131 Binder.restoreCallingIdentity(identity);
8132 }
8133 }
allenwtsu46dcc572020-01-08 18:24:03 +08008134
8135 /**
8136 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8137 *
8138 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8139 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8140 * before being read.
8141 */
8142 @Override
8143 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8144 isCompressed) {
8145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8146 mApp, subId, "notifyRcsAutoConfigurationReceived");
8147 try {
8148 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8149 if (configBinder == null) {
8150 Rlog.e(LOG_TAG, "null result for getImsConfig");
8151 } else {
8152 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8153 }
8154 } catch (RemoteException e) {
8155 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8156 }
8157 }
zoey chene02881a2019-12-30 16:11:23 +08008158
8159 @Override
8160 public boolean isIccLockEnabled(int subId) {
8161 enforceReadPrivilegedPermission("isIccLockEnabled");
8162
8163 // Now that all security checks passes, perform the operation as ourselves.
8164 final long identity = Binder.clearCallingIdentity();
8165 try {
8166 Phone phone = getPhone(subId);
8167 if (phone != null && phone.getIccCard() != null) {
8168 return phone.getIccCard().getIccLockEnabled();
8169 } else {
8170 return false;
8171 }
8172 } finally {
8173 Binder.restoreCallingIdentity(identity);
8174 }
8175 }
8176
8177 /**
8178 * Set the ICC pin lock enabled or disabled.
8179 *
8180 * @return an integer representing the status of IccLock enabled or disabled in the following
8181 * three cases:
8182 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8183 * successfully.
8184 * - Positive number and zero for remaining password attempts.
8185 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8186 *
8187 */
8188 @Override
8189 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8190 enforceModifyPermission();
8191
8192 Phone phone = getPhone(subId);
8193 if (phone == null) {
8194 return 0;
8195 }
8196 // Now that all security checks passes, perform the operation as ourselves.
8197 final long identity = Binder.clearCallingIdentity();
8198 try {
8199 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8200 new Pair<Boolean, String>(enabled, password), phone, null);
8201 return attemptsRemaining;
8202
8203 } catch (Exception e) {
8204 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8205 } finally {
8206 Binder.restoreCallingIdentity(identity);
8207 }
8208 return 0;
8209 }
8210
8211 /**
8212 * Change the ICC password used in ICC pin lock.
8213 *
8214 * @return an integer representing the status of IccLock changed in the following three cases:
8215 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8216 * - Positive number and zero for remaining password attempts.
8217 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8218 *
8219 */
8220 @Override
8221 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8222 enforceModifyPermission();
8223
8224 Phone phone = getPhone(subId);
8225 if (phone == null) {
8226 return 0;
8227 }
8228 // Now that all security checks passes, perform the operation as ourselves.
8229 final long identity = Binder.clearCallingIdentity();
8230 try {
8231 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8232 new Pair<String, String>(oldPassword, newPassword), phone, null);
8233 return attemptsRemaining;
8234
8235 } catch (Exception e) {
8236 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8237 } finally {
8238 Binder.restoreCallingIdentity(identity);
8239 }
8240 return 0;
8241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008242}