blob: e3a08da6b9ef830cd1f14e5a6a942a8642349f08 [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) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07003033 if (!isActiveSubscription(subId)) {
3034 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3035 }
3036
Pengquan Menga1bb6272018-09-06 09:59:22 -07003037 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3038 }
3039
Brad Ebinger35c841c2018-10-01 10:40:55 -07003040 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003041 public boolean isInEmergencySmsMode() {
3042 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 for (Phone phone : PhoneFactory.getPhones()) {
3046 if (phone.isInEmergencySmsMode()) {
3047 return true;
3048 }
3049 }
3050 } finally {
3051 Binder.restoreCallingIdentity(identity);
3052 }
3053 return false;
3054 }
3055
shilu366312e2019-12-17 09:28:10 -08003056 /**
3057 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3058 * @param subId The subscription to use to check the configuration.
3059 * @param c The callback that will be used to send the result.
3060 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003061 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003062 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3063 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003064 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003065 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003066
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003067 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3068 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3069 "IMS not available on device.");
3070 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003071 final long token = Binder.clearCallingIdentity();
3072 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003073 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003074 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003075 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003076 } catch (ImsException e) {
3077 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003078 } finally {
3079 Binder.restoreCallingIdentity(token);
3080 }
3081 }
3082
shilu366312e2019-12-17 09:28:10 -08003083 /**
3084 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3085 * @param subId The subscription to use to check the configuration.
3086 * @param c The callback that will be used to send the result.
3087 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003088 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003089 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003090 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003091 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003092 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3093 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3094 }
Meng Wangafbc5852019-09-19 17:37:13 -07003095 final long token = Binder.clearCallingIdentity();
3096 try {
3097 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3098 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3099 .removeRegistrationCallbackForSubscription(c, subId);
3100 } catch (ImsException e) {
3101 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3102 + "is inactive, ignoring unregister.");
3103 // If the subscription is no longer active, just return, since the callback
3104 // will already have been removed internally.
3105 } finally {
3106 Binder.restoreCallingIdentity(token);
3107 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 }
3109
Brad Ebingera34a6c22019-10-22 17:36:18 -07003110 /**
3111 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3112 */
3113 @Override
3114 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3115 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3116 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3117 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3118 "IMS not available on device.");
3119 }
3120 final long token = Binder.clearCallingIdentity();
3121 try {
3122 Phone phone = getPhone(subId);
3123 if (phone == null) {
3124 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3125 + subId + "'");
3126 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3127 }
3128 phone.getImsRegistrationState(regState -> {
3129 try {
3130 consumer.accept((regState == null)
3131 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3132 } catch (RemoteException e) {
3133 // Ignore if the remote process is no longer available to call back.
3134 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3135 }
3136 });
3137 } finally {
3138 Binder.restoreCallingIdentity(token);
3139 }
3140 }
3141
3142 /**
3143 * Get the transport type for the IMS service registration state.
3144 */
3145 @Override
3146 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003147 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebingera34a6c22019-10-22 17:36:18 -07003148 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3149 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3150 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3151 "IMS not available on device.");
3152 }
3153 final long token = Binder.clearCallingIdentity();
3154 try {
3155 Phone phone = getPhone(subId);
3156 if (phone == null) {
3157 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3158 + subId + "'");
3159 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3160 }
3161 phone.getImsRegistrationTech(regTech -> {
3162 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3163 int regTechConverted = (regTech == null)
3164 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3165 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3166 regTechConverted);
3167 try {
3168 consumer.accept(regTechConverted);
3169 } catch (RemoteException e) {
3170 // Ignore if the remote process is no longer available to call back.
3171 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3172 }
3173 });
3174 } finally {
3175 Binder.restoreCallingIdentity(token);
3176 }
3177 }
3178
shilu366312e2019-12-17 09:28:10 -08003179 /**
3180 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3181 * @param subId The subscription to use to check the configuration.
3182 * @param c The callback that will be used to send the result.
3183 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003184 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003185 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3186 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003187 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003188 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003189 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3190 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3191 "IMS not available on device.");
3192 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003193 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3194 final long token = Binder.clearCallingIdentity();
3195 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003196 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003197 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003198 } catch (ImsException e) {
3199 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003200 } finally {
3201 Binder.restoreCallingIdentity(token);
3202 }
3203 }
3204
shilu366312e2019-12-17 09:28:10 -08003205 /**
3206 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3207 * @param subId The subscription to use to check the configuration.
3208 * @param c The callback that will be used to send the result.
3209 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003210 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003211 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003212 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003213 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003214 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3215 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3216 }
Meng Wangafbc5852019-09-19 17:37:13 -07003217
3218 final long token = Binder.clearCallingIdentity();
3219 try {
3220 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3221 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003222 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003223 } catch (ImsException e) {
3224 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3225 + "is inactive, ignoring unregister.");
3226 // If the subscription is no longer active, just return, since the callback
3227 // will already have been removed internally.
3228 } finally {
3229 Binder.restoreCallingIdentity(token);
3230 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003231 }
3232
3233 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003234 public boolean isCapable(int subId, int capability, int regTech) {
3235 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003236 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3237 final long token = Binder.clearCallingIdentity();
3238 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003239 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003241 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003242 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3243 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003244 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003245 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3246 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003247 } finally {
3248 Binder.restoreCallingIdentity(token);
3249 }
3250 }
3251
3252 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003253 public boolean isAvailable(int subId, int capability, int regTech) {
3254 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 final long token = Binder.clearCallingIdentity();
3256 try {
3257 Phone phone = getPhone(subId);
3258 if (phone == null) return false;
3259 return phone.isImsCapabilityAvailable(capability, regTech);
3260 } finally {
3261 Binder.restoreCallingIdentity(token);
3262 }
3263 }
3264
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003265 /**
3266 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3267 * subscription.
3268 * @param subId The subscription to use to check the configuration.
3269 * @param callback The callback that will be used to send the result.
3270 * @param capability The MmTelFeature capability that will be used to send the result.
3271 * @param transportType The transport type of the MmTelFeature capability.
3272 */
3273 @Override
3274 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3275 int transportType) {
3276 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3277 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3278 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3279 "IMS not available on device.");
3280 }
3281 final long token = Binder.clearCallingIdentity();
3282 try {
3283 int slotId = getSlotIndex(subId);
3284 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3285 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3286 + subId + "'");
3287 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3288 }
3289 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3290 transportType, aBoolean -> {
3291 try {
3292 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3293 } catch (RemoteException e) {
3294 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3295 + "running. Ignore");
3296 }
3297 });
3298 } finally {
3299 Binder.restoreCallingIdentity(token);
3300 }
3301 }
3302
shilu366312e2019-12-17 09:28:10 -08003303 /**
3304 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3305 * @param subId The subscription to use to check the configuration.
3306 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003307 @Override
3308 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003309 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3310 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3311
Brad Ebinger35c841c2018-10-01 10:40:55 -07003312 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3313 final long token = Binder.clearCallingIdentity();
3314 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003315 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003316 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003317 } catch (ImsException e) {
3318 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003319 } finally {
3320 Binder.restoreCallingIdentity(token);
3321 }
3322 }
3323
3324 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003325 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003327 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003328 final long identity = Binder.clearCallingIdentity();
3329 try {
3330 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003331 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003332 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003333 } catch (ImsException e) {
3334 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
3338 }
3339
shilu366312e2019-12-17 09:28:10 -08003340 /**
3341 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3342 * @param subId The subscription to use to check the configuration.
3343 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003344 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003345 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003346 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003347 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003351 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3352 } catch (ImsException e) {
3353 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003354 } finally {
3355 Binder.restoreCallingIdentity(identity);
3356 }
3357 }
3358
3359 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003360 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003362 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 final long identity = Binder.clearCallingIdentity();
3364 try {
3365 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003366 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003367 } catch (ImsException e) {
3368 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003369 } finally {
3370 Binder.restoreCallingIdentity(identity);
3371 }
3372 }
3373
shilu366312e2019-12-17 09:28:10 -08003374 /**
3375 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3376 * @param subId The subscription to use to check the configuration.
3377 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003378 @Override
3379 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003380 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3382 final long identity = Binder.clearCallingIdentity();
3383 try {
3384 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003385 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003386 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003387 } catch (ImsException e) {
3388 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003389 } finally {
3390 Binder.restoreCallingIdentity(identity);
3391 }
3392 }
3393
3394 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003395 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003397 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003398 final long identity = Binder.clearCallingIdentity();
3399 try {
3400 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003401 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003402 } catch (ImsException e) {
3403 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003404 } finally {
3405 Binder.restoreCallingIdentity(identity);
3406 }
3407 }
3408
shilu366312e2019-12-17 09:28:10 -08003409 /**
3410 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3411 * @param subId The subscription to use to check the configuration.
3412 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003413 @Override
3414 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003415 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003416 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3417 final long identity = Binder.clearCallingIdentity();
3418 try {
3419 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003420 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003421 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003422 } catch (ImsException e) {
3423 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
3427 }
3428
3429 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003430 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003432 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003433 final long identity = Binder.clearCallingIdentity();
3434 try {
3435 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003436 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003437 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003438 } catch (ImsException e) {
3439 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003440 } finally {
3441 Binder.restoreCallingIdentity(identity);
3442 }
3443 }
3444
3445 @Override
3446 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3448 "setVoWiFiNonPersistent");
3449 final long identity = Binder.clearCallingIdentity();
3450 try {
3451 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003452 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003453 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003454 } catch (ImsException e) {
3455 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003456 } finally {
3457 Binder.restoreCallingIdentity(identity);
3458 }
3459 }
3460
shilu366312e2019-12-17 09:28:10 -08003461 /**
3462 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3463 * @param subId The subscription to use to check the configuration.
3464 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003465 @Override
3466 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003467 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003468 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3469 final long identity = Binder.clearCallingIdentity();
3470 try {
3471 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003472 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003473 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003474 } catch (ImsException e) {
3475 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003476 } finally {
3477 Binder.restoreCallingIdentity(identity);
3478 }
3479 }
3480
3481 @Override
3482 public void setVoWiFiModeSetting(int subId, int mode) {
3483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3484 "setVoWiFiModeSetting");
3485 final long identity = Binder.clearCallingIdentity();
3486 try {
3487 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003488 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003489 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003490 } catch (ImsException e) {
3491 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003492 } finally {
3493 Binder.restoreCallingIdentity(identity);
3494 }
3495 }
3496
3497 @Override
3498 public int getVoWiFiRoamingModeSetting(int subId) {
3499 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3500 final long identity = Binder.clearCallingIdentity();
3501 try {
3502 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003503 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003504 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003505 } catch (ImsException e) {
3506 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003507 } finally {
3508 Binder.restoreCallingIdentity(identity);
3509 }
3510 }
3511
3512 @Override
3513 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3515 "setVoWiFiRoamingModeSetting");
3516 final long identity = Binder.clearCallingIdentity();
3517 try {
3518 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003519 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003520 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003521 } catch (ImsException e) {
3522 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003523 } finally {
3524 Binder.restoreCallingIdentity(identity);
3525 }
3526 }
3527
3528 @Override
3529 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3531 "setRttCapabilityEnabled");
3532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003535 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3536 } catch (ImsException e) {
3537 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003538 } finally {
3539 Binder.restoreCallingIdentity(identity);
3540 }
3541 }
3542
shilu366312e2019-12-17 09:28:10 -08003543 /**
3544 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3545 * @param subId The subscription to use to check the configuration.
3546 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003547 @Override
3548 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003549 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003550 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003554 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003555 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003556 } catch (ImsException e) {
3557 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003558 } finally {
3559 Binder.restoreCallingIdentity(identity);
3560 }
3561 }
3562
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003563 @Override
3564 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3565 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3566 final long identity = Binder.clearCallingIdentity();
3567 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003568 if (!isImsAvailableOnDevice()) {
3569 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3570 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003571 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003572 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003573 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003574 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003575 } catch (ImsException e) {
3576 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003577 } finally {
3578 Binder.restoreCallingIdentity(identity);
3579 }
3580 }
3581
3582 @Override
3583 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3584 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3585 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003586 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3587 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3588 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003589 try {
3590 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003591 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003592 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003593 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003594 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3595 + "is inactive, ignoring unregister.");
3596 // If the subscription is no longer active, just return, since the callback will already
3597 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003598 } finally {
3599 Binder.restoreCallingIdentity(identity);
3600 }
3601 }
3602
allenwtsu99c623b2020-01-03 18:24:23 +08003603
3604 private void checkModifyPhoneStatePermission(int subId, String message) {
3605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3606 message);
3607 }
3608
3609 private boolean isImsProvisioningRequired(int subId, int capability,
3610 boolean isMmtelCapability) {
3611 Phone phone = getPhone(subId);
3612 if (phone == null) {
3613 loge("phone instance null for subid " + subId);
3614 return false;
3615 }
3616 if (isMmtelCapability) {
3617 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3618 return false;
3619 }
3620 } else {
3621 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3622 return false;
3623 }
3624 }
3625 return true;
3626 }
3627
3628 @Override
3629 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3630 boolean isProvisioned) {
3631 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3632
3633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3636 if (!isImsProvisioningRequired(subId, capability, false)) {
3637 return;
3638 }
3639
3640 // this capability requires provisioning, route to the correct API.
3641 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3642 switch (capability) {
3643 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3644 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3645 ims.setEabProvisioned(isProvisioned);
3646 break;
3647 default: {
3648 throw new IllegalArgumentException("Tried to set provisioning for "
3649 + "rcs capability '" + capability + "', which does not require "
3650 + "provisioning.");
3651 }
3652 }
3653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
3656
3657 }
3658
3659
3660 @Override
3661 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3662 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3666 if (!isImsProvisioningRequired(subId, capability, false)) {
3667 return true;
3668 }
3669
3670 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3671 switch (capability) {
3672 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3673 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3674 return ims.isEabProvisionedOnDevice();
3675
3676 default: {
3677 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3678 + "capability '" + capability + "', which does not require "
3679 + "provisioning.");
3680 }
3681 }
3682
3683 } finally {
3684 Binder.restoreCallingIdentity(identity);
3685 }
3686 }
3687
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003688 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003689 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3690 boolean isProvisioned) {
3691 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3692 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3693 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3694 }
allenwtsu99c623b2020-01-03 18:24:23 +08003695 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003696 final long identity = Binder.clearCallingIdentity();
3697 try {
3698 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003699 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003700 return;
3701 }
3702
3703 // this capability requires provisioning, route to the correct API.
3704 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3705 switch (capability) {
3706 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3707 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3708 ims.setVolteProvisioned(isProvisioned);
3709 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3710 ims.setWfcProvisioned(isProvisioned);
3711 }
3712 break;
3713 }
3714 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3715 // There is currently no difference in VT provisioning type.
3716 ims.setVtProvisioned(isProvisioned);
3717 break;
3718 }
3719 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3720 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3721 // change the capability of the feature instead if needed.
3722 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3723 == isProvisioned) {
3724 // No change in provisioning.
3725 return;
3726 }
3727 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3728 try {
3729 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003730 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003731 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3732 + ", Exception" + e.getMessage());
3733 }
3734 break;
3735 }
3736 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003737 throw new IllegalArgumentException("Tried to set provisioning for "
3738 + "MmTel capability '" + capability + "', which does not require "
3739 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003740 }
3741 }
3742
3743 } finally {
3744 Binder.restoreCallingIdentity(identity);
3745 }
3746 }
3747
3748 @Override
3749 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3750 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3751 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3752 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3753 }
3754 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3755 final long identity = Binder.clearCallingIdentity();
3756 try {
3757 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003758 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003759 return true;
3760 }
3761
3762 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3763 switch (capability) {
3764 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3765 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3766 return ims.isVolteProvisionedOnDevice();
3767 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3768 return ims.isWfcProvisionedOnDevice();
3769 }
3770 // This should never happen, since we are checking tech above to make sure it
3771 // is either LTE or IWLAN.
3772 throw new IllegalArgumentException("Invalid radio technology for voice "
3773 + "capability.");
3774 }
3775 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3776 // There is currently no difference in VT provisioning type.
3777 return ims.isVtProvisionedOnDevice();
3778 }
3779 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3780 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3781 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3782 }
3783 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003784 throw new IllegalArgumentException(
3785 "Tried to get provisioning for MmTel capability '" + capability
3786 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003787 }
3788 }
3789
3790 } finally {
3791 Binder.restoreCallingIdentity(identity);
3792 }
3793 }
3794
3795 @Override
3796 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3797 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3798 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3799 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3800 }
3801 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3802 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3803 return (provisionedBits & capability) > 0;
3804 }
3805
3806 @Override
3807 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3808 boolean isProvisioned) {
3809 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3810 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3811 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3812 }
3813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3814 "setProvisioningStatusForCapability");
3815 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3816 // If the current provisioning status for capability already matches isProvisioned,
3817 // do nothing.
3818 if (((provisionedBits & capability) > 0) == isProvisioned) {
3819 return;
3820 }
3821 if (isProvisioned) {
3822 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3823 } else {
3824 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3825 }
3826 }
3827
3828 /**
3829 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3830 * technology. The bitfield should mirror the bitfield defined by
3831 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3832 */
3833 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3834 String key = getMmTelProvisioningKey(subId, tech);
3835 // Default is no capabilities are provisioned.
3836 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3837 }
3838
3839 /**
3840 * Sets the MmTel capability provisioning bitfield (defined by
3841 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3842 * technology specified.
3843 *
3844 * Note: This is a synchronous command and should not be called on UI thread.
3845 */
3846 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3847 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3848 String key = getMmTelProvisioningKey(subId, tech);
3849 editor.putInt(key, newField);
3850 editor.commit();
3851 }
3852
3853 private static String getMmTelProvisioningKey(int subId, int tech) {
3854 // resulting key is provision_ims_mmtel_{subId}_{tech}
3855 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3856 }
3857
3858 /**
3859 * Query CarrierConfig to see if the specified capability requires provisioning for the
3860 * carrier associated with the subscription id.
3861 */
3862 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3863 int capability) {
3864 CarrierConfigManager configManager = new CarrierConfigManager(context);
3865 PersistableBundle c = configManager.getConfigForSubId(subId);
3866 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003867 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003868 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3869 false);
3870 boolean requireVoiceVtProvisioning = c.getBoolean(
3871 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3872
3873 // First check to make sure that the capability requires provisioning.
3874 switch (capability) {
3875 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3876 // intentional fallthrough
3877 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3878 if (requireVoiceVtProvisioning) {
3879 // Voice and Video requires provisioning
3880 return true;
3881 }
3882 break;
3883 }
3884 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3885 if (requireUtProvisioning) {
3886 // UT requires provisioning
3887 return true;
3888 }
3889 break;
3890 }
3891 }
3892 return false;
3893 }
3894
allenwtsu99c623b2020-01-03 18:24:23 +08003895 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3896 int capability) {
3897 CarrierConfigManager configManager = new CarrierConfigManager(context);
3898 PersistableBundle c = configManager.getConfigForSubId(subId);
3899
3900 boolean requireRcsProvisioning = c.getBoolean(
3901 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3902
3903 // First check to make sure that the capability requires provisioning.
3904 switch (capability) {
3905 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3906 // intentional fallthrough
3907 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3908 if (requireRcsProvisioning) {
3909 // OPTION or PRESENCE requires provisioning
3910 return true;
3911 }
3912 break;
3913 }
3914 }
3915 return false;
3916 }
3917
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003918 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003919 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003920 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3921 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3922 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003923 enforceReadPrivilegedPermission("getImsProvisioningInt");
3924 final long identity = Binder.clearCallingIdentity();
3925 try {
3926 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003927 int slotId = getSlotIndex(subId);
3928 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3929 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3930 + subId + "' for key:" + key);
3931 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3932 }
3933 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003934 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003935 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3936 + subId + "' for key:" + key);
3937 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003938 } finally {
3939 Binder.restoreCallingIdentity(identity);
3940 }
3941 }
3942
3943 @Override
3944 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003945 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3946 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3947 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003948 enforceReadPrivilegedPermission("getImsProvisioningString");
3949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003952 int slotId = getSlotIndex(subId);
3953 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3954 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3955 + subId + "' for key:" + key);
3956 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3957 }
3958 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003959 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003960 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3961 + subId + "' for key:" + key);
3962 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003963 } finally {
3964 Binder.restoreCallingIdentity(identity);
3965 }
3966 }
3967
3968 @Override
3969 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003970 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3971 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3972 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3974 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003975 final long identity = Binder.clearCallingIdentity();
3976 try {
3977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003978 int slotId = getSlotIndex(subId);
3979 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3980 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3981 + subId + "' for key:" + key);
3982 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3983 }
3984 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003985 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003986 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3987 + "' for key:" + key);
3988 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003989 } finally {
3990 Binder.restoreCallingIdentity(identity);
3991 }
3992 }
3993
3994 @Override
3995 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003996 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3997 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3998 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4000 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004001 final long identity = Binder.clearCallingIdentity();
4002 try {
4003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004004 int slotId = getSlotIndex(subId);
4005 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4006 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4007 + subId + "' for key:" + key);
4008 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4009 }
4010 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004011 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004012 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4013 + "' for key:" + key);
4014 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004015 } finally {
4016 Binder.restoreCallingIdentity(identity);
4017 }
4018 }
4019
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004020 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004021 int slotId = SubscriptionManager.getSlotIndex(subId);
4022 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004023 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4024 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004025 }
4026 return slotId;
4027 }
4028
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004029 private int getSlotIndex(int subId) {
4030 int slotId = SubscriptionManager.getSlotIndex(subId);
4031 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4032 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4033 }
4034 return slotId;
4035 }
4036
Wink Saville36469e72014-06-11 15:17:00 -07004037 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004038 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004039 */
4040 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004041 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4042 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004043 final int targetSdk = getTargetSdk(callingPackage);
4044 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004045 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004046 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004047 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004048 mApp, subId, callingPackage, callingFeatureId,
4049 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004050 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4051 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 final Phone phone = getPhone(subId);
4056 if (phone != null) {
4057 return phone.getServiceState().getDataNetworkType();
4058 } else {
4059 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4060 }
4061 } finally {
4062 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004064 }
4065
4066 /**
4067 * Returns the data network type
4068 */
4069 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004070 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4071 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4072 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004073 }
4074
4075 /**
4076 * Returns the data network type for a subId
4077 */
4078 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004079 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4080 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004082 mApp, subId, callingPackage, callingFeatureId,
4083 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004084 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4085 }
4086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087 final long identity = Binder.clearCallingIdentity();
4088 try {
4089 final Phone phone = getPhone(subId);
4090 if (phone != null) {
4091 return phone.getServiceState().getDataNetworkType();
4092 } else {
4093 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4094 }
4095 } finally {
4096 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004097 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004098 }
4099
4100 /**
Wink Saville36469e72014-06-11 15:17:00 -07004101 * Returns the Voice network type for a subId
4102 */
4103 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004104 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4105 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004106 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004107 mApp, subId, callingPackage, callingFeatureId,
4108 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004109 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4110 }
4111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112 final long identity = Binder.clearCallingIdentity();
4113 try {
4114 final Phone phone = getPhone(subId);
4115 if (phone != null) {
4116 return phone.getServiceState().getVoiceNetworkType();
4117 } else {
4118 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4119 }
4120 } finally {
4121 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004122 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004123 }
4124
4125 /**
4126 * @return true if a ICC card is present
4127 */
4128 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004129 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004130 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4131 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004132 }
4133
4134 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004135 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004136 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004137 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004138 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004139 final long identity = Binder.clearCallingIdentity();
4140 try {
4141 final Phone phone = PhoneFactory.getPhone(slotIndex);
4142 if (phone != null) {
4143 return phone.getIccCard().hasIccCard();
4144 } else {
4145 return false;
4146 }
4147 } finally {
4148 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004150 }
4151
4152 /**
4153 * Return if the current radio is LTE on CDMA. This
4154 * is a tri-state return value as for a period of time
4155 * the mode may be unknown.
4156 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004157 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004158 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004159 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004160 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004161 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004162 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4163 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4164 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004165 }
4166
Sanket Padawe356d7632015-06-22 14:03:32 -07004167 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004168 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4169 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004170 try {
4171 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4172 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004173 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4174 }
4175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004176 final long identity = Binder.clearCallingIdentity();
4177 try {
4178 final Phone phone = getPhone(subId);
4179 if (phone == null) {
4180 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4181 } else {
4182 return phone.getLteOnCdmaMode();
4183 }
4184 } finally {
4185 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004186 }
Wink Saville36469e72014-06-11 15:17:00 -07004187 }
4188
Wink Saville36469e72014-06-11 15:17:00 -07004189 /**
4190 * {@hide}
4191 * Returns Default subId, 0 in the case of single standby.
4192 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004193 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004194 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004195 }
4196
Shishir Agrawala9f32182016-04-12 12:00:16 -07004197 private int getSlotForDefaultSubscription() {
4198 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4199 }
4200
Wink Savilleb564aae2014-10-23 10:18:09 -07004201 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004202 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004203 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004204
Pengquan Menge92a50d2018-09-21 15:54:48 -07004205 private boolean isActiveSubscription(int subId) {
4206 return mSubscriptionController.isActiveSubId(subId);
4207 }
4208
Ihab Awadf2177b72013-11-25 13:33:23 -08004209 /**
4210 * @see android.telephony.TelephonyManager.WifiCallingChoices
4211 */
4212 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213 final long identity = Binder.clearCallingIdentity();
4214 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004215 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004216 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4217 getWhenToMakeWifiCallsDefaultPreference());
4218 } finally {
4219 Binder.restoreCallingIdentity(identity);
4220 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004221 }
4222
4223 /**
4224 * @see android.telephony.TelephonyManager.WifiCallingChoices
4225 */
4226 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004227 final long identity = Binder.clearCallingIdentity();
4228 try {
4229 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004230 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004231 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4232 } finally {
4233 Binder.restoreCallingIdentity(identity);
4234 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004235 }
4236
Sailesh Nepald1e68152013-12-12 19:08:02 -08004237 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004238 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004239 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004240 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004241
Jordan Liu4c733742019-02-28 12:03:40 -08004242 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4243 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4244 if (phoneId == -1) {
4245 throw new IllegalArgumentException("Given slot index: " + slotIndex
4246 + " does not correspond to an active phone");
4247 }
4248 return PhoneFactory.getPhone(phoneId);
4249 }
4250
Shishir Agrawal566b7612013-10-28 14:41:00 -07004251 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004252 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4253 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4255 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004257 if (DBG) {
4258 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4259 }
4260 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4261 p2);
4262 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004263
Jordan Liu4c733742019-02-28 12:03:40 -08004264
4265 @Override
4266 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4267 int slotIndex, String callingPackage, String aid, int p2) {
4268 enforceModifyPermission();
4269 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4270 if (DBG) {
4271 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4272 }
4273 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4274 callingPackage, aid, p2);
4275 }
4276
4277 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4278 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004279 final long identity = Binder.clearCallingIdentity();
4280 try {
4281 if (TextUtils.equals(ISDR_AID, aid)) {
4282 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004283 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4284 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004285 if (bestComponent == null
4286 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4287 loge("The calling package is not allowed to access ISD-R.");
4288 throw new SecurityException(
4289 "The calling package is not allowed to access ISD-R.");
4290 }
Derek Tan740e1672017-06-27 14:56:27 -07004291 }
Derek Tan740e1672017-06-27 14:56:27 -07004292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004294 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4295 null /* workSource */);
4296 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004297 return response;
4298 } finally {
4299 Binder.restoreCallingIdentity(identity);
4300 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004301 }
4302
4303 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004304 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4306 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004307 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4308 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4309 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004310
Jordan Liu4c733742019-02-28 12:03:40 -08004311 @Override
4312 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4313 enforceModifyPermission();
4314 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4315 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4316 channel);
4317 }
4318
4319 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004320 final long identity = Binder.clearCallingIdentity();
4321 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004322 if (channel < 0) {
4323 return false;
4324 }
Jordan Liu4c733742019-02-28 12:03:40 -08004325 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4326 null /* workSource */);
4327 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004328 return success;
4329 } finally {
4330 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004331 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004332 }
4333
4334 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004335 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004336 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4338 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004339 if (DBG) {
4340 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4341 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4342 + p3 + " data=" + data);
4343 }
4344 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4345 command, p1, p2, p3, data);
4346 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004347
Jordan Liu4c733742019-02-28 12:03:40 -08004348 @Override
4349 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4350 int command, int p1, int p2, int p3, String data) {
4351 enforceModifyPermission();
4352 if (DBG) {
4353 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4354 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4355 + p3 + " data=" + data);
4356 }
4357 return iccTransmitApduLogicalChannelWithPermission(
4358 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4359 data);
4360 }
4361
4362 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4363 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004364 final long identity = Binder.clearCallingIdentity();
4365 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004366 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367 return "";
4368 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004369
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004370 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004371 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4372 null /* workSource */);
4373 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375 // Append the returned status code to the end of the response payload.
4376 String s = Integer.toHexString(
4377 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4378 if (response.payload != null) {
4379 s = IccUtils.bytesToHexString(response.payload) + s;
4380 }
4381 return s;
4382 } finally {
4383 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004384 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004385 }
Jake Hambye994d462014-02-03 13:10:13 -08004386
Evan Charltonc66da362014-05-16 14:06:40 -07004387 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004388 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4389 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4391 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004392 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004393 if (DBG) {
4394 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4395 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4396 }
4397 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4398 cla, command, p1, p2, p3, data);
4399 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004400
Jordan Liu4c733742019-02-28 12:03:40 -08004401 @Override
4402 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4403 int command, int p1, int p2, int p3, String data) {
4404 enforceModifyPermission();
4405 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4406 if (DBG) {
4407 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4408 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4409 + " data=" + data);
4410 }
4411
4412 return iccTransmitApduBasicChannelWithPermission(
4413 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4414 p2, p3, data);
4415 }
4416
4417 // open APDU basic channel assuming the caller has sufficient permissions
4418 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4419 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420 final long identity = Binder.clearCallingIdentity();
4421 try {
4422 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4423 && TextUtils.equals(ISDR_AID, data)) {
4424 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004425 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4426 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004427 if (bestComponent == null
4428 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4429 loge("The calling package is not allowed to select ISD-R.");
4430 throw new SecurityException(
4431 "The calling package is not allowed to select ISD-R.");
4432 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004433 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004434
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004435 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004436 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4437 null /* workSource */);
4438 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440 // Append the returned status code to the end of the response payload.
4441 String s = Integer.toHexString(
4442 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4443 if (response.payload != null) {
4444 s = IccUtils.bytesToHexString(response.payload) + s;
4445 }
4446 return s;
4447 } finally {
4448 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004449 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004450 }
4451
4452 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004453 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004454 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4456 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458 final long identity = Binder.clearCallingIdentity();
4459 try {
4460 if (DBG) {
4461 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4462 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4463 }
4464
4465 IccIoResult response =
4466 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4467 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4468 subId);
4469
4470 if (DBG) {
4471 log("Exchange SIM_IO [R]" + response);
4472 }
4473
4474 byte[] result = null;
4475 int length = 2;
4476 if (response.payload != null) {
4477 length = 2 + response.payload.length;
4478 result = new byte[length];
4479 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4480 } else {
4481 result = new byte[length];
4482 }
4483
4484 result[length - 1] = (byte) response.sw2;
4485 result[length - 2] = (byte) response.sw1;
4486 return result;
4487 } finally {
4488 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004489 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004490 }
4491
Nathan Haroldb3014052017-01-25 15:57:32 -08004492 /**
4493 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4494 * on a particular subscription
4495 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004496 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4497 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004499 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004500 return null;
4501 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004502
4503 final long identity = Binder.clearCallingIdentity();
4504 try {
4505 if (appType != TelephonyManager.APPTYPE_USIM
4506 && appType != TelephonyManager.APPTYPE_SIM) {
4507 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4508 return null;
4509 }
4510 Object response = sendRequest(
4511 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4512 if (response instanceof String[]) {
4513 return (String[]) response;
4514 }
yincheng zhao2737e882019-09-06 17:06:54 -07004515 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004516 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004517 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004520 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004521 }
4522
yincheng zhao2737e882019-09-06 17:06:54 -07004523 /**
4524 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4525 * subscription.
4526 *
4527 * @param subId the id of the subscription.
4528 * @param appType the uicc app type, must be USIM or SIM.
4529 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4530 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004531 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004532 * @return number of fplmns that is successfully written to the SIM.
4533 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004534 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4535 String callingFeatureId) {
4536 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4537 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004538 if (DBG) logv("no permissions for setForbiddenplmns");
4539 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4540 }
4541 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4542 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4543 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4544 }
4545 if (fplmns == null) {
4546 throw new IllegalArgumentException("Fplmn List provided is null");
4547 }
4548 for (String fplmn : fplmns) {
4549 if (!CellIdentity.isValidPlmn(fplmn)) {
4550 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4551 }
4552 }
4553 final long identity = Binder.clearCallingIdentity();
4554 try {
4555 Object response = sendRequest(
4556 CMD_SET_FORBIDDEN_PLMNS,
4557 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4558 subId);
4559 return (int) response;
4560 } finally {
4561 Binder.restoreCallingIdentity(identity);
4562 }
4563 }
4564
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004565 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004566 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4568 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570 final long identity = Binder.clearCallingIdentity();
4571 try {
4572 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4573 if (response.payload == null) {
4574 return "";
4575 }
Evan Charltonc66da362014-05-16 14:06:40 -07004576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004577 // Append the returned status code to the end of the response payload.
4578 String s = Integer.toHexString(
4579 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4580 s = IccUtils.bytesToHexString(response.payload) + s;
4581 return s;
4582 } finally {
4583 Binder.restoreCallingIdentity(identity);
4584 }
Evan Charltonc66da362014-05-16 14:06:40 -07004585 }
4586
Jake Hambye994d462014-02-03 13:10:13 -08004587 /**
4588 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4589 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4590 *
4591 * @param itemID the ID of the item to read
4592 * @return the NV item as a String, or null on error.
4593 */
4594 @Override
4595 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004596 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4598 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004599
4600 final long identity = Binder.clearCallingIdentity();
4601 try {
4602 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004603 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004604 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4605 return value;
4606 } finally {
4607 Binder.restoreCallingIdentity(identity);
4608 }
Jake Hambye994d462014-02-03 13:10:13 -08004609 }
4610
4611 /**
4612 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4613 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4614 *
4615 * @param itemID the ID of the item to read
4616 * @param itemValue the value to write, as a String
4617 * @return true on success; false on any failure
4618 */
4619 @Override
4620 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004621 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4623 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624
4625 final long identity = Binder.clearCallingIdentity();
4626 try {
4627 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4628 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004629 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004630 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4631 return success;
4632 } finally {
4633 Binder.restoreCallingIdentity(identity);
4634 }
Jake Hambye994d462014-02-03 13:10:13 -08004635 }
4636
4637 /**
4638 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4639 * Used for device configuration by some CDMA operators.
4640 *
4641 * @param preferredRoamingList byte array containing the new PRL
4642 * @return true on success; false on any failure
4643 */
4644 @Override
4645 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4647 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004648
4649 final long identity = Binder.clearCallingIdentity();
4650 try {
4651 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4652 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4653 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4654 return success;
4655 } finally {
4656 Binder.restoreCallingIdentity(identity);
4657 }
Jake Hambye994d462014-02-03 13:10:13 -08004658 }
4659
4660 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004661 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004662 * Used for device configuration by some CDMA operators.
4663 *
chen xu6dac5ab2018-10-26 17:39:23 -07004664 * @param slotIndex - device slot.
4665 *
Jake Hambye994d462014-02-03 13:10:13 -08004666 * @return true on success; false on any failure
4667 */
4668 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004669 public boolean resetModemConfig(int slotIndex) {
4670 Phone phone = PhoneFactory.getPhone(slotIndex);
4671 if (phone != null) {
4672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4673 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004674
chen xu6dac5ab2018-10-26 17:39:23 -07004675 final long identity = Binder.clearCallingIdentity();
4676 try {
4677 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4678 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4679 return success;
4680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683 }
chen xu6dac5ab2018-10-26 17:39:23 -07004684 return false;
4685 }
4686
4687 /**
4688 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4689 *
4690 * @param slotIndex - device slot.
4691 *
4692 * @return true on success; false on any failure
4693 */
4694 @Override
4695 public boolean rebootModem(int slotIndex) {
4696 Phone phone = PhoneFactory.getPhone(slotIndex);
4697 if (phone != null) {
4698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4699 mApp, phone.getSubId(), "rebootModem");
4700
4701 final long identity = Binder.clearCallingIdentity();
4702 try {
4703 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4704 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4705 return success;
4706 } finally {
4707 Binder.restoreCallingIdentity(identity);
4708 }
4709 }
4710 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004711 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004712
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004713 public String[] getPcscfAddress(String apnType, String callingPackage,
4714 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004715 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4717 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004718 return new String[0];
4719 }
4720
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004721 final long identity = Binder.clearCallingIdentity();
4722 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004723 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004724 } finally {
4725 Binder.restoreCallingIdentity(identity);
4726 }
Wink Saville36469e72014-06-11 15:17:00 -07004727 }
4728
Brad Ebinger51f743a2017-01-23 13:50:20 -08004729 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004730 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4731 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004732 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004733 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004734 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735
4736 final long identity = Binder.clearCallingIdentity();
4737 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004738 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004739 // may happen if the device does not support IMS.
4740 return;
4741 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004742 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004743 } finally {
4744 Binder.restoreCallingIdentity(identity);
4745 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004746 }
4747
4748 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004749 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4750 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004751 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004752 public void disableIms(int slotId) {
4753 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004754
4755 final long identity = Binder.clearCallingIdentity();
4756 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004757 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004758 // may happen if the device does not support IMS.
4759 return;
4760 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004761 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 } finally {
4763 Binder.restoreCallingIdentity(identity);
4764 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004765 }
4766
4767 /**
4768 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4769 * feature or {@link null} if the service is not available. If the feature is available, the
4770 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4771 */
4772 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004773 IImsServiceFeatureCallback callback) {
4774 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004775
4776 final long identity = Binder.clearCallingIdentity();
4777 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004778 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004779 // may happen if the device does not support IMS.
4780 return null;
4781 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004782 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 } finally {
4784 Binder.restoreCallingIdentity(identity);
4785 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004786 }
4787
4788 /**
4789 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4790 * feature during emergency calling or {@link null} if the service is not available. If the
4791 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4792 * listener for feature updates.
4793 */
4794 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4795 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004796
4797 final long identity = Binder.clearCallingIdentity();
4798 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004799 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004800 // may happen if the device does not support IMS.
4801 return null;
4802 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004803 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004804 } finally {
4805 Binder.restoreCallingIdentity(identity);
4806 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004807 }
4808
Brad Ebinger5f64b052017-12-14 14:26:15 -08004809 /**
4810 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004811 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004812 */
4813 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4814 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815
4816 final long identity = Binder.clearCallingIdentity();
4817 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004818 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004819 // may happen if the device does not support IMS.
4820 return null;
4821 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004822 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004823 } finally {
4824 Binder.restoreCallingIdentity(identity);
4825 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004826 }
4827
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004828 /**
4829 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004830 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004831 */
4832 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004834
4835 final long identity = Binder.clearCallingIdentity();
4836 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004837 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004838 // may happen if the device does not support IMS.
4839 return null;
4840 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004841 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004842 } finally {
4843 Binder.restoreCallingIdentity(identity);
4844 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004845 }
4846
Brad Ebinger884c07b2018-02-15 16:17:40 -08004847 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004848 * Sets the ImsService Package Name that Telephony will bind to.
4849 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004850 * @param slotIndex the slot ID that the ImsService should bind for.
4851 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004852 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004853 * @param featureTypes An integer array of feature types associated with a packageName.
4854 * @param packageName The name of the package that the current configuration will be replaced
4855 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004856 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004857 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004858 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4859 int[] featureTypes, String packageName) {
4860 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4861 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4863 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004864 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004865
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004866 final long identity = Binder.clearCallingIdentity();
4867 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004868 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004869 // may happen if the device does not support IMS.
4870 return false;
4871 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004872 Map<Integer, String> featureConfig = new HashMap<>();
4873 for (int featureType : featureTypes) {
4874 featureConfig.put(featureType, packageName);
4875 }
4876 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4877 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004878 } finally {
4879 Binder.restoreCallingIdentity(identity);
4880 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004881 }
4882
4883 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004884 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004885 *
4886 * @param slotId The slot that the ImsService is associated with.
4887 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4888 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004889 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004890 * @return the package name of the ImsService configuration.
4891 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004892 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4893 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004894 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004895 TelephonyPermissions
4896 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4897 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4898 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004899
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900 final long identity = Binder.clearCallingIdentity();
4901 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004902 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004903 // may happen if the device does not support IMS.
4904 return "";
4905 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004906 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004907 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4908 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909 } finally {
4910 Binder.restoreCallingIdentity(identity);
4911 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004912 }
4913
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004914 /**
4915 * Get the MmTelFeature state associated with the requested subscription id.
4916 * @param subId The subscription that the MmTelFeature is associated with.
4917 * @param callback A callback with an integer containing the
4918 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4919 */
4920 @Override
4921 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4922 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4923 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4924 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4925 "IMS not available on device.");
4926 }
4927 final long token = Binder.clearCallingIdentity();
4928 try {
4929 int slotId = getSlotIndex(subId);
4930 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4931 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4932 + subId + "'");
4933 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4934 }
4935 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4936 try {
4937 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4938 } catch (RemoteException e) {
4939 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4940 + "Ignore");
4941 }
4942 });
4943 } finally {
4944 Binder.restoreCallingIdentity(token);
4945 }
4946 }
4947
Wink Saville36469e72014-06-11 15:17:00 -07004948 public void setImsRegistrationState(boolean registered) {
4949 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950
4951 final long identity = Binder.clearCallingIdentity();
4952 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004953 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 } finally {
4955 Binder.restoreCallingIdentity(identity);
4956 }
Wink Saville36469e72014-06-11 15:17:00 -07004957 }
4958
4959 /**
Stuart Scott54788802015-03-30 13:18:01 -07004960 * Set the network selection mode to automatic.
4961 *
4962 */
4963 @Override
4964 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4966 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967
Pengquan Menge92a50d2018-09-21 15:54:48 -07004968 if (!isActiveSubscription(subId)) {
4969 return;
4970 }
4971
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972 final long identity = Binder.clearCallingIdentity();
4973 try {
4974 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4975 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4976 } finally {
4977 Binder.restoreCallingIdentity(identity);
4978 }
Stuart Scott54788802015-03-30 13:18:01 -07004979 }
4980
Pengquan Mengea84e042018-09-20 14:57:26 -07004981 /**
4982 * Ask the radio to connect to the input network and change selection mode to manual.
4983 *
4984 * @param subId the id of the subscription.
4985 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4986 * the operator to attach to.
4987 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4988 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4989 * normal network selection next time.
4990 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004991 */
4992 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004993 public boolean setNetworkSelectionModeManual(
4994 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4996 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004997
4998 if (!isActiveSubscription(subId)) {
4999 return false;
5000 }
5001
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002 final long identity = Binder.clearCallingIdentity();
5003 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005004 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005006 if (DBG) {
5007 log("setNetworkSelectionModeManual: subId: " + subId
5008 + " operator: " + operatorInfo);
5009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5011 } finally {
5012 Binder.restoreCallingIdentity(identity);
5013 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005014 }
5015
5016 /**
5017 * Scans for available networks.
5018 */
5019 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005020 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5021 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5023 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005024 LocationAccessPolicy.LocationPermissionResult locationResult =
5025 LocationAccessPolicy.checkLocationPermission(mApp,
5026 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5027 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005028 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005029 .setCallingPid(Binder.getCallingPid())
5030 .setCallingUid(Binder.getCallingUid())
5031 .setMethod("getCellNetworkScanResults")
5032 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5033 .build());
5034 switch (locationResult) {
5035 case DENIED_HARD:
5036 throw new SecurityException("Not allowed to access scan results -- location");
5037 case DENIED_SOFT:
5038 return null;
5039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005040
Pengquan Menga1bb6272018-09-06 09:59:22 -07005041 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042 try {
5043 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005044 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 } finally {
5047 Binder.restoreCallingIdentity(identity);
5048 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005049 }
5050
5051 /**
yinxub1bed742017-04-17 11:45:04 -07005052 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005053 *
yinxub1bed742017-04-17 11:45:04 -07005054 * @param subId id of the subscription
5055 * @param request contains the radio access networks with bands/channels to scan
5056 * @param messenger callback messenger for scan results or errors
5057 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005058 * @return the id of the requested scan which can be used to stop the scan.
5059 */
5060 @Override
5061 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005062 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5064 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005065 LocationAccessPolicy.LocationPermissionResult locationResult =
5066 LocationAccessPolicy.checkLocationPermission(mApp,
5067 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5068 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005069 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005070 .setCallingPid(Binder.getCallingPid())
5071 .setCallingUid(Binder.getCallingUid())
5072 .setMethod("requestNetworkScan")
5073 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5074 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005075 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005076 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005077 if (e != null) {
5078 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5079 throw e;
5080 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005081 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005082 return TelephonyScanManager.INVALID_SCAN_ID;
5083 }
5084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 }
Hall Liu912dfd32019-04-25 14:02:26 -07005086 int callingUid = Binder.getCallingUid();
5087 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005088 final long identity = Binder.clearCallingIdentity();
5089 try {
5090 return mNetworkScanRequestTracker.startNetworkScan(
5091 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005092 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005093 } finally {
5094 Binder.restoreCallingIdentity(identity);
5095 }
yinxu504e1392017-04-12 16:03:22 -07005096 }
5097
Hall Liub2ac8ef2019-02-28 15:56:23 -08005098 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005099 NetworkScanRequest request, int subId) {
5100 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5101 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5102 boolean hasNetworkScanPermission =
5103 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5104 == PERMISSION_GRANTED;
5105
5106 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5107 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5108 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005109 }
5110
5111 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5112 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005113 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5114 return new SecurityException("Specific channels must not be"
5115 + " scanned without location access.");
5116 }
5117 }
5118 }
5119
Hall Liub2ac8ef2019-02-28 15:56:23 -08005120 return null;
5121 }
5122
yinxu504e1392017-04-12 16:03:22 -07005123 /**
5124 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005125 *
5126 * @param subId id of the subscription
5127 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005128 */
5129 @Override
5130 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005131 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5132 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133
Hall Liu912dfd32019-04-25 14:02:26 -07005134 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135 final long identity = Binder.clearCallingIdentity();
5136 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005137 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138 } finally {
5139 Binder.restoreCallingIdentity(identity);
5140 }
yinxu504e1392017-04-12 16:03:22 -07005141 }
5142
5143 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005144 * Get the calculated preferred network type.
5145 * Used for debugging incorrect network type.
5146 *
5147 * @return the preferred network type, defined in RILConstants.java.
5148 */
5149 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005150 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005151 final Phone defaultPhone = getDefaultPhone();
5152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005153 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005154 return RILConstants.PREFERRED_NETWORK_MODE;
5155 }
5156
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005157 final long identity = Binder.clearCallingIdentity();
5158 try {
5159 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005160 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161 } finally {
5162 Binder.restoreCallingIdentity(identity);
5163 }
Junda Liu84d15a22014-07-02 11:21:04 -07005164 }
5165
5166 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005167 * Get the preferred network type.
5168 * Used for device configuration by some CDMA operators.
5169 *
5170 * @return the preferred network type, defined in RILConstants.java.
5171 */
5172 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005173 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005174 TelephonyPermissions
5175 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5176 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177
5178 final long identity = Binder.clearCallingIdentity();
5179 try {
5180 if (DBG) log("getPreferredNetworkType");
5181 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5182 int networkType = (result != null ? result[0] : -1);
5183 if (DBG) log("getPreferredNetworkType: " + networkType);
5184 return networkType;
5185 } finally {
5186 Binder.restoreCallingIdentity(identity);
5187 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005188 }
5189
5190 /**
5191 * Set the preferred network type.
5192 * Used for device configuration by some CDMA operators.
5193 *
5194 * @param networkType the preferred network type, defined in RILConstants.java.
5195 * @return true on success; false on any failure.
5196 */
5197 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005198 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5200 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201
5202 final long identity = Binder.clearCallingIdentity();
5203 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005204 Settings.Global.putInt(mApp.getContentResolver(),
5205 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5206 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 } finally {
5208 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005209 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005210 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005211
5212 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005213 * Get the allowed network types that store in the telephony provider.
5214 *
5215 * @param subId the id of the subscription.
5216 * @return allowedNetworkTypes the allowed network types.
5217 */
5218 @Override
5219 public long getAllowedNetworkTypes(int subId) {
5220 TelephonyPermissions
5221 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5222 mApp, subId, "getAllowedNetworkTypes");
5223
5224 final long identity = Binder.clearCallingIdentity();
5225 try {
5226 return SubscriptionManager.getLongSubscriptionProperty(
5227 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
5231 }
5232
5233 /**
5234 * Set the allowed network types.
5235 *
5236 * @param subId the id of the subscription.
5237 * @param allowedNetworkTypes the allowed network types.
5238 * @return true on success; false on any failure.
5239 */
5240 @Override
5241 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5243 mApp, subId, "setAllowedNetworkTypes");
5244 final long identity = Binder.clearCallingIdentity();
5245 try {
5246 SubscriptionManager.setSubscriptionProperty(subId,
5247 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5248 String.valueOf(allowedNetworkTypes));
5249 return setPreferredNetworkTypesInternal(subId);
5250 } finally {
5251 Binder.restoreCallingIdentity(identity);
5252 }
5253 }
5254
5255 private boolean setPreferredNetworkTypesInternal(int subId) {
5256 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5257 Settings.Global.getInt(mApp.getContentResolver(),
5258 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5259 RILConstants.PREFERRED_NETWORK_MODE));
5260 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5261 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5262 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5263 (int) (networkTypeBitMask & allowedNetworkTypes));
5264
5265 if (DBG) {
5266 log("setPreferredNetworkTypesInternal: subId " + subId
5267 + " networkTypes " + networkTypeBitMask
5268 + " allowedNetworkTypes " + allowedNetworkTypes
5269 + " networkMode " + networkMode);
5270 }
5271
5272 Boolean success = (Boolean) sendRequest(
5273 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5274 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5275 return success;
5276 }
5277
5278 /**
Miaoa84611c2019-03-15 09:21:10 +08005279 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005280 *
Miaoa84611c2019-03-15 09:21:10 +08005281 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005282 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005283 * @hide
5284 */
5285 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005286 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005287 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005289 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 try {
Miaoa84611c2019-03-15 09:21:10 +08005291 if (phone != null) {
5292 return phone.hasMatchedTetherApnSetting();
5293 } else {
5294 return false;
5295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296 } finally {
5297 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005298 }
Junda Liu475951f2014-11-07 16:45:03 -08005299 }
5300
5301 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005302 * Set mobile data enabled
5303 * Used by the user through settings etc to turn on/off mobile data
5304 *
5305 * @param enable {@code true} turn turn data on, else {@code false}
5306 */
5307 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005308 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5310 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311
5312 final long identity = Binder.clearCallingIdentity();
5313 try {
5314 int phoneId = mSubscriptionController.getPhoneId(subId);
5315 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5316 Phone phone = PhoneFactory.getPhone(phoneId);
5317 if (phone != null) {
5318 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005319 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005321 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322 }
5323 } finally {
5324 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005325 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005326 }
5327
5328 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005329 * Enable or disable always reporting signal strength changes from radio.
5330 *
5331 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5332 */
5333 @Override
5334 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5335 enforceModifyPermission();
5336 enforceSystemCaller();
5337
5338 final long identity = Binder.clearCallingIdentity();
5339 final Phone phone = getPhone(subId);
5340 try {
5341 if (phone != null) {
5342 if (DBG) {
5343 log("setAlwaysReportSignalStrength: subId=" + subId
5344 + " isEnable=" + isEnable);
5345 }
5346 phone.setAlwaysReportSignalStrength(isEnable);
5347 } else {
5348 loge("setAlwaysReportSignalStrength: no phone found for subId="
5349 + subId);
5350 }
5351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
5354 }
5355
5356 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005357 * Get the user enabled state of Mobile Data.
5358 *
5359 * TODO: remove and use isUserDataEnabled.
5360 * This can't be removed now because some vendor codes
5361 * calls through ITelephony directly while they should
5362 * use TelephonyManager.
5363 *
5364 * @return true on enabled
5365 */
5366 @Override
5367 public boolean getDataEnabled(int subId) {
5368 return isUserDataEnabled(subId);
5369 }
5370
5371 /**
5372 * Get whether mobile data is enabled per user setting.
5373 *
5374 * There are other factors deciding whether mobile data is actually enabled, but they are
5375 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005376 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005377 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005378 *
5379 * @return {@code true} if data is enabled else {@code false}
5380 */
5381 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005382 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005383 try {
5384 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5385 null);
5386 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5388 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005389 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005390
5391 final long identity = Binder.clearCallingIdentity();
5392 try {
5393 int phoneId = mSubscriptionController.getPhoneId(subId);
5394 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5395 Phone phone = PhoneFactory.getPhone(phoneId);
5396 if (phone != null) {
5397 boolean retVal = phone.isUserDataEnabled();
5398 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5399 return retVal;
5400 } else {
5401 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5402 return false;
5403 }
5404 } finally {
5405 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005406 }
5407 }
5408
5409 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005410 * Checks if the device is capable of mobile data by considering whether whether the
5411 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5412 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005413 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005414 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005415 */
5416 @Override
5417 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005418 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419
5420 final long identity = Binder.clearCallingIdentity();
5421 try {
5422 int phoneId = mSubscriptionController.getPhoneId(subId);
5423 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5424 Phone phone = PhoneFactory.getPhone(phoneId);
5425 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005426 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005427 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5428 return retVal;
5429 } else {
5430 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5431 return false;
5432 }
5433 } finally {
5434 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005435 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005436 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005437
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005438 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5439 Phone phone) {
5440 //load access rules from carrier configs, and check those as well: b/139133814
5441 SubscriptionController subController = SubscriptionController.getInstance();
5442 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5443 || subController == null) return privilegeFromSim;
5444
5445 int uid = Binder.getCallingUid();
5446 PackageManager pkgMgr = phone.getContext().getPackageManager();
5447 String[] packages = pkgMgr.getPackagesForUid(uid);
5448
5449 final long identity = Binder.clearCallingIdentity();
5450 try {
5451 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5452 SubscriptionManager subManager = (SubscriptionManager)
5453 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5454 for (String pkg : packages) {
5455 if (subManager.canManageSubscription(subInfo, pkg)) {
5456 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5457 }
5458 }
5459 return privilegeFromSim;
5460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
5463 }
5464
5465 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5466 String pkgName) {
5467 //load access rules from carrier configs, and check those as well: b/139133814
5468 SubscriptionController subController = SubscriptionController.getInstance();
5469 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5470 || subController == null) return privilegeFromSim;
5471
5472 final long identity = Binder.clearCallingIdentity();
5473 try {
5474 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5475 SubscriptionManager subManager = (SubscriptionManager)
5476 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5477 return subManager.canManageSubscription(subInfo, pkgName)
5478 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5479 } finally {
5480 Binder.restoreCallingIdentity(identity);
5481 }
5482 }
5483
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005484 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005485 public int getCarrierPrivilegeStatus(int subId) {
5486 final Phone phone = getPhone(subId);
5487 if (phone == null) {
5488 loge("getCarrierPrivilegeStatus: Invalid subId");
5489 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5490 }
5491 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005492 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005493 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005494 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5495 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005496
5497 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5498 card.getCarrierPrivilegeStatusForCurrentTransaction(
5499 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005500 }
Junda Liu29340342014-07-10 15:23:27 -07005501
5502 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005503 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005504 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005505 final Phone phone = getPhone(subId);
5506 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005507 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005508 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5509 }
5510 UiccProfile profile =
5511 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5512 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005513 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005514 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5515 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005516 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005517 profile.getCarrierPrivilegeStatusForUid(
5518 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005519 }
5520
5521 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005522 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5523 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005524 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005525 }
5526
5527 int phoneId = SubscriptionManager.getPhoneId(subId);
5528 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005529 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005530 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005531 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5532 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005533 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5534 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5535 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005536 }
5537
5538 @Override
5539 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005540 if (TextUtils.isEmpty(pkgName))
5541 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005542 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5543 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5544 UiccCard card = UiccController.getInstance().getUiccCard(i);
5545 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005546 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005547 continue;
5548 }
5549
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005550 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5551 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5552 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005553 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5554 break;
5555 }
5556 }
5557
5558 return result;
Junda Liu29340342014-07-10 15:23:27 -07005559 }
Derek Tan89e89d42014-07-08 17:00:10 -07005560
5561 @Override
Junda Liue64de782015-04-16 17:19:16 -07005562 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5563 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5564 loge("phoneId " + phoneId + " is not valid.");
5565 return null;
5566 }
5567 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005568 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005569 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005570 return null ;
5571 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005572 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005573 }
5574
Amith Yamasani6e118872016-02-19 12:53:51 -08005575 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005576 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005577 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005578 List<String> privilegedPackages = new ArrayList<>();
5579 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005580 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5581 // has UICC in that slot.
5582 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005583 if (card.hasCarrierPrivilegeRules()) {
5584 if (packages == null) {
5585 // Only check packages in user 0 for now
5586 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005587 PackageManager.MATCH_DISABLED_COMPONENTS
5588 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005589 | PackageManager.GET_SIGNING_CERTIFICATES,
5590 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005591 }
5592 for (int p = packages.size() - 1; p >= 0; p--) {
5593 PackageInfo pkgInfo = packages.get(p);
5594 if (pkgInfo != null && pkgInfo.packageName != null
5595 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005596 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005597 privilegedPackages.add(pkgInfo.packageName);
5598 }
5599 }
5600 }
5601 }
5602 return privilegedPackages;
5603 }
5604
chen xuf7e9fe82019-05-09 19:31:02 -07005605 @Override
5606 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005607 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5608
5609 final long identity = Binder.clearCallingIdentity();
5610
chen xuf7e9fe82019-05-09 19:31:02 -07005611 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005612 try {
5613 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5614 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5615 }
5616 } finally {
5617 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005618 }
5619 return privilegedPackages;
5620 }
5621
Wink Savilleb564aae2014-10-23 10:18:09 -07005622 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005623 final Phone phone = getPhone(subId);
5624 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005625 if (card == null) {
5626 loge("getIccId: No UICC");
5627 return null;
5628 }
5629 String iccId = card.getIccId();
5630 if (TextUtils.isEmpty(iccId)) {
5631 loge("getIccId: ICC ID is null or empty.");
5632 return null;
5633 }
5634 return iccId;
5635 }
5636
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005637 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005638 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5639 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005640 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005641 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643 final long identity = Binder.clearCallingIdentity();
5644 try {
5645 final String iccId = getIccId(subId);
5646 final Phone phone = getPhone(subId);
5647 if (phone == null) {
5648 return false;
5649 }
5650 final String subscriberId = phone.getSubscriberId();
5651
5652 if (DBG_MERGE) {
5653 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5654 + subscriberId + " to " + number);
5655 }
5656
5657 if (TextUtils.isEmpty(iccId)) {
5658 return false;
5659 }
5660
5661 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5662
5663 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5664 if (alphaTag == null) {
5665 editor.remove(alphaTagPrefKey);
5666 } else {
5667 editor.putString(alphaTagPrefKey, alphaTag);
5668 }
5669
5670 // Record both the line number and IMSI for this ICCID, since we need to
5671 // track all merged IMSIs based on line number
5672 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5673 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5674 if (number == null) {
5675 editor.remove(numberPrefKey);
5676 editor.remove(subscriberPrefKey);
5677 } else {
5678 editor.putString(numberPrefKey, number);
5679 editor.putString(subscriberPrefKey, subscriberId);
5680 }
5681
5682 editor.commit();
5683 return true;
5684 } finally {
5685 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005686 }
Derek Tan7226c842014-07-02 17:42:23 -07005687 }
5688
5689 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005690 public String getLine1NumberForDisplay(int subId, String callingPackage,
5691 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005692 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005694 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005695 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005696 return null;
5697 }
Derek Tan97ebb422014-09-05 16:55:38 -07005698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 final long identity = Binder.clearCallingIdentity();
5700 try {
5701 String iccId = getIccId(subId);
5702 if (iccId != null) {
5703 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5704 if (DBG_MERGE) {
5705 log("getLine1NumberForDisplay returning "
5706 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5707 }
5708 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005709 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5711 return null;
5712 } finally {
5713 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005714 }
Derek Tan7226c842014-07-02 17:42:23 -07005715 }
5716
5717 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005718 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5719 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005720 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005721 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005722 return null;
5723 }
Derek Tan97ebb422014-09-05 16:55:38 -07005724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725 final long identity = Binder.clearCallingIdentity();
5726 try {
5727 String iccId = getIccId(subId);
5728 if (iccId != null) {
5729 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5730 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5731 }
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 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005737
5738 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005739 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5740 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005741 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5742 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005743 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005744 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005745 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005746 return null;
5747 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005748
Jordan Liub49b04b2019-05-06 14:45:15 -07005749 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5750 // the process, where TelephonyManager was instantiated.
5751 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005752 final long identity = Binder.clearCallingIdentity();
5753 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005754 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005755 final TelephonyManager tele = TelephonyManager.from(context);
5756 final SubscriptionManager sub = SubscriptionManager.from(context);
5757
5758 // Figure out what subscribers are currently active
5759 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760
Jordan Liub49b04b2019-05-06 14:45:15 -07005761 // Only consider subs which match the current subId
5762 // This logic can be simplified. See b/131189269 for progress.
5763 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005764 activeSubscriberIds.add(tele.getSubscriberId(subId));
5765 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766
5767 // First pass, find a number override for an active subscriber
5768 String mergeNumber = null;
5769 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5770 for (String key : prefs.keySet()) {
5771 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5772 final String subscriberId = (String) prefs.get(key);
5773 if (activeSubscriberIds.contains(subscriberId)) {
5774 final String iccId = key.substring(
5775 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5776 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5777 mergeNumber = (String) prefs.get(numberKey);
5778 if (DBG_MERGE) {
5779 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5780 + " for active subscriber " + subscriberId);
5781 }
5782 if (!TextUtils.isEmpty(mergeNumber)) {
5783 break;
5784 }
5785 }
5786 }
5787 }
5788
5789 // Shortcut when no active merged subscribers
5790 if (TextUtils.isEmpty(mergeNumber)) {
5791 return null;
5792 }
5793
5794 // Second pass, find all subscribers under that line override
5795 final ArraySet<String> result = new ArraySet<>();
5796 for (String key : prefs.keySet()) {
5797 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5798 final String number = (String) prefs.get(key);
5799 if (mergeNumber.equals(number)) {
5800 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5801 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5802 final String subscriberId = (String) prefs.get(subscriberKey);
5803 if (!TextUtils.isEmpty(subscriberId)) {
5804 result.add(subscriberId);
5805 }
5806 }
5807 }
5808 }
5809
5810 final String[] resultArray = result.toArray(new String[result.size()]);
5811 Arrays.sort(resultArray);
5812 if (DBG_MERGE) {
5813 Slog.d(LOG_TAG,
5814 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5815 }
5816 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005817 } finally {
5818 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005819 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005820 }
5821
5822 @Override
zoey chen38003472019-12-13 17:16:31 +08005823 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5824 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005825
5826 final long identity = Binder.clearCallingIdentity();
5827 try {
5828 final TelephonyManager telephonyManager = mApp.getSystemService(
5829 TelephonyManager.class);
5830 String subscriberId = telephonyManager.getSubscriberId(subId);
5831 if (subscriberId == null) {
5832 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005833 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005834 + subId);
5835 }
5836 return null;
5837 }
5838
5839 final SubscriptionInfo info = SubscriptionController.getInstance()
5840 .getSubscriptionInfo(subId);
5841 final ParcelUuid groupUuid = info.getGroupUuid();
5842 // If it doesn't belong to any group, return just subscriberId of itself.
5843 if (groupUuid == null) {
5844 return new String[]{subscriberId};
5845 }
5846
5847 // Get all subscriberIds from the group.
5848 final List<String> mergedSubscriberIds = new ArrayList<>();
5849 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005850 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5851 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005852 for (SubscriptionInfo subInfo : groupInfos) {
5853 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5854 if (subscriberId != null) {
5855 mergedSubscriberIds.add(subscriberId);
5856 }
5857 }
5858
5859 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5860 } finally {
5861 Binder.restoreCallingIdentity(identity);
5862
5863 }
5864 }
5865
5866 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005867 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005868 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005869 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005870
5871 final long identity = Binder.clearCallingIdentity();
5872 try {
5873 final Phone phone = getPhone(subId);
5874 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5875 } finally {
5876 Binder.restoreCallingIdentity(identity);
5877 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005878 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005879
5880 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005881 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005882 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5883 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005884 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5885 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005886
5887 final long identity = Binder.clearCallingIdentity();
5888 try {
5889 final Phone phone = getPhone(subId);
5890 if (phone == null) {
5891 return false;
5892 }
5893 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5894 cdmaNonRoamingList);
5895 } finally {
5896 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005897 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005898 }
5899
5900 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005901 @Deprecated
5902 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5903 enforceModifyPermission();
5904
5905 int returnValue = 0;
5906 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005907 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005908 if(result.exception == null) {
5909 if (result.result != null) {
5910 byte[] responseData = (byte[])(result.result);
5911 if(responseData.length > oemResp.length) {
5912 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5913 responseData.length + "bytes. Buffer Size is " +
5914 oemResp.length + "bytes.");
5915 }
5916 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5917 returnValue = responseData.length;
5918 }
5919 } else {
5920 CommandException ex = (CommandException) result.exception;
5921 returnValue = ex.getCommandError().ordinal();
5922 if(returnValue > 0) returnValue *= -1;
5923 }
5924 } catch (RuntimeException e) {
5925 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5926 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5927 if(returnValue > 0) returnValue *= -1;
5928 }
5929
5930 return returnValue;
5931 }
5932
5933 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005934 public void setRadioCapability(RadioAccessFamily[] rafs) {
5935 try {
5936 ProxyController.getInstance().setRadioCapability(rafs);
5937 } catch (RuntimeException e) {
5938 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5939 }
5940 }
5941
5942 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005943 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005944 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005945 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005946 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005947 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005948 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 final long identity = Binder.clearCallingIdentity();
5950 try {
chen xub97461a2018-10-26 14:17:57 -07005951 TelephonyPermissions
5952 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5953 mApp, phone.getSubId(), "getRadioAccessFamily");
5954 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955 } finally {
5956 Binder.restoreCallingIdentity(identity);
5957 }
chen xub97461a2018-10-26 14:17:57 -07005958 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005959 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005960
5961 @Override
5962 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005963 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005964 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965
5966 final long identity = Binder.clearCallingIdentity();
5967 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005968 ImsManager.getInstance(defaultPhone.getContext(),
5969 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 } finally {
5971 Binder.restoreCallingIdentity(identity);
5972 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005973 }
5974
5975 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005976 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005977 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5979 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005980 return false;
5981 }
Svet Ganovb320e182015-04-16 12:30:10 -07005982
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983 final long identity = Binder.clearCallingIdentity();
5984 try {
5985 // Check the user preference and the system-level IMS setting. Even if the user has
5986 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5987 // In the long run, we may instead need to check if there exists a connection service
5988 // which can support video calling.
5989 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005990 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 return imsManager.isVtEnabledByPlatform()
5992 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5993 && imsManager.isVtEnabledByUser();
5994 } finally {
5995 Binder.restoreCallingIdentity(identity);
5996 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005997 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005998
Andrew Leea1239f22015-03-02 17:44:07 -08005999 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006000 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6001 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006003 mApp, subId, callingPackage, callingFeatureId,
6004 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005 return false;
6006 }
6007
6008 final long identity = Binder.clearCallingIdentity();
6009 try {
6010 CarrierConfigManager configManager =
6011 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006012 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6014 } finally {
6015 Binder.restoreCallingIdentity(identity);
6016 }
Andrew Leea1239f22015-03-02 17:44:07 -08006017 }
6018
6019 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006020 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006022 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006023 return false;
6024 }
6025
6026 final long identity = Binder.clearCallingIdentity();
6027 try {
6028 CarrierConfigManager configManager =
6029 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006030 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6032 } finally {
6033 Binder.restoreCallingIdentity(identity);
6034 }
Andrew Leea1239f22015-03-02 17:44:07 -08006035 }
6036
Andrew Lee9431b832015-03-09 18:46:45 -07006037 @Override
6038 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006039 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006040 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006041 }
6042
6043 @Override
6044 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 final long identity = Binder.clearCallingIdentity();
6046 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006047 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 } finally {
6049 Binder.restoreCallingIdentity(identity);
6050 }
Andrew Lee9431b832015-03-09 18:46:45 -07006051 }
6052
Hall Liuf6668912018-10-31 17:05:23 -07006053 /**
6054 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6055 * support for the feature and device firmware support.
6056 *
6057 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6058 */
6059 @Override
6060 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006062 final Phone phone = getPhone(subscriptionId);
6063 if (phone == null) {
6064 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6065 return false;
6066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006068 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6070 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006071 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 return isCarrierSupported && isDeviceSupported;
6073 } finally {
6074 Binder.restoreCallingIdentity(identity);
6075 }
Hall Liu98187582018-01-22 19:15:32 -08006076 }
6077
Hall Liuf6668912018-10-31 17:05:23 -07006078 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006079 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6080 * RTT setting, will return true if the device and carrier both support RTT.
6081 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006082 */
6083 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084 final long identity = Binder.clearCallingIdentity();
6085 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006086 boolean isRttSupported = isRttSupported(subscriptionId);
6087 boolean isUserRttSettingOn = Settings.Secure.getInt(
6088 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6089 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6090 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6091 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 } finally {
6093 Binder.restoreCallingIdentity(identity);
6094 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006095 }
6096
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006097 @Deprecated
6098 @Override
6099 public String getDeviceId(String callingPackage) {
6100 return getDeviceIdWithFeature(callingPackage, null);
6101 }
6102
Sanket Padawe7310cc72015-01-14 09:53:20 -08006103 /**
6104 * Returns the unique device ID of phone, for example, the IMEI for
6105 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6106 *
6107 * <p>Requires Permission:
6108 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6109 */
6110 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006111 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006112 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006113 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006114 return null;
6115 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006116 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006117 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006118 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006119 return null;
6120 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121
6122 final long identity = Binder.clearCallingIdentity();
6123 try {
6124 return phone.getDeviceId();
6125 } finally {
6126 Binder.restoreCallingIdentity(identity);
6127 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006128 }
6129
Ping Sunc67b7c22016-03-02 19:16:45 +08006130 /**
6131 * {@hide}
6132 * Returns the IMS Registration Status on a particular subid
6133 *
6134 * @param subId
6135 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006136 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006137 Phone phone = getPhone(subId);
6138 if (phone != null) {
6139 return phone.isImsRegistered();
6140 } else {
6141 return false;
6142 }
6143 }
6144
Santos Cordon7a1885b2015-02-03 11:15:19 -08006145 @Override
6146 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006147 final long identity = Binder.clearCallingIdentity();
6148 try {
6149 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6150 } finally {
6151 Binder.restoreCallingIdentity(identity);
6152 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006153 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006154
Tyler Gunnf70ed162019-04-03 15:28:53 -07006155 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006156 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006157 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006159 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006160 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6161 }
6162 final long identity = Binder.clearCallingIdentity();
6163 try {
6164 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6165 } finally {
6166 Binder.restoreCallingIdentity(identity);
6167 }
6168 }
6169
6170 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006171 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6172 final long identity = Binder.clearCallingIdentity();
6173 try {
6174 Phone phone = getPhone(subscriptionId);
6175 if (phone == null) {
6176 return null;
6177 }
6178 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6179 } finally {
6180 Binder.restoreCallingIdentity(identity);
6181 }
6182 }
6183
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006184 /**
6185 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006186 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006187 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188 final long identity = Binder.clearCallingIdentity();
6189 try {
6190 Phone phone = getPhone(subId);
6191 if (phone != null) {
6192 return phone.isWifiCallingEnabled();
6193 } else {
6194 return false;
6195 }
6196 } finally {
6197 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006198 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006199 }
6200
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006201 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006202 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006203 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006204 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006205 final long identity = Binder.clearCallingIdentity();
6206 try {
6207 Phone phone = getPhone(subId);
6208 if (phone != null) {
6209 return phone.isVideoEnabled();
6210 } else {
6211 return false;
6212 }
6213 } finally {
6214 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006215 }
6216 }
6217
6218 /**
6219 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6220 * defined in {@link ImsRegistrationImplBase}.
6221 */
6222 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006223 final long identity = Binder.clearCallingIdentity();
6224 try {
6225 Phone phone = getPhone(subId);
6226 if (phone != null) {
6227 return phone.getImsRegistrationTech();
6228 } else {
6229 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6230 }
6231 } finally {
6232 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006233 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006234 }
6235
Stuart Scott8eef64f2015-04-08 15:13:54 -07006236 @Override
6237 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006238 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006239 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6240 return;
6241 }
6242
Svet Ganovcc087f82015-05-12 20:35:54 -07006243 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006244
Svet Ganovcc087f82015-05-12 20:35:54 -07006245 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006246 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6247 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006248 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006249 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006250 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006251 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6252 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006253 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006254 // There has been issues when Sms raw table somehow stores orphan
6255 // fragments. They lead to garbled message when new fragments come
6256 // in and combined with those stale ones. In case this happens again,
6257 // user can reset all network settings which will clean up this table.
6258 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006259 // Clean up IMS settings as well here.
6260 int slotId = getSlotIndex(subId);
6261 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6262 ImsManager.getInstance(mApp, slotId).factoryReset();
6263 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006264
6265 // Erase modem config if erase modem on network setting is enabled.
6266 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6267 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6268 if (configValue != null && Boolean.parseBoolean(configValue)) {
6269 sendEraseModemConfig(getDefaultPhone());
6270 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006271 } finally {
6272 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006273 }
6274 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006275
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006276 private void cleanUpSmsRawTable(Context context) {
6277 ContentResolver resolver = context.getContentResolver();
6278 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6279 resolver.delete(uri, null, null);
6280 }
6281
Narayan Kamath1c496c22015-04-16 14:40:19 +01006282 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006283 public String getSimLocaleForSubscriber(int subId) {
6284 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6285 final Phone phone = getPhone(subId);
6286 if (phone == null) {
6287 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006288 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 final long identity = Binder.clearCallingIdentity();
6291 try {
chen xu5d3637b2019-01-21 23:31:38 -08006292 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006293 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006294 if (info == null) {
6295 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6296 return null;
6297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 // Try and fetch the locale from the carrier properties or from the SIM language
6299 // preferences (EF-PL and EF-LI)...
6300 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006302 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6303 if (localeFromDefaultSim != null) {
6304 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6305 if (DBG) log("Using locale from subId: " + subId + " locale: "
6306 + localeFromDefaultSim);
6307 return localeFromDefaultSim.toLanguageTag();
6308 } else {
6309 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310 }
6311 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006313 // The SIM language preferences only store a language (e.g. fr = French), not an
6314 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6315 // the SIM and carrier preferences does not include a country we add the country
6316 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006317 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006318 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006319 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006320 return mccLocale.toLanguageTag();
6321 }
6322
6323 if (DBG) log("No locale found - returning null");
6324 return null;
6325 } finally {
6326 Binder.restoreCallingIdentity(identity);
6327 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006328 }
6329
6330 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006331 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6332 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006333 }
6334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006335 /**
6336 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6337 */
6338 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006339 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6340 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006341 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006342
Chenjie Yu1ba97252018-01-11 18:16:20 -08006343 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006344 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006345
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006346 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006347 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6348 * representing the state of the modem.
6349 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006350 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6351 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006352 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006353 */
6354 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006355 public void requestModemActivityInfo(ResultReceiver result) {
6356 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006357 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358
6359 final long identity = Binder.clearCallingIdentity();
6360 try {
6361 ModemActivityInfo ret = null;
6362 synchronized (mLastModemActivityInfo) {
6363 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6364 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006365 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006366 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006368 int[] txTimeMs = info.getTransmitTimeMillis();
6369 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006370 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006371 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006372 }
6373 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006374 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6375 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376 mLastModemActivityInfo.setIdleTimeMillis(
6377 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006378 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6379 mLastModemActivityInfo.setReceiveTimeMillis(
6380 info.getReceiveTimeMillis() + mLastModemActivityInfo
6381 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006382 }
Chen Xud78231e2019-09-10 18:49:52 -07006383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6385 mLastModemActivityInfo.getSleepTimeMillis(),
6386 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006387 mLastModemActivityInfo.getTransmitTimeMillis(),
6388 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006389 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390 Bundle bundle = new Bundle();
6391 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6392 result.send(0, bundle);
6393 } finally {
6394 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006395 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006396 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006397
Siddharth Rayb8114062018-06-17 15:02:38 -07006398 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6399 // less than total activity duration.
6400 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6401 if (info == null) {
6402 return false;
6403 }
6404 int activityDurationMs =
6405 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6406 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006407 int[] txTimeMs = info.getTransmitTimeMillis();
6408 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6409 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006410 }
6411 return (info.isValid()
6412 && (info.getSleepTimeMillis() <= activityDurationMs)
6413 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006414 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006415 && (totalTxTimeMs <= activityDurationMs));
6416 }
6417
Jack Yu85bd38a2015-11-09 11:34:32 -08006418 /**
6419 * {@hide}
6420 * Returns the service state information on specified subscription.
6421 */
6422 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006423 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6424 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006425 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006426 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006427 return null;
6428 }
6429
Hall Liuf19c44f2018-11-27 14:38:17 -08006430 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6431 LocationAccessPolicy.checkLocationPermission(mApp,
6432 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6433 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006434 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006435 .setCallingPid(Binder.getCallingPid())
6436 .setCallingUid(Binder.getCallingUid())
6437 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006438 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006439 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6440 .build());
6441
6442 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6443 LocationAccessPolicy.checkLocationPermission(mApp,
6444 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6445 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006446 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006447 .setCallingPid(Binder.getCallingPid())
6448 .setCallingUid(Binder.getCallingUid())
6449 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006450 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006451 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6452 .build());
6453 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6454 boolean hasFinePermission =
6455 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6456 boolean hasCoarsePermission =
6457 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6458
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006459 final long identity = Binder.clearCallingIdentity();
6460 try {
6461 final Phone phone = getPhone(subId);
6462 if (phone == null) {
6463 return null;
6464 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006465
Hall Liuf19c44f2018-11-27 14:38:17 -08006466 ServiceState ss = phone.getServiceState();
6467
6468 // Scrub out the location info in ServiceState depending on what level of access
6469 // the caller has.
6470 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006471 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6472 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006473 } finally {
6474 Binder.restoreCallingIdentity(identity);
6475 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006476 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006477
6478 /**
6479 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6480 *
6481 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6482 * voicemail ringtone.
6483 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6484 * PhoneAccount.
6485 */
6486 @Override
6487 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006488 final long identity = Binder.clearCallingIdentity();
6489 try {
6490 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6491 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006492 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006493 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006495 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006499 }
6500
6501 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006502 * Sets the per-account voicemail ringtone.
6503 *
6504 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6505 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6506 *
6507 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6508 * voicemail ringtone.
6509 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6510 * PhoneAccount.
6511 */
6512 @Override
6513 public void setVoicemailRingtoneUri(String callingPackage,
6514 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006515 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006516 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006517 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6518 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6520 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6521 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006523
6524 final long identity = Binder.clearCallingIdentity();
6525 try {
6526 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6527 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006528 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006529 }
6530 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6531 } finally {
6532 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006533 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006534 }
6535
6536 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006537 * Returns whether vibration is set for voicemail notification in Phone settings.
6538 *
6539 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6540 * voicemail vibration setting.
6541 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6542 */
6543 @Override
6544 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545 final long identity = Binder.clearCallingIdentity();
6546 try {
6547 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6548 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006549 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006551
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6553 } finally {
6554 Binder.restoreCallingIdentity(identity);
6555 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006556 }
6557
Youhan Wange64578a2016-05-02 15:32:42 -07006558 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006559 * Sets the per-account voicemail vibration.
6560 *
6561 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6562 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6563 *
6564 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6565 * voicemail vibration setting.
6566 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6567 * specific PhoneAccount.
6568 */
6569 @Override
6570 public void setVoicemailVibrationEnabled(String callingPackage,
6571 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006572 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006573 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006574 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6575 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6577 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6578 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006579 }
6580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581 final long identity = Binder.clearCallingIdentity();
6582 try {
6583 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6584 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006585 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586 }
6587 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6588 } finally {
6589 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006590 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006591 }
6592
6593 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006594 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6595 *
6596 * @throws SecurityException if the caller does not have the required permission
6597 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006598 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006599 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006600 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006601 }
6602
6603 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006604 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6605 * permission.
6606 *
6607 * @throws SecurityException if the caller does not have the required permission
6608 */
6609 private void enforceSendSmsPermission() {
6610 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6611 }
6612
6613 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006614 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006615 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006616 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006617 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006618 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006619 final long identity = Binder.clearCallingIdentity();
6620 try {
6621 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006622 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006623 if (componentName == null) {
6624 throw new SecurityException(
6625 "Caller not current active visual voicemail package[null]");
6626 }
6627 String vvmPackage = componentName.getPackageName();
6628 if (!callingPackage.equals(vvmPackage)) {
6629 throw new SecurityException("Caller not current active visual voicemail package["
6630 + vvmPackage + "]");
6631 }
6632 } finally {
6633 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006634 }
6635 }
6636
6637 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006638 * Return the application ID for the app type.
6639 *
6640 * @param subId the subscription ID that this request applies to.
6641 * @param appType the uicc app type.
6642 * @return Application ID for specificied app type, or null if no uicc.
6643 */
6644 @Override
6645 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006646 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006647 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006648
6649 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006650 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006651 if (phone == null) {
6652 return null;
6653 }
6654 String aid = null;
6655 try {
6656 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6657 .getApplicationByType(appType).getAid();
6658 } catch (Exception e) {
6659 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6660 }
6661 return aid;
6662 } finally {
6663 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006664 }
Youhan Wange64578a2016-05-02 15:32:42 -07006665 }
6666
Youhan Wang4001d252016-05-11 10:29:41 -07006667 /**
6668 * Return the Electronic Serial Number.
6669 *
6670 * @param subId the subscription ID that this request applies to.
6671 * @return ESN or null if error.
6672 */
6673 @Override
6674 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006675 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006676 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006677
6678 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006679 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006680 if (phone == null) {
6681 return null;
6682 }
6683 String esn = null;
6684 try {
6685 esn = phone.getEsn();
6686 } catch (Exception e) {
6687 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6688 }
6689 return esn;
6690 } finally {
6691 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006692 }
Youhan Wang4001d252016-05-11 10:29:41 -07006693 }
6694
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006695 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006696 * Return the Preferred Roaming List Version.
6697 *
6698 * @param subId the subscription ID that this request applies to.
6699 * @return PRLVersion or null if error.
6700 */
6701 @Override
6702 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006703 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006704 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705
6706 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006707 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 if (phone == null) {
6709 return null;
6710 }
6711 String cdmaPrlVersion = null;
6712 try {
6713 cdmaPrlVersion = phone.getCdmaPrlVersion();
6714 } catch (Exception e) {
6715 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6716 }
6717 return cdmaPrlVersion;
6718 } finally {
6719 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006720 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006721 }
6722
6723 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006724 * Get snapshot of Telephony histograms
6725 * @return List of Telephony histograms
6726 * @hide
6727 */
6728 @Override
6729 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6731 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732
6733 final long identity = Binder.clearCallingIdentity();
6734 try {
6735 return RIL.getTelephonyRILTimingHistograms();
6736 } finally {
6737 Binder.restoreCallingIdentity(identity);
6738 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006739 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006740
6741 /**
6742 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006743 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6744 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006745 * Require system privileges. In the future we may add this to carrier APIs.
6746 *
Michele Berionne482f8202018-11-27 18:57:59 -08006747 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006748 */
6749 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006750 @TelephonyManager.SetCarrierRestrictionResult
6751 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006752 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006753 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006754
Michele Berionne482f8202018-11-27 18:57:59 -08006755 if (carrierRestrictionRules == null) {
6756 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006757 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 final long identity = Binder.clearCallingIdentity();
6760 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006761 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006762 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 } finally {
6764 Binder.restoreCallingIdentity(identity);
6765 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006766 }
6767
6768 /**
6769 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006770 * Get the allowed carrier list and the excluded carrier list, including the priority between
6771 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006772 * Require system privileges. In the future we may add this to carrier APIs.
6773 *
Michele Berionne482f8202018-11-27 18:57:59 -08006774 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006775 */
6776 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006777 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006778 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006779 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780
6781 final long identity = Binder.clearCallingIdentity();
6782 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006783 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6784 if (response instanceof CarrierRestrictionRules) {
6785 return (CarrierRestrictionRules) response;
6786 }
6787 // Response is an Exception of some kind,
6788 // which is signalled to the user as a NULL retval
6789 return null;
6790 } catch (Exception e) {
6791 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6792 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793 } finally {
6794 Binder.restoreCallingIdentity(identity);
6795 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006796 }
6797
fionaxu59545b42016-05-25 15:53:37 -07006798 /**
6799 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6800 * @param subId the subscription ID that this action applies to.
6801 * @param enabled control enable or disable metered apns.
6802 * {@hide}
6803 */
6804 @Override
6805 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6806 enforceModifyPermission();
6807 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006808
6809 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006810 if (phone == null) {
6811 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6812 return;
6813 }
6814 try {
6815 phone.carrierActionSetMeteredApnsEnabled(enabled);
6816 } catch (Exception e) {
6817 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006818 } finally {
6819 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006820 }
6821 }
6822
6823 /**
6824 * Action set from carrier signalling broadcast receivers to enable/disable radio
6825 * @param subId the subscription ID that this action applies to.
6826 * @param enabled control enable or disable radio.
6827 * {@hide}
6828 */
6829 @Override
6830 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6831 enforceModifyPermission();
6832 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006833
6834 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006835 if (phone == null) {
6836 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6837 return;
6838 }
6839 try {
6840 phone.carrierActionSetRadioEnabled(enabled);
6841 } catch (Exception e) {
6842 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006843 } finally {
6844 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006845 }
6846 }
6847
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006848 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006849 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6850 * network status based on which carrier apps could apply actions accordingly,
6851 * enable/disable default url handler for example.
6852 *
6853 * @param subId the subscription ID that this action applies to.
6854 * @param report control start/stop reporting the default network status.
6855 * {@hide}
6856 */
6857 @Override
6858 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6859 enforceModifyPermission();
6860 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861
6862 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006863 if (phone == null) {
6864 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6865 return;
6866 }
6867 try {
6868 phone.carrierActionReportDefaultNetworkStatus(report);
6869 } catch (Exception e) {
6870 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871 } finally {
6872 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006873 }
6874 }
6875
6876 /**
fionaxud9622282017-07-17 17:51:30 -07006877 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6878 * @param subId the subscription ID that this action applies to.
6879 * {@hide}
6880 */
6881 @Override
6882 public void carrierActionResetAll(int subId) {
6883 enforceModifyPermission();
6884 final Phone phone = getPhone(subId);
6885 if (phone == null) {
6886 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6887 return;
6888 }
6889 try {
6890 phone.carrierActionResetAll();
6891 } catch (Exception e) {
6892 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6893 }
6894 }
6895
6896 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006897 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6898 * bug report is being generated.
6899 */
6900 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006901 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006902 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6903 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006904 writer.println("Permission Denial: can't dump Phone from pid="
6905 + Binder.getCallingPid()
6906 + ", uid=" + Binder.getCallingUid()
6907 + "without permission "
6908 + android.Manifest.permission.DUMP);
6909 return;
6910 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006911 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006912 }
Jack Yueb89b242016-06-22 13:27:47 -07006913
Brad Ebingerdac2f002018-04-03 15:17:52 -07006914 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006915 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6916 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6917 @NonNull String[] args) {
6918 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6919 this, in.getFileDescriptor(), out.getFileDescriptor(),
6920 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006921 }
6922
Jack Yueb89b242016-06-22 13:27:47 -07006923 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006924 * Get aggregated video call data usage since boot.
6925 *
6926 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6927 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006928 * {@hide}
6929 */
6930 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006931 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006932 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6933 null);
6934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006935 final long identity = Binder.clearCallingIdentity();
6936 try {
6937 // NetworkStatsService keeps tracking the active network interface and identity. It
6938 // records the delta with the corresponding network identity.
6939 // We just return the total video call data usage snapshot since boot.
6940 Phone phone = getPhone(subId);
6941 if (phone != null) {
6942 return phone.getVtDataUsage(perUidStats);
6943 }
6944 return null;
6945 } finally {
6946 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006947 }
Jack Yueb89b242016-06-22 13:27:47 -07006948 }
Jack Yu75ab2952016-07-08 14:29:33 -07006949
6950 /**
6951 * Policy control of data connection. Usually used when data limit is passed.
6952 * @param enabled True if enabling the data, otherwise disabling.
6953 * @param subId Subscription index
6954 * {@hide}
6955 */
6956 @Override
6957 public void setPolicyDataEnabled(boolean enabled, int subId) {
6958 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006959
6960 final long identity = Binder.clearCallingIdentity();
6961 try {
6962 Phone phone = getPhone(subId);
6963 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006964 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965 }
6966 } finally {
6967 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006968 }
6969 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006970
6971 /**
6972 * Get Client request stats
6973 * @return List of Client Request Stats
6974 * @hide
6975 */
6976 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006977 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6978 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006979 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006980 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006981 return null;
6982 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006983 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006985 final long identity = Binder.clearCallingIdentity();
6986 try {
6987 if (phone != null) {
6988 return phone.getClientRequestStats();
6989 }
6990
6991 return null;
6992 } finally {
6993 Binder.restoreCallingIdentity(identity);
6994 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006995 }
6996
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006997 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006998 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006999 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007000 }
Jack Yueb4124c2017-02-16 15:32:43 -08007001
7002 /**
Grace Chen70990072017-03-24 17:21:30 -07007003 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007004 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007005 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007006 * @param state State of SIM (power down, power up, pass through)
7007 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7008 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7009 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007010 *
7011 **/
7012 @Override
Grace Chen70990072017-03-24 17:21:30 -07007013 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007014 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007015 Phone phone = PhoneFactory.getPhone(slotIndex);
7016
vagdeviaf9a5b92018-08-15 16:01:53 -07007017 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019 final long identity = Binder.clearCallingIdentity();
7020 try {
7021 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007022 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 }
7024 } finally {
7025 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007026 }
7027 }
Shuo Qiandd210312017-04-12 22:11:33 +00007028
Tyler Gunn65d45c22017-06-05 11:22:26 -07007029 private boolean isUssdApiAllowed(int subId) {
7030 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007031 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007032 if (configManager == null) {
7033 return false;
7034 }
7035 PersistableBundle pb = configManager.getConfigForSubId(subId);
7036 if (pb == null) {
7037 return false;
7038 }
7039 return pb.getBoolean(
7040 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7041 }
7042
Shuo Qiandd210312017-04-12 22:11:33 +00007043 /**
7044 * Check if phone is in emergency callback mode
7045 * @return true if phone is in emergency callback mode
7046 * @param subId sub id
7047 */
goneil9c5f4872017-12-05 14:07:56 -08007048 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007049 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007050 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007051 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052
7053 final long identity = Binder.clearCallingIdentity();
7054 try {
7055 if (phone != null) {
7056 return phone.isInEcm();
7057 } else {
7058 return false;
7059 }
7060 } finally {
7061 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007062 }
7063 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007064
7065 /**
7066 * Get the current signal strength information for the given subscription.
7067 * Because this information is not updated when the device is in a low power state
7068 * it should not be relied-upon to be current.
7069 * @param subId Subscription index
7070 * @return the most recent cached signal strength info from the modem
7071 */
7072 @Override
7073 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074 final long identity = Binder.clearCallingIdentity();
7075 try {
7076 Phone p = getPhone(subId);
7077 if (p == null) {
7078 return null;
7079 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 return p.getSignalStrength();
7082 } finally {
7083 Binder.restoreCallingIdentity(identity);
7084 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007085 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007086
Pengquan Meng77b7f132018-08-22 14:49:57 -07007087 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007088 * Get the current modem radio state for the given slot.
7089 * @param slotIndex slot index.
7090 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007091 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007092 * @return the current radio power state from the modem
7093 */
7094 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007095 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007096 Phone phone = PhoneFactory.getPhone(slotIndex);
7097 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007098 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7099 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007100 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7101 }
7102
7103 final long identity = Binder.clearCallingIdentity();
7104 try {
7105 return phone.getRadioPowerState();
7106 } finally {
7107 Binder.restoreCallingIdentity(identity);
7108 }
7109 }
7110 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7111 }
7112
7113 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007114 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7115 *
7116 * <p>Requires one of the following permissions:
7117 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7118 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7119 * privileges.
7120 *
7121 * @param subId subscription id
7122 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7123 * {@code false}.
7124 */
7125 @Override
7126 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007127 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7128 null /* message */);
7129
Pengquan Menga1bb6272018-09-06 09:59:22 -07007130 boolean isEnabled = false;
7131 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007132 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007133 Phone phone = getPhone(subId);
7134 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007135 } catch (Exception e) {
7136 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7137 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007138 } finally {
7139 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007140 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007141 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007142 }
7143
7144
7145 /**
7146 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7147 *
7148 * <p> Requires permission:
7149 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7150 * privileges.
7151 *
7152 * @param subId subscription id
7153 * @param isEnabled {@code true} means enable, {@code false} means disable.
7154 */
7155 @Override
7156 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7158 mApp, subId, "setDataRoamingEnabled");
7159
Pengquan Menga1bb6272018-09-06 09:59:22 -07007160 final long identity = Binder.clearCallingIdentity();
7161 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007162 Phone phone = getPhone(subId);
7163 if (phone != null) {
7164 phone.setDataRoamingEnabled(isEnabled);
7165 }
7166 } finally {
7167 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007168 }
7169 }
7170
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007171 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007172 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007173 TelephonyPermissions
7174 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007175 mApp, subId, "isManualNetworkSelectionAllowed");
7176
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007177 boolean isAllowed = true;
7178 final long identity = Binder.clearCallingIdentity();
7179 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007180 Phone phone = getPhone(subId);
7181 if (phone != null) {
7182 isAllowed = phone.isCspPlmnEnabled();
7183 }
7184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
7187 return isAllowed;
7188 }
7189
7190 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007191 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007192 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007193 try {
7194 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007195 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007196 } catch (SecurityException e) {
7197 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7198 // has carrier privileges on an active UICC
7199 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7200 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007201 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007202 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007203 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007204
7205 final long identity = Binder.clearCallingIdentity();
7206 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007207 UiccController uiccController = UiccController.getInstance();
7208 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007209 if (hasReadPermission) {
7210 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007211 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007212
7213 // Remove private info if the caller doesn't have access
7214 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7215 for (UiccCardInfo cardInfo : cardInfos) {
7216 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7217 // is available
7218 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7219 if (card == null || card.getUiccProfile() == null) {
7220 // assume no access if the card or profile is unavailable
7221 filteredInfos.add(cardInfo.getUnprivileged());
7222 continue;
7223 }
7224 UiccProfile profile = card.getUiccProfile();
7225 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7226 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7227 filteredInfos.add(cardInfo);
7228 } else {
7229 filteredInfos.add(cardInfo.getUnprivileged());
7230 }
7231 }
7232 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007233 } finally {
7234 Binder.restoreCallingIdentity(identity);
7235 }
7236 }
7237
7238 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007239 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007240 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007242 final long identity = Binder.clearCallingIdentity();
7243 try {
7244 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7245 if (slots == null) {
7246 Rlog.i(LOG_TAG, "slots is null.");
7247 return null;
7248 }
7249
7250 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7251 for (int i = 0; i < slots.length; i++) {
7252 UiccSlot slot = slots[i];
7253 if (slot == null) {
7254 continue;
7255 }
7256
Jordan Liu7be7e652019-05-06 18:55:02 +00007257 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007258 UiccCard card = slot.getUiccCard();
7259 if (card != null) {
7260 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007261 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007262 cardId = slot.getEid();
7263 if (TextUtils.isEmpty(cardId)) {
7264 cardId = slot.getIccId();
7265 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266 }
7267
Jordan Liu857451f2019-05-09 16:35:35 -07007268 if (cardId != null) {
7269 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7270 // if cardId is an EID, it's all digits so this is fine
7271 cardId = IccUtils.stripTrailingFs(cardId);
7272 }
7273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007274 int cardState = 0;
7275 switch (slot.getCardState()) {
7276 case CARDSTATE_ABSENT:
7277 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7278 break;
7279 case CARDSTATE_PRESENT:
7280 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7281 break;
7282 case CARDSTATE_ERROR:
7283 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7284 break;
7285 case CARDSTATE_RESTRICTED:
7286 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7287 break;
7288 default:
7289 break;
7290
7291 }
7292
7293 infos[i] = new UiccSlotInfo(
7294 slot.isActive(),
7295 slot.isEuicc(),
7296 cardId,
7297 cardState,
7298 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007299 slot.isExtendedApduSupported(),
7300 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007301 }
7302 return infos;
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007305 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007306 }
7307
7308 @Override
7309 public boolean switchSlots(int[] physicalSlots) {
7310 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007311
7312 final long identity = Binder.clearCallingIdentity();
7313 try {
7314 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7315 } finally {
7316 Binder.restoreCallingIdentity(identity);
7317 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007318 }
Jack Yu4c988042018-02-27 15:30:01 -08007319
7320 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007321 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007322 final long identity = Binder.clearCallingIdentity();
7323 try {
7324 return UiccController.getInstance().getCardIdForDefaultEuicc();
7325 } finally {
7326 Binder.restoreCallingIdentity(identity);
7327 }
7328 }
7329
7330 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007331 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7332 enforceModifyPermission();
7333 final Phone phone = getPhone(subId);
7334 if (phone == null) {
7335 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7336 return;
7337 }
7338
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007339 final long identity = Binder.clearCallingIdentity();
7340 try {
7341 phone.setRadioIndicationUpdateMode(filters, mode);
7342 } finally {
7343 Binder.restoreCallingIdentity(identity);
7344 }
Jack Yu4c988042018-02-27 15:30:01 -08007345 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007346
7347 /**
goneil47ffb6e2018-04-06 15:40:58 -07007348 * A test API to reload the UICC profile.
7349 *
7350 * <p>Requires that the calling app has permission
7351 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7352 * @hide
7353 */
7354 @Override
7355 public void refreshUiccProfile(int subId) {
7356 enforceModifyPermission();
7357
7358 final long identity = Binder.clearCallingIdentity();
7359 try {
7360 Phone phone = getPhone(subId);
7361 if (phone == null) {
7362 return;
7363 }
7364 UiccCard uiccCard = phone.getUiccCard();
7365 if (uiccCard == null) {
7366 return;
7367 }
7368 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7369 if (uiccProfile == null) {
7370 return;
7371 }
7372 uiccProfile.refresh();
7373 } finally {
7374 Binder.restoreCallingIdentity(identity);
7375 }
7376 }
7377
7378 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007379 * Returns false if the mobile data is disabled by default, otherwise return true.
7380 */
7381 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007382 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007383 }
7384
7385 /**
7386 * Returns true if the data roaming is enabled by default, i.e the system property
7387 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7388 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7389 */
7390 private boolean getDefaultDataRoamingEnabled(int subId) {
7391 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007392 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007393 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007394 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7395 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7396 return isDataRoamingEnabled;
7397 }
7398
7399 /**
7400 * Returns the default network type for the given {@code subId}, if the default network type is
7401 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7402 */
7403 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007404 List<Integer> list = TelephonyProperties.default_network();
7405 int phoneId = mSubscriptionController.getPhoneId(subId);
7406 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7407 return list.get(phoneId);
7408 }
7409 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007410 }
fionaxua13278b2018-03-21 00:08:13 -07007411
7412 @Override
7413 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007414 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007415 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007416
7417 final long identity = Binder.clearCallingIdentity();
7418 try {
7419 final Phone phone = getPhone(subId);
7420 if (phone == null) {
7421 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7422 return;
7423 }
chen xueaba88a2019-03-15 13:15:10 -07007424 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7425 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 } finally {
7427 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007428 }
fionaxua13278b2018-03-21 00:08:13 -07007429 }
7430
7431 @Override
7432 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007433 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434
7435 final long identity = Binder.clearCallingIdentity();
7436 try {
7437 final Phone phone = getPhone(subId);
7438 if (phone == null) {
7439 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7440 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7441 }
7442 return phone.getCarrierIdListVersion();
7443 } finally {
7444 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007445 }
fionaxua13278b2018-03-21 00:08:13 -07007446 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007447
7448 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007449 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7450 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007451 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007452 mApp, subId, callingPackage, callingFeatureId,
7453 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007454 return -1;
7455 }
7456
7457 final long identity = Binder.clearCallingIdentity();
7458 try {
7459 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7460 } finally {
7461 Binder.restoreCallingIdentity(identity);
7462 }
7463 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007464
7465 @Override
7466 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007467 TelephonyPermissions
7468 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007469 mApp, subId, "getCdmaRoamingMode");
7470
7471 final long identity = Binder.clearCallingIdentity();
7472 try {
7473 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7474 } finally {
7475 Binder.restoreCallingIdentity(identity);
7476 }
7477 }
7478
7479 @Override
7480 public boolean setCdmaRoamingMode(int subId, int mode) {
7481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7482 mApp, subId, "setCdmaRoamingMode");
7483
7484 final long identity = Binder.clearCallingIdentity();
7485 try {
7486 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7487 } finally {
7488 Binder.restoreCallingIdentity(identity);
7489 }
7490 }
7491
7492 @Override
7493 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7495 mApp, subId, "setCdmaSubscriptionMode");
7496
7497 final long identity = Binder.clearCallingIdentity();
7498 try {
7499 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7500 } finally {
7501 Binder.restoreCallingIdentity(identity);
7502 }
7503 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007504
sqianc5eccab2018-10-19 18:46:41 -07007505 @Override
sqian8c685422019-02-22 15:55:18 -08007506 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007507 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007509 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7510 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007511 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7512 }
7513 final long identity = Binder.clearCallingIdentity();
7514 try {
sqian854d44b2018-12-12 16:48:18 -08007515 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7516 for (Phone phone: PhoneFactory.getPhones()) {
7517 if (phone.getEmergencyNumberTracker() != null
7518 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7519 emergencyNumberListInternal.put(
7520 phone.getSubId(),
7521 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7522 }
sqian11b7a0e2018-12-05 18:48:28 -08007523 }
sqian854d44b2018-12-12 16:48:18 -08007524 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007525 } finally {
7526 Binder.restoreCallingIdentity(identity);
7527 }
sqianc5eccab2018-10-19 18:46:41 -07007528 }
7529
7530 @Override
sqian8c685422019-02-22 15:55:18 -08007531 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007532 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007533 if (!exactMatch) {
7534 TelephonyPermissions
7535 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007536 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007537 }
7538 final long identity = Binder.clearCallingIdentity();
7539 try {
sqian854d44b2018-12-12 16:48:18 -08007540 for (Phone phone: PhoneFactory.getPhones()) {
7541 if (phone.getEmergencyNumberTracker() != null
7542 && phone.getEmergencyNumberTracker() != null) {
7543 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7544 number, exactMatch)) {
7545 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007546 }
7547 }
sqian11b7a0e2018-12-05 18:48:28 -08007548 }
7549 return false;
7550 } finally {
7551 Binder.restoreCallingIdentity(identity);
7552 }
7553 }
7554
sqianf4ca7ed2019-01-15 18:32:07 -08007555 /**
7556 * Update emergency number list for test mode.
7557 */
7558 @Override
7559 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7560 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7561 "updateEmergencyNumberListTestMode");
7562
7563 final long identity = Binder.clearCallingIdentity();
7564 try {
7565 for (Phone phone: PhoneFactory.getPhones()) {
7566 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7567 if (tracker != null) {
7568 tracker.executeEmergencyNumberTestModeCommand(action, num);
7569 }
7570 }
7571 } finally {
7572 Binder.restoreCallingIdentity(identity);
7573 }
7574 }
7575
7576 /**
7577 * Get the full emergency number list for test mode.
7578 */
7579 @Override
7580 public List<String> getEmergencyNumberListTestMode() {
7581 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7582 "getEmergencyNumberListTestMode");
7583
7584 final long identity = Binder.clearCallingIdentity();
7585 try {
7586 Set<String> emergencyNumbers = new HashSet<>();
7587 for (Phone phone: PhoneFactory.getPhones()) {
7588 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7589 if (tracker != null) {
7590 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7591 emergencyNumbers.add(num.getNumber());
7592 }
7593 }
7594 }
7595 return new ArrayList<>(emergencyNumbers);
7596 } finally {
7597 Binder.restoreCallingIdentity(identity);
7598 }
7599 }
7600
chen xud6b45bd2018-10-30 22:27:10 -07007601 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007602 public int getEmergencyNumberDbVersion(int subId) {
7603 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7604
7605 final long identity = Binder.clearCallingIdentity();
7606 try {
7607 final Phone phone = getPhone(subId);
7608 if (phone == null) {
7609 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7610 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7611 }
7612 return phone.getEmergencyNumberDbVersion();
7613 } finally {
7614 Binder.restoreCallingIdentity(identity);
7615 }
7616 }
7617
7618 @Override
7619 public void notifyOtaEmergencyNumberDbInstalled() {
7620 enforceModifyPermission();
7621
7622 final long identity = Binder.clearCallingIdentity();
7623 try {
7624 for (Phone phone: PhoneFactory.getPhones()) {
7625 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7626 if (tracker != null) {
7627 tracker.updateOtaEmergencyNumberDatabase();
7628 }
7629 }
7630 } finally {
7631 Binder.restoreCallingIdentity(identity);
7632 }
7633 }
7634
7635 @Override
7636 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7637 enforceActiveEmergencySessionPermission();
7638
7639 final long identity = Binder.clearCallingIdentity();
7640 try {
7641 for (Phone phone: PhoneFactory.getPhones()) {
7642 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7643 if (tracker != null) {
7644 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7645 }
7646 }
7647 } finally {
7648 Binder.restoreCallingIdentity(identity);
7649 }
7650 }
7651
7652 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007653 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7654 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7655 Phone phone = getPhone(subId);
7656 if (phone == null) {
7657 return null;
7658 }
7659 final long identity = Binder.clearCallingIdentity();
7660 try {
7661 UiccProfile profile = UiccController.getInstance()
7662 .getUiccProfileForPhone(phone.getPhoneId());
7663 if (profile != null) {
7664 return profile.getCertsFromCarrierPrivilegeAccessRules();
7665 }
7666 } finally {
7667 Binder.restoreCallingIdentity(identity);
7668 }
7669 return null;
7670 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007671
7672 /**
7673 * Enable or disable a modem stack.
7674 */
7675 @Override
7676 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7677 enforceModifyPermission();
7678
7679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 Phone phone = PhoneFactory.getPhone(slotIndex);
7682 if (phone == null) {
7683 return false;
7684 } else {
7685 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7686 }
7687 } finally {
7688 Binder.restoreCallingIdentity(identity);
7689 }
7690 }
Michelecea4cf22018-12-21 15:00:11 -08007691
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007692 /**
7693 * Whether a modem stack is enabled or not.
7694 */
7695 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007696 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7697 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007698 Phone phone = PhoneFactory.getPhone(slotIndex);
7699 if (phone == null) return false;
7700
7701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007702 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7703 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007704 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7705 }
7706
7707 final long identity = Binder.clearCallingIdentity();
7708 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007709 try {
7710 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7711 } catch (NoSuchElementException ex) {
7712 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7713 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007714 } finally {
7715 Binder.restoreCallingIdentity(identity);
7716 }
7717 }
7718
Michelecea4cf22018-12-21 15:00:11 -08007719 @Override
Michele0ea7d782019-03-19 14:58:42 -07007720 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007721 enforceModifyPermission();
7722
7723 final long identity = Binder.clearCallingIdentity();
7724 try {
7725 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007726 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007727 .commit();
7728 } finally {
7729 Binder.restoreCallingIdentity(identity);
7730 }
7731 }
7732
7733 @Override
Michele0ea7d782019-03-19 14:58:42 -07007734 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007735 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007737 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7738 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007739 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007740 }
Michelecea4cf22018-12-21 15:00:11 -08007741
7742 final long identity = Binder.clearCallingIdentity();
7743 try {
Michele0ea7d782019-03-19 14:58:42 -07007744 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007745 } finally {
7746 Binder.restoreCallingIdentity(identity);
7747 }
7748 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007749
Michele0ea7d782019-03-19 14:58:42 -07007750 @TelephonyManager.IsMultiSimSupportedResult
7751 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007752 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7753 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7754 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007755 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7756 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007757 }
7758 // Check if the hardware supports multisim functionality. If usage of multisim is not
7759 // supported by the modem, indicate that it is restricted.
7760 PhoneCapability staticCapability =
7761 mPhoneConfigurationManager.getStaticPhoneCapability();
7762 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007763 loge("isMultiSimSupportedInternal: no static configuration available");
7764 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007765 }
7766 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007767 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7768 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007769 }
7770 // Check if support of multiple SIMs is restricted by carrier
7771 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007772 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007773 }
7774
Michele0ea7d782019-03-19 14:58:42 -07007775 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007776 }
7777
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007778 /**
7779 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007780 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7781 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7782 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007783 * @param numOfSims number of active sims we want to switch to
7784 */
7785 @Override
7786 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007787 if (numOfSims == 1) {
7788 enforceModifyPermission();
7789 } else {
7790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7791 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7792 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007793 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007794
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007795 try {
Michele30b57b22019-03-01 12:01:14 -08007796 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007797 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007798 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7799 return;
7800 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007801 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7802 } finally {
7803 Binder.restoreCallingIdentity(identity);
7804 }
7805 }
7806
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007807 @Override
7808 public boolean isApplicationOnUicc(int subId, int appType) {
7809 enforceReadPrivilegedPermission("isApplicationOnUicc");
7810 Phone phone = getPhone(subId);
7811 if (phone == null) {
7812 return false;
7813 }
7814 final long identity = Binder.clearCallingIdentity();
7815 try {
7816 UiccCard uiccCard = phone.getUiccCard();
7817 if (uiccCard == null) {
7818 return false;
7819 }
7820 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7821 if (uiccProfile == null) {
7822 return false;
7823 }
7824 if (TelephonyManager.APPTYPE_SIM <= appType
7825 && appType <= TelephonyManager.APPTYPE_ISIM) {
7826 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7827 }
7828 return false;
7829 } finally {
7830 Binder.restoreCallingIdentity(identity);
7831 }
7832 }
7833
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007834 /**
chen xub4baa772019-04-03 10:23:41 -07007835 * Get whether making changes to modem configurations will trigger reboot.
7836 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007837 */
7838 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007839 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7840 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007841 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007842 mApp, subId, callingPackage, callingFeatureId,
7843 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007844 return false;
7845 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007846 final long identity = Binder.clearCallingIdentity();
7847 try {
7848 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7849 } finally {
7850 Binder.restoreCallingIdentity(identity);
7851 }
7852 }
7853
Nathan Harold29f5f052019-02-15 13:41:57 -08007854 private void updateModemStateMetrics() {
7855 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7856 // TODO: check the state for each modem if the api is ready.
7857 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7858 }
7859
Pengquan Meng3889a572019-01-23 11:16:29 -08007860 @Override
7861 public int[] getSlotsMapping() {
7862 enforceReadPrivilegedPermission("getSlotsMapping");
7863
7864 final long identity = Binder.clearCallingIdentity();
7865 try {
7866 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7867 // All logical slots should have a mapping to a physical slot.
7868 int[] logicalSlotsMapping = new int[phoneCount];
7869 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7870 for (int i = 0; i < slotInfos.length; i++) {
7871 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7872 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7873 }
7874 }
7875 return logicalSlotsMapping;
7876 } finally {
7877 Binder.restoreCallingIdentity(identity);
7878 }
7879 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007880
7881 /**
7882 * Get the IRadio HAL Version
7883 */
7884 @Override
7885 public int getRadioHalVersion() {
7886 Phone phone = getDefaultPhone();
7887 if (phone == null) return -1;
7888 HalVersion hv = phone.getHalVersion();
7889 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7890 return hv.major * 100 + hv.minor;
7891 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007892
7893 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007894 * Get the current calling package name.
7895 * @return the current calling package name
7896 */
7897 @Override
7898 public String getCurrentPackageName() {
7899 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
7900 }
7901
7902 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007903 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7904 * corresponding network requests on a subId.
7905 *
7906 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007907 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007908 * 2) APN is un-metered for this subscription, or
7909 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007910 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007911 *
7912 * @return whether data is allowed for a apn type.
7913 *
7914 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007915 */
7916 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007917 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007918 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7919 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007920
7921 // Now that all security checks passes, perform the operation as ourselves.
7922 final long identity = Binder.clearCallingIdentity();
7923 try {
7924 Phone phone = getPhone(subId);
7925 if (phone == null) return false;
7926
Jack Yu41407ee2019-05-13 16:54:09 -07007927 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007928 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7929 } finally {
7930 Binder.restoreCallingIdentity(identity);
7931 }
7932 }
7933
7934 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007935 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007936 enforceReadPrivilegedPermission("isApnMetered");
7937
7938 // Now that all security checks passes, perform the operation as ourselves.
7939 final long identity = Binder.clearCallingIdentity();
7940 try {
7941 Phone phone = getPhone(subId);
7942 if (phone == null) return true; // By default return true.
7943
Jack Yu41407ee2019-05-13 16:54:09 -07007944 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007945 } finally {
7946 Binder.restoreCallingIdentity(identity);
7947 }
7948 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007949
7950 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08007951 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
7952 int subscriptionId, IBooleanConsumer resultCallback) {
7953 enforceModifyPermission();
7954 long token = Binder.clearCallingIdentity();
7955 try {
7956 Phone phone = getPhone(subscriptionId);
7957 if (phone == null) {
7958 try {
7959 if (resultCallback != null) {
7960 resultCallback.accept(false);
7961 }
7962 } catch (RemoteException e) {
7963 // ignore
7964 }
7965 return;
7966 }
7967 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
7968 Pair.create(specifiers, (x) -> {
7969 try {
7970 if (resultCallback != null) {
7971 resultCallback.accept(x);
7972 }
7973 } catch (RemoteException e) {
7974 // ignore
7975 }
7976 });
7977 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
7978 } finally {
7979 Binder.restoreCallingIdentity(token);
7980 }
7981 }
7982
7983 @Override
changbetty7157e9e2019-12-06 18:16:37 +08007984 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7985 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7986 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7987 if (iccRecords == null) {
7988 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7989 return false;
7990 }
7991 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7992 }
7993
7994 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007995 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007996 if (callingPackage == null) {
7997 callingPackage = getCurrentPackageName();
7998 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007999 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8000 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8001 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8002 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8003 }
8004 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8005 Intent intent = new Intent();
8006 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8007 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8008 // Bring up choose default SMS subscription dialog right now
8009 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8010 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8011 mApp.startActivity(intent);
8012 }
chen xud5ca2d52019-05-28 15:20:57 -07008013
8014 @Override
8015 public String getMmsUAProfUrl(int subId) {
8016 //TODO investigate if this API should require proper permission check in R b/133791609
8017 final long identity = Binder.clearCallingIdentity();
8018 try {
8019 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8020 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8021 } finally {
8022 Binder.restoreCallingIdentity(identity);
8023 }
8024 }
8025
8026 @Override
8027 public String getMmsUserAgent(int subId) {
8028 //TODO investigate if this API should require proper permission check in R b/133791609
8029 final long identity = Binder.clearCallingIdentity();
8030 try {
8031 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8032 .getString(com.android.internal.R.string.config_mms_user_agent);
8033 } finally {
8034 Binder.restoreCallingIdentity(identity);
8035 }
8036 }
Jack Yub07d4972019-05-28 16:12:25 -07008037
8038 @Override
8039 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8040 enforceModifyPermission();
8041
8042 // Now that all security checks passes, perform the operation as ourselves.
8043 final long identity = Binder.clearCallingIdentity();
8044 try {
8045 Phone phone = getPhone(subId);
8046 if (phone == null) return false;
8047
8048 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8049 } finally {
8050 Binder.restoreCallingIdentity(identity);
8051 }
8052 }
8053
8054 @Override
8055 public boolean isDataAllowedInVoiceCall(int subId) {
8056 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8057
8058 // Now that all security checks passes, perform the operation as ourselves.
8059 final long identity = Binder.clearCallingIdentity();
8060 try {
8061 Phone phone = getPhone(subId);
8062 if (phone == null) return false;
8063
8064 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8065 } finally {
8066 Binder.restoreCallingIdentity(identity);
8067 }
8068 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008069
changbettyd5c246e2019-12-24 15:40:37 +08008070 @Override
8071 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8072 enforceModifyPermission();
8073
8074 // Now that all security checks passes, perform the operation as ourselves.
8075 final long identity = Binder.clearCallingIdentity();
8076 try {
8077 Phone phone = getPhone(subId);
8078 if (phone == null) return false;
8079
8080 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8081 } finally {
8082 Binder.restoreCallingIdentity(identity);
8083 }
8084 }
8085
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008086 /**
8087 * Updates whether conference event pacakge handling is enabled.
8088 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8089 * otherwise.
8090 */
8091 @Override
8092 public void setCepEnabled(boolean isCepEnabled) {
8093 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8094
8095 final long identity = Binder.clearCallingIdentity();
8096 try {
8097 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8098 for (Phone phone : PhoneFactory.getPhones()) {
8099 Phone defaultPhone = phone.getImsPhone();
8100 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8101 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8102 ImsPhoneCallTracker imsPhoneCallTracker =
8103 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8104 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8105 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8106 + imsPhone.getMsisdn());
8107 }
8108 }
8109 } finally {
8110 Binder.restoreCallingIdentity(identity);
8111 }
8112 }
allenwtsu46dcc572020-01-08 18:24:03 +08008113
8114 /**
8115 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8116 *
8117 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8118 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8119 * before being read.
8120 */
8121 @Override
8122 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8123 isCompressed) {
8124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8125 mApp, subId, "notifyRcsAutoConfigurationReceived");
8126 try {
8127 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8128 if (configBinder == null) {
8129 Rlog.e(LOG_TAG, "null result for getImsConfig");
8130 } else {
8131 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8132 }
8133 } catch (RemoteException e) {
8134 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8135 }
8136 }
zoey chene02881a2019-12-30 16:11:23 +08008137
8138 @Override
8139 public boolean isIccLockEnabled(int subId) {
8140 enforceReadPrivilegedPermission("isIccLockEnabled");
8141
8142 // Now that all security checks passes, perform the operation as ourselves.
8143 final long identity = Binder.clearCallingIdentity();
8144 try {
8145 Phone phone = getPhone(subId);
8146 if (phone != null && phone.getIccCard() != null) {
8147 return phone.getIccCard().getIccLockEnabled();
8148 } else {
8149 return false;
8150 }
8151 } finally {
8152 Binder.restoreCallingIdentity(identity);
8153 }
8154 }
8155
8156 /**
8157 * Set the ICC pin lock enabled or disabled.
8158 *
8159 * @return an integer representing the status of IccLock enabled or disabled in the following
8160 * three cases:
8161 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8162 * successfully.
8163 * - Positive number and zero for remaining password attempts.
8164 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8165 *
8166 */
8167 @Override
8168 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8169 enforceModifyPermission();
8170
8171 Phone phone = getPhone(subId);
8172 if (phone == null) {
8173 return 0;
8174 }
8175 // Now that all security checks passes, perform the operation as ourselves.
8176 final long identity = Binder.clearCallingIdentity();
8177 try {
8178 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8179 new Pair<Boolean, String>(enabled, password), phone, null);
8180 return attemptsRemaining;
8181
8182 } catch (Exception e) {
8183 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8184 } finally {
8185 Binder.restoreCallingIdentity(identity);
8186 }
8187 return 0;
8188 }
8189
8190 /**
8191 * Change the ICC password used in ICC pin lock.
8192 *
8193 * @return an integer representing the status of IccLock changed in the following three cases:
8194 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8195 * - Positive number and zero for remaining password attempts.
8196 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8197 *
8198 */
8199 @Override
8200 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8201 enforceModifyPermission();
8202
8203 Phone phone = getPhone(subId);
8204 if (phone == null) {
8205 return 0;
8206 }
8207 // Now that all security checks passes, perform the operation as ourselves.
8208 final long identity = Binder.clearCallingIdentity();
8209 try {
8210 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8211 new Pair<String, String>(oldPassword, newPassword), phone, null);
8212 return attemptsRemaining;
8213
8214 } catch (Exception e) {
8215 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8216 } finally {
8217 Binder.restoreCallingIdentity(identity);
8218 }
8219 return 0;
8220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008221}