blob: f8a44e29b1e1f2750a7a338aa45f55fe29e6023a [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;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070067import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080068import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070069import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080070import android.telephony.CellIdentityCdma;
71import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070073import android.telephony.CellInfoGsm;
74import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070075import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070076import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070077import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080078import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070079import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080080import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070081import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080082import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080083import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070084import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080085import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070086import android.telephony.Rlog;
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;
113import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800114import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800130import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700131import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800132import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800134import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700135import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700136import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700139import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800140import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700141import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700142import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700143import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700144import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700145import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700146import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700147import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800149import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800150import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700151import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800152import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700153import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800154import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700155import com.android.internal.telephony.imsphone.ImsPhone;
156import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800157import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800160import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800162import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700163import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000167import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800168import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700169import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800170import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700171import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700172import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800173import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700175import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800176
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700177import java.io.FileDescriptor;
178import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800180import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800181import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800182import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800183import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100184import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800185import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700186import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188
189/**
190 * Implementation of the ITelephony interface.
191 */
Santos Cordon117fee72014-05-16 17:56:12 -0700192public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 private static final String LOG_TAG = "PhoneInterfaceManager";
194 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
195 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800196 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
198 // Message codes used with mMainThreadHandler
199 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700200 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
201 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202 private static final int CMD_OPEN_CHANNEL = 9;
203 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
204 private static final int CMD_CLOSE_CHANNEL = 11;
205 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800206 private static final int CMD_NV_READ_ITEM = 13;
207 private static final int EVENT_NV_READ_ITEM_DONE = 14;
208 private static final int CMD_NV_WRITE_ITEM = 15;
209 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
210 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
211 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700212 private static final int CMD_RESET_MODEM_CONFIG = 19;
213 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800214 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
215 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
216 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
217 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800218 private static final int CMD_SEND_ENVELOPE = 25;
219 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000220 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
221 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700222 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
223 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
224 private static final int CMD_EXCHANGE_SIM_IO = 31;
225 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800226 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
227 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700228 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
229 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700230 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
231 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700232 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
233 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
234 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
235 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700236 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
237 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
238 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
239 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700240 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800241 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
242 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000243 private static final int CMD_SWITCH_SLOTS = 50;
244 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700245 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
246 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
247 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
248 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
249 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
250 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
251 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
252 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700253 private static final int CMD_GET_ALL_CELL_INFO = 60;
254 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
255 private static final int CMD_GET_CELL_LOCATION = 62;
256 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700257 private static final int CMD_MODEM_REBOOT = 64;
258 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700259 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
260 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800261 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
262 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700263 private static final int CMD_GET_MODEM_STATUS = 70;
264 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700265 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
266 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700267 private static final int CMD_ERASE_MODEM_CONFIG = 74;
268 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800270 // Parameters of select command.
271 private static final int SELECT_COMMAND = 0xA4;
272 private static final int SELECT_P1 = 0x04;
273 private static final int SELECT_P2 = 0;
274 private static final int SELECT_P3 = 0x10;
275
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276 /** The singleton instance. */
277 private static PhoneInterfaceManager sInstance;
278
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800281 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700282 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800283 private AppOpsManager mAppOps;
284 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800285 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800286 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700287 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288
Derek Tan97ebb422014-09-05 16:55:38 -0700289 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
290 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800291 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800292 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700293
Michelecea4cf22018-12-21 15:00:11 -0800294 // String to store multi SIM allowed
295 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
296
Derek Tan740e1672017-06-27 14:56:27 -0700297 // The AID of ISD-R.
298 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
299
yinxub1bed742017-04-17 11:45:04 -0700300 private NetworkScanRequestTracker mNetworkScanRequestTracker;
301
David Kelly5e06a7f2018-03-12 14:10:59 +0000302 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
303 private static final int MANUFACTURER_CODE_LENGTH = 8;
304
Derek Tan89e89d42014-07-08 17:00:10 -0700305 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700306 * Experiment flag to enable erase modem config on reset network, default value is false
307 */
308 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
309 "reset_network_erase_modem_config_enabled";
310
311 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700312 * A request object to use for transmitting data to an ICC.
313 */
314 private static final class IccAPDUArgument {
315 public int channel, cla, command, p1, p2, p3;
316 public String data;
317
318 public IccAPDUArgument(int channel, int cla, int command,
319 int p1, int p2, int p3, String data) {
320 this.channel = channel;
321 this.cla = cla;
322 this.command = command;
323 this.p1 = p1;
324 this.p2 = p2;
325 this.p3 = p3;
326 this.data = data;
327 }
328 }
329
330 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700331 * A request object to use for transmitting data to an ICC.
332 */
333 private static final class ManualNetworkSelectionArgument {
334 public OperatorInfo operatorInfo;
335 public boolean persistSelection;
336
337 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
338 this.operatorInfo = operatorInfo;
339 this.persistSelection = persistSelection;
340 }
341 }
342
343 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
345 * request after sending. The main thread will notify the request when it is complete.
346 */
347 private static final class MainThreadRequest {
348 /** The argument to use for the request */
349 public Object argument;
350 /** The result of the request that is run on the main thread */
351 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800352 // The subscriber id that this request applies to. Defaults to
353 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
354 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355
Nathan Harold92bed182018-10-12 18:16:49 -0700356 // In cases where subId is unavailable, the caller needs to specify the phone.
357 public Phone phone;
358
vagdeviaf9a5b92018-08-15 16:01:53 -0700359 public WorkSource workSource;
360
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 public MainThreadRequest(Object argument) {
362 this.argument = argument;
363 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800364
Nathan Harold92bed182018-10-12 18:16:49 -0700365 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
366 this.argument = argument;
367 if (phone != null) {
368 this.phone = phone;
369 }
370 this.workSource = workSource;
371 }
372
vagdeviaf9a5b92018-08-15 16:01:53 -0700373 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800374 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800375 if (subId != null) {
376 this.subId = subId;
377 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700378 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800379 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 }
381
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800382 private static final class IncomingThirdPartyCallArgs {
383 public final ComponentName component;
384 public final String callId;
385 public final String callerDisplayName;
386
387 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
388 String callerDisplayName) {
389 this.component = component;
390 this.callId = callId;
391 this.callerDisplayName = callerDisplayName;
392 }
393 }
394
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 /**
396 * A handler that processes messages on the main thread in the phone process. Since many
397 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
398 * inbound binder threads to the main thread in the phone process. The Binder thread
399 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
400 * on, which will be notified when the operation completes and will contain the result of the
401 * request.
402 *
403 * <p>If a MainThreadRequest object is provided in the msg.obj field,
404 * note that request.result must be set to something non-null for the calling thread to
405 * unblock.
406 */
407 private final class MainThreadHandler extends Handler {
408 @Override
409 public void handleMessage(Message msg) {
410 MainThreadRequest request;
411 Message onCompleted;
412 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800413 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800415 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416
417 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700418 case CMD_HANDLE_USSD_REQUEST: {
419 request = (MainThreadRequest) msg.obj;
420 final Phone phone = getPhoneFromRequest(request);
421 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
422 String ussdRequest = ussdObject.first;
423 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700424
Pengquan Menga1bb6272018-09-06 09:59:22 -0700425 if (!isUssdApiAllowed(request.subId)) {
426 // Carrier does not support use of this API, return failure.
427 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
428 UssdResponse response = new UssdResponse(ussdRequest, null);
429 Bundle returnData = new Bundle();
430 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
431 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700432
Pengquan Menga1bb6272018-09-06 09:59:22 -0700433 request.result = true;
434 notifyRequester(request);
435 return;
436 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700437
Pengquan Menga1bb6272018-09-06 09:59:22 -0700438 try {
439 request.result = phone != null
440 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
441 } catch (CallStateException cse) {
442 request.result = false;
443 }
444 // Wake up the requesting thread
445 notifyRequester(request);
446 break;
pkanwar32d516d2016-10-14 19:37:38 -0700447 }
448
Yorke Lee716f67e2015-06-17 15:39:16 -0700449 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700451 final Phone phone = getPhoneFromRequest(request);
452 request.result = phone != null ?
453 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
454 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800463 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700464 if (uiccCard == null) {
465 loge("iccTransmitApduLogicalChannel: No UICC");
466 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700467 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700468 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700469 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
470 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700471 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 iccArgument.channel, iccArgument.cla, iccArgument.command,
473 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700475 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 break;
477
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 ar = (AsyncResult) msg.obj;
480 request = (MainThreadRequest) ar.userObj;
481 if (ar.exception == null && ar.result != null) {
482 request.result = ar.result;
483 } else {
484 request.result = new IccIoResult(0x6F, 0, (byte[])null);
485 if (ar.result == null) {
486 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800487 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800489 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 } else {
491 loge("iccTransmitApduLogicalChannel: Unknown exception");
492 }
493 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700495 break;
496
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
498 request = (MainThreadRequest) msg.obj;
499 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800500 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 if (uiccCard == null) {
502 loge("iccTransmitApduBasicChannel: No UICC");
503 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 } else {
506 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
507 request);
508 uiccCard.iccTransmitApduBasicChannel(
509 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
510 iccArgument.p3, iccArgument.data, onCompleted);
511 }
512 break;
513
514 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
515 ar = (AsyncResult) msg.obj;
516 request = (MainThreadRequest) ar.userObj;
517 if (ar.exception == null && ar.result != null) {
518 request.result = ar.result;
519 } else {
520 request.result = new IccIoResult(0x6F, 0, (byte[])null);
521 if (ar.result == null) {
522 loge("iccTransmitApduBasicChannel: Empty response");
523 } else if (ar.exception instanceof CommandException) {
524 loge("iccTransmitApduBasicChannel: CommandException: " +
525 ar.exception);
526 } else {
527 loge("iccTransmitApduBasicChannel: Unknown exception");
528 }
529 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 break;
532
533 case CMD_EXCHANGE_SIM_IO:
534 request = (MainThreadRequest) msg.obj;
535 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800536 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 if (uiccCard == null) {
538 loge("iccExchangeSimIO: No UICC");
539 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700540 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 } else {
542 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
543 request);
544 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
545 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
546 iccArgument.data, onCompleted);
547 }
548 break;
549
550 case EVENT_EXCHANGE_SIM_IO_DONE:
551 ar = (AsyncResult) msg.obj;
552 request = (MainThreadRequest) ar.userObj;
553 if (ar.exception == null && ar.result != null) {
554 request.result = ar.result;
555 } else {
556 request.result = new IccIoResult(0x6f, 0, (byte[])null);
557 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 break;
560
Derek Tan4d5e5c12014-02-04 11:54:58 -0800561 case CMD_SEND_ENVELOPE:
562 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 if (uiccCard == null) {
565 loge("sendEnvelopeWithStatus: No UICC");
566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 } else {
569 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
570 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
571 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800572 break;
573
574 case EVENT_SEND_ENVELOPE_DONE:
575 ar = (AsyncResult) msg.obj;
576 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700577 if (ar.exception == null && ar.result != null) {
578 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800579 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700580 request.result = new IccIoResult(0x6F, 0, (byte[])null);
581 if (ar.result == null) {
582 loge("sendEnvelopeWithStatus: Empty response");
583 } else if (ar.exception instanceof CommandException) {
584 loge("sendEnvelopeWithStatus: CommandException: " +
585 ar.exception);
586 } else {
587 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
588 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800589 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700590 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800591 break;
592
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 case CMD_OPEN_CHANNEL:
594 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800595 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800596 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 if (uiccCard == null) {
598 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800599 request.result = new IccOpenLogicalChannelResponse(-1,
600 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700601 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700602 } else {
603 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800604 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
605 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700606 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 break;
608
609 case EVENT_OPEN_CHANNEL_DONE:
610 ar = (AsyncResult) msg.obj;
611 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 int[] result = (int[]) ar.result;
615 int channelId = result[0];
616 byte[] selectResponse = null;
617 if (result.length > 1) {
618 selectResponse = new byte[result.length - 1];
619 for (int i = 1; i < result.length; ++i) {
620 selectResponse[i - 1] = (byte) result[i];
621 }
622 }
623 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700624 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 if (ar.result == null) {
627 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 if (ar.exception != null) {
630 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
631 }
632
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700633 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700634 if (ar.exception instanceof CommandException) {
635 CommandException.Error error =
636 ((CommandException) (ar.exception)).getCommandError();
637 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700638 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700639 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700640 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 }
642 }
643 openChannelResp = new IccOpenLogicalChannelResponse(
644 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700646 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700647 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 break;
649
650 case CMD_CLOSE_CHANNEL:
651 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800652 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700653 if (uiccCard == null) {
654 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900655 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 } else {
658 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
659 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
660 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 break;
662
663 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800664 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
665 break;
666
667 case CMD_NV_READ_ITEM:
668 request = (MainThreadRequest) msg.obj;
669 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800670 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
671 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800672 break;
673
674 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 ar = (AsyncResult) msg.obj;
676 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800677 if (ar.exception == null && ar.result != null) {
678 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800680 request.result = "";
681 if (ar.result == null) {
682 loge("nvReadItem: Empty response");
683 } else if (ar.exception instanceof CommandException) {
684 loge("nvReadItem: CommandException: " +
685 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800687 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 }
689 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 break;
692
Jake Hambye994d462014-02-03 13:10:13 -0800693 case CMD_NV_WRITE_ITEM:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
696 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800697 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700698 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800699 break;
700
701 case EVENT_NV_WRITE_ITEM_DONE:
702 handleNullReturnEvent(msg, "nvWriteItem");
703 break;
704
705 case CMD_NV_WRITE_CDMA_PRL:
706 request = (MainThreadRequest) msg.obj;
707 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800708 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800709 break;
710
711 case EVENT_NV_WRITE_CDMA_PRL_DONE:
712 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
713 break;
714
chen xu6dac5ab2018-10-26 17:39:23 -0700715 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800716 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700717 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800718 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800719 break;
720
chen xu6dac5ab2018-10-26 17:39:23 -0700721 case EVENT_RESET_MODEM_CONFIG_DONE:
722 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800723 break;
724
Jake Hamby7c27be32014-03-03 13:25:59 -0800725 case CMD_GET_PREFERRED_NETWORK_TYPE:
726 request = (MainThreadRequest) msg.obj;
727 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700728 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800729 break;
730
731 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
732 ar = (AsyncResult) msg.obj;
733 request = (MainThreadRequest) ar.userObj;
734 if (ar.exception == null && ar.result != null) {
735 request.result = ar.result; // Integer
736 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800737 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800738 if (ar.result == null) {
739 loge("getPreferredNetworkType: Empty response");
740 } else if (ar.exception instanceof CommandException) {
741 loge("getPreferredNetworkType: CommandException: " +
742 ar.exception);
743 } else {
744 loge("getPreferredNetworkType: Unknown exception");
745 }
746 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700747 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800748 break;
749
750 case CMD_SET_PREFERRED_NETWORK_TYPE:
751 request = (MainThreadRequest) msg.obj;
752 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
753 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700754 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800755 break;
756
757 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
758 handleNullReturnEvent(msg, "setPreferredNetworkType");
759 break;
760
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000761 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
762 request = (MainThreadRequest)msg.obj;
763 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800764 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000765 break;
766
767 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
768 ar = (AsyncResult)msg.obj;
769 request = (MainThreadRequest)ar.userObj;
770 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700771 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000772 break;
773
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800774 case CMD_SET_VOICEMAIL_NUMBER:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
777 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800778 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
779 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800780 break;
781
782 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
783 handleNullReturnEvent(msg, "setVoicemailNumber");
784 break;
785
Stuart Scott54788802015-03-30 13:18:01 -0700786 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
789 request);
790 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
791 break;
792
793 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
794 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
795 break;
796
Shishir Agrawal302c8692015-06-19 13:49:39 -0700797 case CMD_PERFORM_NETWORK_SCAN:
798 request = (MainThreadRequest) msg.obj;
799 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
800 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
801 break;
802
803 case EVENT_PERFORM_NETWORK_SCAN_DONE:
804 ar = (AsyncResult) msg.obj;
805 request = (MainThreadRequest) ar.userObj;
806 CellNetworkScanResult cellScanResult;
807 if (ar.exception == null && ar.result != null) {
808 cellScanResult = new CellNetworkScanResult(
809 CellNetworkScanResult.STATUS_SUCCESS,
810 (List<OperatorInfo>) ar.result);
811 } else {
812 if (ar.result == null) {
813 loge("getCellNetworkScanResults: Empty response");
814 }
815 if (ar.exception != null) {
816 loge("getCellNetworkScanResults: Exception: " + ar.exception);
817 }
818 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
819 if (ar.exception instanceof CommandException) {
820 CommandException.Error error =
821 ((CommandException) (ar.exception)).getCommandError();
822 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
823 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
824 } else if (error == CommandException.Error.GENERIC_FAILURE) {
825 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
826 }
827 }
828 cellScanResult = new CellNetworkScanResult(errorCode, null);
829 }
830 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700831 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700832 break;
833
834 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
835 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700836 ManualNetworkSelectionArgument selArg =
837 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700838 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
839 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700840 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
841 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700842 break;
843
844 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700845 ar = (AsyncResult) msg.obj;
846 request = (MainThreadRequest) ar.userObj;
847 if (ar.exception == null) {
848 request.result = true;
849 } else {
850 request.result = false;
851 loge("setNetworkSelectionModeManual " + ar.exception);
852 }
853 notifyRequester(request);
854 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700855 break;
856
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700857 case CMD_GET_MODEM_ACTIVITY_INFO:
858 request = (MainThreadRequest) msg.obj;
859 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700860 if (defaultPhone != null) {
861 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
862 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700863 break;
864
865 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
866 ar = (AsyncResult) msg.obj;
867 request = (MainThreadRequest) ar.userObj;
868 if (ar.exception == null && ar.result != null) {
869 request.result = ar.result;
870 } else {
871 if (ar.result == null) {
872 loge("queryModemActivityInfo: Empty response");
873 } else if (ar.exception instanceof CommandException) {
874 loge("queryModemActivityInfo: CommandException: " +
875 ar.exception);
876 } else {
877 loge("queryModemActivityInfo: Unknown exception");
878 }
879 }
Amit Mahajand4766222016-01-28 15:28:28 -0800880 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
881 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800882 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800883 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700884 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700885 break;
886
Meng Wang1a7c35a2016-05-05 20:56:15 -0700887 case CMD_SET_ALLOWED_CARRIERS:
888 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800889 CarrierRestrictionRules argument =
890 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800892 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700893 break;
894
895 case EVENT_SET_ALLOWED_CARRIERS_DONE:
896 ar = (AsyncResult) msg.obj;
897 request = (MainThreadRequest) ar.userObj;
898 if (ar.exception == null && ar.result != null) {
899 request.result = ar.result;
900 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800901 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
902 if (ar.exception instanceof CommandException) {
903 loge("setAllowedCarriers: CommandException: " + ar.exception);
904 CommandException.Error error =
905 ((CommandException) (ar.exception)).getCommandError();
906 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
907 request.result =
908 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
909 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700910 } else {
911 loge("setAllowedCarriers: Unknown exception");
912 }
913 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700914 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700915 break;
916
917 case CMD_GET_ALLOWED_CARRIERS:
918 request = (MainThreadRequest) msg.obj;
919 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800920 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700921 break;
922
923 case EVENT_GET_ALLOWED_CARRIERS_DONE:
924 ar = (AsyncResult) msg.obj;
925 request = (MainThreadRequest) ar.userObj;
926 if (ar.exception == null && ar.result != null) {
927 request.result = ar.result;
928 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800929 request.result = new IllegalStateException(
930 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700931 if (ar.result == null) {
932 loge("getAllowedCarriers: Empty response");
933 } else if (ar.exception instanceof CommandException) {
934 loge("getAllowedCarriers: CommandException: " +
935 ar.exception);
936 } else {
937 loge("getAllowedCarriers: Unknown exception");
938 }
939 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700940 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700941 break;
942
Nathan Haroldb3014052017-01-25 15:57:32 -0800943 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
944 ar = (AsyncResult) msg.obj;
945 request = (MainThreadRequest) ar.userObj;
946 if (ar.exception == null && ar.result != null) {
947 request.result = ar.result;
948 } else {
949 request.result = new IllegalArgumentException(
950 "Failed to retrieve Forbidden Plmns");
951 if (ar.result == null) {
952 loge("getForbiddenPlmns: Empty response");
953 } else {
954 loge("getForbiddenPlmns: Unknown exception");
955 }
956 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700957 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800958 break;
959
960 case CMD_GET_FORBIDDEN_PLMNS:
961 request = (MainThreadRequest) msg.obj;
962 uiccCard = getUiccCardFromRequest(request);
963 if (uiccCard == null) {
964 loge("getForbiddenPlmns() UiccCard is null");
965 request.result = new IllegalArgumentException(
966 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700967 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800968 break;
969 }
970 Integer appType = (Integer) request.argument;
971 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
972 if (uiccApp == null) {
973 loge("getForbiddenPlmns() no app with specified type -- "
974 + appType);
975 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700976 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800977 break;
978 } else {
979 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
980 + " specified type -- " + appType);
981 }
982 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
983 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
984 onCompleted);
985 break;
986
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000987 case CMD_SWITCH_SLOTS:
988 request = (MainThreadRequest) msg.obj;
989 int[] physicalSlots = (int[]) request.argument;
990 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
991 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
992 break;
993
994 case EVENT_SWITCH_SLOTS_DONE:
995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
997 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700998 notifyRequester(request);
999 break;
1000 case CMD_GET_NETWORK_SELECTION_MODE:
1001 request = (MainThreadRequest) msg.obj;
1002 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1003 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1004 break;
1005
1006 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1007 ar = (AsyncResult) msg.obj;
1008 request = (MainThreadRequest) ar.userObj;
1009 if (ar.exception != null) {
1010 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1011 } else {
1012 int mode = ((int[]) ar.result)[0];
1013 if (mode == 0) {
1014 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1015 } else {
1016 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1017 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001018 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001019 notifyRequester(request);
1020 break;
1021 case CMD_GET_CDMA_ROAMING_MODE:
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1024 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1025 break;
1026 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1027 ar = (AsyncResult) msg.obj;
1028 request = (MainThreadRequest) ar.userObj;
1029 if (ar.exception != null) {
1030 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1031 } else {
1032 request.result = ((int[]) ar.result)[0];
1033 }
1034 notifyRequester(request);
1035 break;
1036 case CMD_SET_CDMA_ROAMING_MODE:
1037 request = (MainThreadRequest) msg.obj;
1038 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1039 int mode = (int) request.argument;
1040 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1041 break;
1042 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1043 ar = (AsyncResult) msg.obj;
1044 request = (MainThreadRequest) ar.userObj;
1045 request.result = ar.exception == null;
1046 notifyRequester(request);
1047 break;
1048 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1049 request = (MainThreadRequest) msg.obj;
1050 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1051 int subscriptionMode = (int) request.argument;
1052 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1053 break;
1054 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
1057 request.result = ar.exception == null;
1058 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001059 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 case CMD_GET_ALL_CELL_INFO:
1061 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001063 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001065 case EVENT_GET_ALL_CELL_INFO_DONE:
1066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001068 // If a timeout occurs, the response will be null
1069 request.result = (ar.exception == null && ar.result != null)
1070 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001071 synchronized (request) {
1072 request.notifyAll();
1073 }
1074 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 case CMD_REQUEST_CELL_INFO_UPDATE:
1076 request = (MainThreadRequest) msg.obj;
1077 request.phone.requestCellInfoUpdate(request.workSource,
1078 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1079 break;
1080 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1081 ar = (AsyncResult) msg.obj;
1082 request = (MainThreadRequest) ar.userObj;
1083 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1084 try {
1085 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001086 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001087 cb.onError(
1088 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1089 ar.exception.getClass().getName(),
1090 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001091 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001093 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001094 } else {
1095 // use the result as returned
1096 cb.onCellInfo((List<CellInfo>) ar.result);
1097 }
1098 } catch (RemoteException re) {
1099 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1100 }
1101 break;
1102 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001103 request = (MainThreadRequest) msg.obj;
1104 WorkSource ws = (WorkSource) request.argument;
1105 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001106 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001107 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001108 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001109 ar = (AsyncResult) msg.obj;
1110 request = (MainThreadRequest) ar.userObj;
1111 if (ar.exception == null) {
1112 request.result = ar.result;
1113 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001114 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001115 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001116 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001117 }
1118
1119 synchronized (request) {
1120 request.notifyAll();
1121 }
1122 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001123 case CMD_MODEM_REBOOT:
1124 request = (MainThreadRequest) msg.obj;
1125 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001126 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001127 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001128 case EVENT_CMD_MODEM_REBOOT_DONE:
1129 handleNullReturnEvent(msg, "rebootModem");
1130 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001131 case CMD_REQUEST_ENABLE_MODEM:
1132 request = (MainThreadRequest) msg.obj;
1133 boolean enable = (boolean) request.argument;
1134 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001135 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001136 PhoneConfigurationManager.getInstance()
1137 .enablePhone(request.phone, enable, onCompleted);
1138 break;
1139 case EVENT_ENABLE_MODEM_DONE:
1140 ar = (AsyncResult) msg.obj;
1141 request = (MainThreadRequest) ar.userObj;
1142 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001143 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001144 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001145 if ((boolean) request.result) {
1146 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1147 updateModemStateMetrics();
1148 } else {
1149 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1150 + ar.exception);
1151 }
1152 notifyRequester(request);
1153 break;
1154 case CMD_GET_MODEM_STATUS:
1155 request = (MainThreadRequest) msg.obj;
1156 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1157 PhoneConfigurationManager.getInstance()
1158 .getPhoneStatusFromModem(request.phone, onCompleted);
1159 break;
1160 case EVENT_GET_MODEM_STATUS_DONE:
1161 ar = (AsyncResult) msg.obj;
1162 request = (MainThreadRequest) ar.userObj;
1163 int id = request.phone.getPhoneId();
1164 if (ar.exception == null && ar.result != null) {
1165 request.result = ar.result;
1166 //update the cache as modem status has changed
1167 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1168 (boolean) request.result);
1169 } else {
1170 // Return true if modem status cannot be retrieved. For most cases,
1171 // modem status is on. And for older version modems, GET_MODEM_STATUS
1172 // and disable modem are not supported. Modem is always on.
1173 // TODO: this should be fixed in R to support a third
1174 // status UNKNOWN b/131631629
1175 request.result = true;
1176 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1177 + ar.exception);
1178 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001179 notifyRequester(request);
1180 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001181 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1182 ar = (AsyncResult) msg.obj;
1183 request = (MainThreadRequest) ar.userObj;
1184 if (ar.exception == null && ar.result != null) {
1185 request.result = ar.result;
1186 } else {
1187 request.result = -1;
1188 loge("Failed to set Forbidden Plmns");
1189 if (ar.result == null) {
1190 loge("setForbidenPlmns: Empty response");
1191 } else if (ar.exception != null) {
1192 loge("setForbiddenPlmns: Exception: " + ar.exception);
1193 request.result = -1;
1194 } else {
1195 loge("setForbiddenPlmns: Unknown exception");
1196 }
1197 }
1198 notifyRequester(request);
1199 break;
1200 case CMD_SET_FORBIDDEN_PLMNS:
1201 request = (MainThreadRequest) msg.obj;
1202 uiccCard = getUiccCardFromRequest(request);
1203 if (uiccCard == null) {
1204 loge("setForbiddenPlmns: UiccCard is null");
1205 request.result = -1;
1206 notifyRequester(request);
1207 break;
1208 }
1209 Pair<Integer, List<String>> setFplmnsArgs =
1210 (Pair<Integer, List<String>>) request.argument;
1211 appType = setFplmnsArgs.first;
1212 List<String> fplmns = setFplmnsArgs.second;
1213 uiccApp = uiccCard.getApplicationByType(appType);
1214 if (uiccApp == null) {
1215 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1216 request.result = -1;
1217 loge("Failed to get UICC App");
1218 notifyRequester(request);
1219 } else {
1220 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1221 ((SIMRecords) uiccApp.getIccRecords())
1222 .setForbiddenPlmns(onCompleted, fplmns);
1223 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001224 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001225 case CMD_ERASE_MODEM_CONFIG:
1226 request = (MainThreadRequest) msg.obj;
1227 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1228 defaultPhone.eraseModemConfig(onCompleted);
1229 break;
1230 case EVENT_ERASE_MODEM_CONFIG_DONE:
1231 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001232 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001233 default:
1234 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1235 break;
1236 }
1237 }
Jake Hambye994d462014-02-03 13:10:13 -08001238
Pengquan Menga1bb6272018-09-06 09:59:22 -07001239 private void notifyRequester(MainThreadRequest request) {
1240 synchronized (request) {
1241 request.notifyAll();
1242 }
1243 }
1244
Jake Hambye994d462014-02-03 13:10:13 -08001245 private void handleNullReturnEvent(Message msg, String command) {
1246 AsyncResult ar = (AsyncResult) msg.obj;
1247 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1248 if (ar.exception == null) {
1249 request.result = true;
1250 } else {
1251 request.result = false;
1252 if (ar.exception instanceof CommandException) {
1253 loge(command + ": CommandException: " + ar.exception);
1254 } else {
1255 loge(command + ": Unknown exception");
1256 }
1257 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001258 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260 }
1261
1262 /**
1263 * Posts the specified command to be executed on the main thread,
1264 * waits for the request to complete, and returns the result.
1265 * @see #sendRequestAsync
1266 */
1267 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001268 return sendRequest(
1269 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001270 }
1271
1272 /**
1273 * Posts the specified command to be executed on the main thread,
1274 * waits for the request to complete, and returns the result.
1275 * @see #sendRequestAsync
1276 */
1277 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1278 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001279 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001280 }
1281
1282 /**
1283 * Posts the specified command to be executed on the main thread,
1284 * waits for the request to complete, and returns the result.
1285 * @see #sendRequestAsync
1286 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001287 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001288 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001289 }
1290
1291 /**
1292 * Posts the specified command to be executed on the main thread,
1293 * waits for the request to complete, and returns the result.
1294 * @see #sendRequestAsync
1295 */
Nathan Harold92bed182018-10-12 18:16:49 -07001296 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1297 return sendRequest(command, argument, subId, null, workSource);
1298 }
1299
1300 /**
1301 * Posts the specified command to be executed on the main thread,
1302 * waits for the request to complete, and returns the result.
1303 * @see #sendRequestAsync
1304 */
1305 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1306 return sendRequest(
1307 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1308 }
1309
1310 /**
1311 * Posts the specified command to be executed on the main thread,
1312 * waits for the request to complete, and returns the result.
1313 * @see #sendRequestAsync
1314 */
1315 private Object sendRequest(
1316 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1318 throw new RuntimeException("This method will deadlock if called from the main thread.");
1319 }
1320
Nathan Harold92bed182018-10-12 18:16:49 -07001321 MainThreadRequest request = null;
1322 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1323 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1324 } else if (phone != null) {
1325 request = new MainThreadRequest(argument, phone, workSource);
1326 } else {
1327 request = new MainThreadRequest(argument, subId, workSource);
1328 }
1329
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330 Message msg = mMainThreadHandler.obtainMessage(command, request);
1331 msg.sendToTarget();
1332
1333 // Wait for the request to complete
1334 synchronized (request) {
1335 while (request.result == null) {
1336 try {
1337 request.wait();
1338 } catch (InterruptedException e) {
1339 // Do nothing, go back and wait until the request is complete
1340 }
1341 }
1342 }
1343 return request.result;
1344 }
1345
1346 /**
1347 * Asynchronous ("fire and forget") version of sendRequest():
1348 * Posts the specified command to be executed on the main thread, and
1349 * returns immediately.
1350 * @see #sendRequest
1351 */
1352 private void sendRequestAsync(int command) {
1353 mMainThreadHandler.sendEmptyMessage(command);
1354 }
1355
1356 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001357 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001358 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001359 */
1360 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001361 sendRequestAsync(command, argument, null, null);
1362 }
1363
1364 /**
1365 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1366 * @see {@link #sendRequest(int,Object)}
1367 */
1368 private void sendRequestAsync(
1369 int command, Object argument, Phone phone, WorkSource workSource) {
1370 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001371 Message msg = mMainThreadHandler.obtainMessage(command, request);
1372 msg.sendToTarget();
1373 }
1374
1375 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 * Initialize the singleton PhoneInterfaceManager instance.
1377 * This is only done once, at startup, from PhoneApp.onCreate().
1378 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001379 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380 synchronized (PhoneInterfaceManager.class) {
1381 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001382 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383 } else {
1384 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1385 }
1386 return sInstance;
1387 }
1388 }
1389
1390 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001391 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001394 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001395 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1397 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001398 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001399 mTelephonySharedPreferences =
1400 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001401 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001402 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001403
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 publish();
1405 }
1406
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001407 private Phone getDefaultPhone() {
1408 Phone thePhone = getPhone(getDefaultSubscription());
1409 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1410 }
1411
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 private void publish() {
1413 if (DBG) log("publish: " + this);
1414
Peter Wangc035ce42020-01-08 21:00:22 -08001415 TelephonyFrameworkInitializer
1416 .getTelephonyServiceManager()
1417 .getTelephonyServiceRegisterer()
1418 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419 }
1420
Stuart Scott584921c2015-01-15 17:10:34 -08001421 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001422 if (request.phone != null) {
1423 return request.phone;
1424 } else {
1425 return getPhoneFromSubId(request.subId);
1426 }
1427 }
1428
1429 private Phone getPhoneFromSubId(int subId) {
1430 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1431 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001432 }
1433
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001434 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1435 Phone phone = getPhoneFromRequest(request);
1436 return phone == null ? null :
1437 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1438 }
1439
Wink Saville36469e72014-06-11 15:17:00 -07001440 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001441 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001442 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001444
Naina Nallurid63128d2019-09-17 14:10:30 -07001445 private void sendEraseModemConfig(Phone phone) {
1446 if (phone != null) {
1447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1448 mApp, phone.getSubId(), "eraseModemConfig");
1449 final long identity = Binder.clearCallingIdentity();
1450 try {
1451 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1452 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1453 } finally {
1454 Binder.restoreCallingIdentity(identity);
1455 }
1456 }
1457 }
1458
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001460 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001461 }
1462
Wink Savilleb564aae2014-10-23 10:18:09 -07001463 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001464 if (DBG) log("dial: " + number);
1465 // No permission check needed here: This is just a wrapper around the
1466 // ACTION_DIAL intent, which is available to any app since it puts up
1467 // the UI before it does anything.
1468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001469 final long identity = Binder.clearCallingIdentity();
1470 try {
1471 String url = createTelUrl(number);
1472 if (url == null) {
1473 return;
1474 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001476 // PENDING: should we just silently fail if phone is offhook or ringing?
1477 PhoneConstants.State state = mCM.getState(subId);
1478 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1479 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1480 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1481 mApp.startActivity(intent);
1482 }
1483 } finally {
1484 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001485 }
1486 }
1487
1488 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001489 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001490 }
1491
Wink Savilleb564aae2014-10-23 10:18:09 -07001492 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001493 if (DBG) log("call: " + number);
1494
1495 // This is just a wrapper around the ACTION_CALL intent, but we still
1496 // need to do a permission check since we're calling startActivity()
1497 // from the context of the phone app.
1498 enforceCallPermission();
1499
Jordan Liu1617b712019-07-10 15:06:26 -07001500 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 != AppOpsManager.MODE_ALLOWED) {
1502 return;
1503 }
1504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001505 final long identity = Binder.clearCallingIdentity();
1506 try {
1507 String url = createTelUrl(number);
1508 if (url == null) {
1509 return;
1510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001512 boolean isValid = false;
1513 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1514 if (slist != null) {
1515 for (SubscriptionInfo subInfoRecord : slist) {
1516 if (subInfoRecord.getSubscriptionId() == subId) {
1517 isValid = true;
1518 break;
1519 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001520 }
Wink Saville08874612014-08-31 19:19:58 -07001521 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001522 if (!isValid) {
1523 return;
1524 }
Wink Saville08874612014-08-31 19:19:58 -07001525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001526 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1527 intent.putExtra(SUBSCRIPTION_KEY, subId);
1528 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1529 mApp.startActivity(intent);
1530 } finally {
1531 Binder.restoreCallingIdentity(identity);
1532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 }
1534
Wink Savilleb564aae2014-10-23 10:18:09 -07001535 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001537 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1538 }
1539
Wink Savilleb564aae2014-10-23 10:18:09 -07001540 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001541 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001542 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1543 }
1544
Wink Savilleb564aae2014-10-23 10:18:09 -07001545 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001546 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001547
1548 final long identity = Binder.clearCallingIdentity();
1549 try {
1550 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1551 checkSimPin.start();
1552 return checkSimPin.unlockSim(null, pin);
1553 } finally {
1554 Binder.restoreCallingIdentity(identity);
1555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 }
1557
Wink Savilleb564aae2014-10-23 10:18:09 -07001558 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001560
1561 final long identity = Binder.clearCallingIdentity();
1562 try {
1563 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1564 checkSimPuk.start();
1565 return checkSimPuk.unlockSim(puk, pin);
1566 } finally {
1567 Binder.restoreCallingIdentity(identity);
1568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 }
1570
1571 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001572 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 * a synchronous one.
1574 */
1575 private static class UnlockSim extends Thread {
1576
1577 private final IccCard mSimCard;
1578
1579 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001580 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1581 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582
1583 // For replies from SimCard interface
1584 private Handler mHandler;
1585
1586 // For async handler to identify request type
1587 private static final int SUPPLY_PIN_COMPLETE = 100;
1588
1589 public UnlockSim(IccCard simCard) {
1590 mSimCard = simCard;
1591 }
1592
1593 @Override
1594 public void run() {
1595 Looper.prepare();
1596 synchronized (UnlockSim.this) {
1597 mHandler = new Handler() {
1598 @Override
1599 public void handleMessage(Message msg) {
1600 AsyncResult ar = (AsyncResult) msg.obj;
1601 switch (msg.what) {
1602 case SUPPLY_PIN_COMPLETE:
1603 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1604 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001605 mRetryCount = msg.arg1;
1606 if (ar.exception != null) {
1607 if (ar.exception instanceof CommandException &&
1608 ((CommandException)(ar.exception)).getCommandError()
1609 == CommandException.Error.PASSWORD_INCORRECT) {
1610 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1611 } else {
1612 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1613 }
1614 } else {
1615 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001617 mDone = true;
1618 UnlockSim.this.notifyAll();
1619 }
1620 break;
1621 }
1622 }
1623 };
1624 UnlockSim.this.notifyAll();
1625 }
1626 Looper.loop();
1627 }
1628
1629 /*
1630 * Use PIN or PUK to unlock SIM card
1631 *
1632 * If PUK is null, unlock SIM card with PIN
1633 *
1634 * If PUK is not null, unlock SIM card with PUK and set PIN code
1635 */
Wink Saville9de0f752013-10-22 19:04:03 -07001636 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001637
1638 while (mHandler == null) {
1639 try {
1640 wait();
1641 } catch (InterruptedException e) {
1642 Thread.currentThread().interrupt();
1643 }
1644 }
1645 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1646
1647 if (puk == null) {
1648 mSimCard.supplyPin(pin, callback);
1649 } else {
1650 mSimCard.supplyPuk(puk, pin, callback);
1651 }
1652
1653 while (!mDone) {
1654 try {
1655 Log.d(LOG_TAG, "wait for done");
1656 wait();
1657 } catch (InterruptedException e) {
1658 // Restore the interrupted status
1659 Thread.currentThread().interrupt();
1660 }
1661 }
1662 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001663 int[] resultArray = new int[2];
1664 resultArray[0] = mResult;
1665 resultArray[1] = mRetryCount;
1666 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667 }
1668 }
1669
1670 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001671 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001672
1673 }
1674
Wink Savilleb564aae2014-10-23 10:18:09 -07001675 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 // No permission check needed here: this call is harmless, and it's
1677 // needed for the ServiceState.requestStateUpdate() call (which is
1678 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001679 final long identity = Binder.clearCallingIdentity();
1680 try {
1681 final Phone phone = getPhone(subId);
1682 if (phone != null) {
1683 phone.updateServiceLocation();
1684 }
1685 } finally {
1686 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001687 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 }
1689
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001690 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001691 @Override
1692 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001693 return isRadioOnWithFeature(callingPackage, null);
1694 }
1695
1696
1697 @Override
1698 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1699 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1700 callingFeatureId);
1701 }
1702
1703 @Deprecated
1704 @Override
1705 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1706 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001707 }
1708
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001709 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001710 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1711 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001713 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001714 return false;
1715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001716
1717 final long identity = Binder.clearCallingIdentity();
1718 try {
1719 return isRadioOnForSubscriber(subId);
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
1722 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001723 }
1724
1725 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001726 final long identity = Binder.clearCallingIdentity();
1727 try {
1728 final Phone phone = getPhone(subId);
1729 if (phone != null) {
1730 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1731 } else {
1732 return false;
1733 }
1734 } finally {
1735 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 }
1738
1739 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001740 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 }
Wink Saville36469e72014-06-11 15:17:00 -07001742
Wink Savilleb564aae2014-10-23 10:18:09 -07001743 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001745
1746 final long identity = Binder.clearCallingIdentity();
1747 try {
1748 final Phone phone = getPhone(subId);
1749 if (phone != null) {
1750 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1751 }
1752 } finally {
1753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001754 }
Wink Saville36469e72014-06-11 15:17:00 -07001755 }
1756
1757 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001758 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001759 }
1760
Wink Savilleb564aae2014-10-23 10:18:09 -07001761 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001763
1764 final long identity = Binder.clearCallingIdentity();
1765 try {
1766 final Phone phone = getPhone(subId);
1767 if (phone == null) {
1768 return false;
1769 }
1770 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1771 toggleRadioOnOffForSubscriber(subId);
1772 }
1773 return true;
1774 } finally {
1775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 }
Wink Saville36469e72014-06-11 15:17:00 -07001778
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001779 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001780 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001781 /*
1782 * If any of the Radios are available, it will need to be
1783 * shutdown. So return true if any Radio is available.
1784 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001785 final long identity = Binder.clearCallingIdentity();
1786 try {
1787 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1788 Phone phone = PhoneFactory.getPhone(i);
1789 if (phone != null && phone.isRadioAvailable()) return true;
1790 }
1791 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1792 return false;
1793 } finally {
1794 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001795 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001796 }
1797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001798 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001799 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001800 enforceModifyPermission();
1801
1802 final long identity = Binder.clearCallingIdentity();
1803 try {
1804 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1805 logv("Shutting down Phone " + i);
1806 shutdownRadioUsingPhoneId(i);
1807 }
1808 } finally {
1809 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001810 }
1811 }
1812
1813 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001814 Phone phone = PhoneFactory.getPhone(phoneId);
1815 if (phone != null && phone.isRadioAvailable()) {
1816 phone.shutdownRadio();
1817 }
1818 }
1819
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001821 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001822
1823 final long identity = Binder.clearCallingIdentity();
1824 try {
1825 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1826 if (defaultPhone != null) {
1827 defaultPhone.setRadioPower(turnOn);
1828 return true;
1829 } else {
1830 loge("There's no default phone.");
1831 return false;
1832 }
1833 } finally {
1834 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001835 }
Wink Saville36469e72014-06-11 15:17:00 -07001836 }
1837
Wink Savilleb564aae2014-10-23 10:18:09 -07001838 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001840
1841 final long identity = Binder.clearCallingIdentity();
1842 try {
1843 final Phone phone = getPhone(subId);
1844 if (phone != null) {
1845 phone.setRadioPower(turnOn);
1846 return true;
1847 } else {
1848 return false;
1849 }
1850 } finally {
1851 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001852 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 }
1854
Wink Saville36469e72014-06-11 15:17:00 -07001855 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001856 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 public boolean enableDataConnectivity() {
1858 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001859
1860 final long identity = Binder.clearCallingIdentity();
1861 try {
1862 int subId = mSubscriptionController.getDefaultDataSubId();
1863 final Phone phone = getPhone(subId);
1864 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001865 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001866 return true;
1867 } else {
1868 return false;
1869 }
1870 } finally {
1871 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 }
1874
Wink Saville36469e72014-06-11 15:17:00 -07001875 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001876 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 public boolean disableDataConnectivity() {
1878 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001879
1880 final long identity = Binder.clearCallingIdentity();
1881 try {
1882 int subId = mSubscriptionController.getDefaultDataSubId();
1883 final Phone phone = getPhone(subId);
1884 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001885 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001886 return true;
1887 } else {
1888 return false;
1889 }
1890 } finally {
1891 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 }
1894
Sanket Padawe356d7632015-06-22 14:03:32 -07001895 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001896 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001897 final long identity = Binder.clearCallingIdentity();
1898 try {
1899 final Phone phone = getPhone(subId);
1900 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001901 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001902 } else {
1903 return false;
1904 }
1905 } finally {
1906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 }
1909
1910 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001911 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001912 }
1913
pkanwarae03a6b2016-11-06 20:37:09 -08001914 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001915 enforceCallPermission();
1916
1917 final long identity = Binder.clearCallingIdentity();
1918 try {
1919 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1920 return;
1921 }
1922 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1923 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1924 } finally {
1925 Binder.restoreCallingIdentity(identity);
1926 }
pkanwar32d516d2016-10-14 19:37:38 -07001927 };
1928
Wink Savilleb564aae2014-10-23 10:18:09 -07001929 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001931
1932 final long identity = Binder.clearCallingIdentity();
1933 try {
1934 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1935 return false;
1936 }
1937 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1938 } finally {
1939 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001940 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
1942
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001944 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001945 }
1946
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001947 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001948 final long identity = Binder.clearCallingIdentity();
1949 try {
1950 Phone phone = PhoneFactory.getPhone(slotIndex);
1951 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1952 PhoneConstantConversions.convertCallState(phone.getState());
1953 } finally {
1954 Binder.restoreCallingIdentity(identity);
1955 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 }
1957
Sanket Padawe356d7632015-06-22 14:03:32 -07001958 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001959 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001960 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1961 }
1962
1963 @Override
1964 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001965 final long identity = Binder.clearCallingIdentity();
1966 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001967 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001968 if (phone != null) {
1969 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1970 } else {
1971 return PhoneConstantConversions.convertDataState(
1972 PhoneConstants.DataState.DISCONNECTED);
1973 }
1974 } finally {
1975 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 }
1978
Sanket Padawe356d7632015-06-22 14:03:32 -07001979 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001980 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001981 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1982 }
1983
1984 @Override
1985 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 final long identity = Binder.clearCallingIdentity();
1987 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001988 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001989 if (phone != null) {
1990 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1991 } else {
1992 return TelephonyManager.DATA_ACTIVITY_NONE;
1993 }
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 }
1998
1999 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002000 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002001 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002002 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002003
2004 LocationAccessPolicy.LocationPermissionResult locationResult =
2005 LocationAccessPolicy.checkLocationPermission(mApp,
2006 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2007 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002008 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002009 .setCallingPid(Binder.getCallingPid())
2010 .setCallingUid(Binder.getCallingUid())
2011 .setMethod("getCellLocation")
2012 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2013 .build());
2014 switch (locationResult) {
2015 case DENIED_HARD:
2016 throw new SecurityException("Not allowed to access cell location");
2017 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002018 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2019 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002020 }
2021
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002022 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002023 final long identity = Binder.clearCallingIdentity();
2024 try {
2025 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002026 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002027 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002028 } finally {
2029 Binder.restoreCallingIdentity(identity);
2030 }
Svetoslav64fad262015-04-14 14:35:21 -07002031 }
2032
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002034 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2035 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002036 if (!TextUtils.isEmpty(callingPackage)) {
2037 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2039 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002040 return "";
2041 }
2042 }
2043
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002044 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2045 // registered cell info, so return a NULL country instead.
2046 final long identity = Binder.clearCallingIdentity();
2047 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002048 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2049 // Get default phone in this case.
2050 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2051 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002052 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002053 // Todo: fix this when we can get the actual cellular network info when the device
2054 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002055 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002056 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2057 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002058 return "";
2059 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002060 Phone phone = PhoneFactory.getPhone(phoneId);
2061 if (phone != null) {
2062 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002063 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002064 if (sst != null) {
2065 LocaleTracker lt = sst.getLocaleTracker();
2066 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002067 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2068 return lt.getCurrentCountry();
2069 } else if (emergencyNumberTracker != null) {
2070 return emergencyNumberTracker.getEmergencyCountryIso();
2071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072 }
2073 }
2074 }
2075 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002076 } finally {
2077 Binder.restoreCallingIdentity(identity);
2078 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002079 }
2080
2081 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002083 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002084 }
2085
Sanket Padawe356d7632015-06-22 14:03:32 -07002086 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002087 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 mApp.enforceCallingOrSelfPermission(
2089 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002090
2091 final long identity = Binder.clearCallingIdentity();
2092 try {
2093 final Phone phone = getPhone(subId);
2094 if (phone != null) {
2095 phone.enableLocationUpdates();
2096 }
2097 } finally {
2098 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002099 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 }
2101
2102 @Override
2103 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002104 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002105 }
2106
Sanket Padawe356d7632015-06-22 14:03:32 -07002107 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002108 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 mApp.enforceCallingOrSelfPermission(
2110 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002111
2112 final long identity = Binder.clearCallingIdentity();
2113 try {
2114 final Phone phone = getPhone(subId);
2115 if (phone != null) {
2116 phone.disableLocationUpdates();
2117 }
2118 } finally {
2119 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002120 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 }
2122
Nathan Harold31d7ff32018-10-15 20:20:30 -07002123 /**
2124 * Returns the target SDK version number for a given package name.
2125 *
Nathan Haroldec184742019-07-10 17:04:16 -07002126 * This call MUST be invoked before clearing the calling UID.
2127 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002128 * @return target SDK if the package is found or INT_MAX.
2129 */
2130 private int getTargetSdk(String packageName) {
2131 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002132 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002133 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002134 if (ai != null) return ai.targetSdkVersion;
2135 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002136 loge("Failed to get package info for pkg="
2137 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002138 }
2139 return Integer.MAX_VALUE;
2140 }
2141
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002142 @Override
2143 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002144 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2145 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002146 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002147 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2148 throw new SecurityException(
2149 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2150 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002151
Jordan Liu1617b712019-07-10 15:06:26 -07002152 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2154 return null;
2155 }
Svetoslav64fad262015-04-14 14:35:21 -07002156
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002157 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002159 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002160 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161
Nathan Haroldf180aac2018-06-01 18:43:55 -07002162 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2163 for (CellInfo ci : info) {
2164 if (ci instanceof CellInfoGsm) {
2165 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2166 } else if (ci instanceof CellInfoWcdma) {
2167 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002170 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 }
2172
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002173 private List<CellInfo> getCachedCellInfo() {
2174 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2175 for (Phone phone : PhoneFactory.getPhones()) {
2176 List<CellInfo> info = phone.getAllCellInfo();
2177 if (info != null) cellInfos.addAll(info);
2178 }
2179 return cellInfos;
2180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181
2182 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002183 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002184 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002185 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002186
2187 LocationAccessPolicy.LocationPermissionResult locationResult =
2188 LocationAccessPolicy.checkLocationPermission(mApp,
2189 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2190 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002191 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002192 .setCallingPid(Binder.getCallingPid())
2193 .setCallingUid(Binder.getCallingUid())
2194 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002195 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002196 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2197 .build());
2198 switch (locationResult) {
2199 case DENIED_HARD:
2200 throw new SecurityException("Not allowed to access cell info");
2201 case DENIED_SOFT:
2202 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 }
2204
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002205 final int targetSdk = getTargetSdk(callingPackage);
2206 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2207 return getCachedCellInfo();
2208 }
2209
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002210 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002211 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002212 final long identity = Binder.clearCallingIdentity();
2213 try {
2214 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2215 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002216 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002217 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002218 if (info != null) cellInfos.addAll(info);
2219 }
2220 return cellInfos;
2221 } finally {
2222 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 }
2224 }
2225
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002226 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002227 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2228 String callingFeatureId) {
2229 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2230 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002231 }
2232
2233 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002234 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2235 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002236 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002237 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002238 }
2239
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002240 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2241 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002242 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002243 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002244
2245 LocationAccessPolicy.LocationPermissionResult locationResult =
2246 LocationAccessPolicy.checkLocationPermission(mApp,
2247 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2248 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002249 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002250 .setCallingPid(Binder.getCallingPid())
2251 .setCallingUid(Binder.getCallingUid())
2252 .setMethod("requestCellInfoUpdate")
2253 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2254 .build());
2255 switch (locationResult) {
2256 case DENIED_HARD:
2257 throw new SecurityException("Not allowed to access cell info");
2258 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002259 try {
2260 cb.onCellInfo(new ArrayList<CellInfo>());
2261 } catch (RemoteException re) {
2262 // Drop without consequences
2263 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002264 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002265 }
2266
Nathan Harolda939a962019-05-09 10:13:47 -07002267
2268 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002269 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2270
2271 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2272 }
2273
2274 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002276 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002277 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002278
2279 final long identity = Binder.clearCallingIdentity();
2280 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002281 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002282 } finally {
2283 Binder.restoreCallingIdentity(identity);
2284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 }
2286
Shishir Agrawala9f32182016-04-12 12:00:16 -07002287 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002288 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002289 Phone phone = PhoneFactory.getPhone(slotIndex);
2290 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002291 return null;
2292 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002293 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002294 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002295 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002296 return null;
2297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002298
2299 final long identity = Binder.clearCallingIdentity();
2300 try {
2301 return phone.getImei();
2302 } finally {
2303 Binder.restoreCallingIdentity(identity);
2304 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002305 }
2306
2307 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002308 public String getTypeAllocationCodeForSlot(int slotIndex) {
2309 Phone phone = PhoneFactory.getPhone(slotIndex);
2310 String tac = null;
2311 if (phone != null) {
2312 String imei = phone.getImei();
2313 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2314 }
2315 return tac;
2316 }
2317
2318 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002319 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002320 Phone phone = PhoneFactory.getPhone(slotIndex);
2321 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002322 return null;
2323 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002324
Jeff Davidson913390f2018-02-23 17:11:49 -08002325 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002326 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002327 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002328 return null;
2329 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002330
2331 final long identity = Binder.clearCallingIdentity();
2332 try {
2333 return phone.getMeid();
2334 } finally {
2335 Binder.restoreCallingIdentity(identity);
2336 }
Jack Yu2af8d712017-03-15 17:14:14 -07002337 }
2338
2339 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002340 public String getManufacturerCodeForSlot(int slotIndex) {
2341 Phone phone = PhoneFactory.getPhone(slotIndex);
2342 String manufacturerCode = null;
2343 if (phone != null) {
2344 String meid = phone.getMeid();
2345 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2346 }
2347 return manufacturerCode;
2348 }
2349
2350 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002351 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2352 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002353 Phone phone = PhoneFactory.getPhone(slotIndex);
2354 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002355 return null;
2356 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002357 int subId = phone.getSubId();
2358 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002359 mApp, subId, callingPackage, callingFeatureId,
2360 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002361 return null;
2362 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002363
2364 final long identity = Binder.clearCallingIdentity();
2365 try {
2366 return phone.getDeviceSvn();
2367 } finally {
2368 Binder.restoreCallingIdentity(identity);
2369 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002370 }
2371
fionaxu43304da2017-11-27 22:51:16 -08002372 @Override
2373 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002374 final long identity = Binder.clearCallingIdentity();
2375 try {
2376 final Phone phone = getPhone(subId);
2377 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
2380 }
fionaxu43304da2017-11-27 22:51:16 -08002381 }
2382
2383 @Override
2384 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002385 final long identity = Binder.clearCallingIdentity();
2386 try {
2387 final Phone phone = getPhone(subId);
2388 return phone == null ? null : phone.getCarrierName();
2389 } finally {
2390 Binder.restoreCallingIdentity(identity);
2391 }
fionaxu43304da2017-11-27 22:51:16 -08002392 }
2393
calvinpanffe225e2018-11-01 19:43:06 +08002394 @Override
chen xu0026ca62019-03-06 15:28:50 -08002395 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002396 final long identity = Binder.clearCallingIdentity();
2397 try {
2398 final Phone phone = getPhone(subId);
2399 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002400 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002401 } finally {
2402 Binder.restoreCallingIdentity(identity);
2403 }
2404 }
2405
2406 @Override
chen xu0026ca62019-03-06 15:28:50 -08002407 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002408 final long identity = Binder.clearCallingIdentity();
2409 try {
2410 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002411 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002412 } finally {
2413 Binder.restoreCallingIdentity(identity);
2414 }
2415 }
2416
chen xu651eec72018-11-11 19:03:44 -08002417 @Override
chen xu864e11c2018-12-06 22:10:03 -08002418 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2419 if (!isSubscriptionMccMnc) {
2420 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2421 }
chen xu651eec72018-11-11 19:03:44 -08002422 final Phone phone = PhoneFactory.getPhone(slotIndex);
2423 if (phone == null) {
2424 return TelephonyManager.UNKNOWN_CARRIER_ID;
2425 }
2426 final long identity = Binder.clearCallingIdentity();
2427 try {
2428 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2429 } finally {
2430 Binder.restoreCallingIdentity(identity);
2431 }
2432 }
2433
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002434 //
2435 // Internal helper methods.
2436 //
2437
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002438 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2440 *
2441 * @throws SecurityException if the caller does not have the required permission
2442 */
2443 private void enforceModifyPermission() {
2444 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2445 }
2446
Shuo Qian3b6ee772019-11-13 17:43:31 -08002447 private void enforceActiveEmergencySessionPermission() {
2448 mApp.enforceCallingOrSelfPermission(
2449 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2450 }
2451
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 /**
2453 * Make sure the caller has the CALL_PHONE permission.
2454 *
2455 * @throws SecurityException if the caller does not have the required permission
2456 */
2457 private void enforceCallPermission() {
2458 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2459 }
2460
paulhu5a773602019-08-23 19:17:33 +08002461 private void enforceSettingsPermission() {
2462 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002463 }
2464
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 private String createTelUrl(String number) {
2466 if (TextUtils.isEmpty(number)) {
2467 return null;
2468 }
2469
Jake Hambye994d462014-02-03 13:10:13 -08002470 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 }
2472
Ihab Awadf9e92732013-12-05 18:02:52 -08002473 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2475 }
2476
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002477 private static void logv(String msg) {
2478 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2479 }
2480
Ihab Awadf9e92732013-12-05 18:02:52 -08002481 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2483 }
2484
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002485 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002487 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002488 }
2489
Sanket Padawe356d7632015-06-22 14:03:32 -07002490 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002491 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492 final long identity = Binder.clearCallingIdentity();
2493 try {
2494 final Phone phone = PhoneFactory.getPhone(slotIndex);
2495 if (phone == null) {
2496 return PhoneConstants.PHONE_TYPE_NONE;
2497 } else {
2498 return phone.getPhoneType();
2499 }
2500 } finally {
2501 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002502 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002503 }
2504
2505 /**
2506 * Returns the CDMA ERI icon index to display
2507 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002508 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002509 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2510 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2511 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002512 }
2513
Sanket Padawe356d7632015-06-22 14:03:32 -07002514 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002515 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2516 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002517 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002518 mApp, subId, callingPackage, callingFeatureId,
2519 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002520 return -1;
2521 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002522
2523 final long identity = Binder.clearCallingIdentity();
2524 try {
2525 final Phone phone = getPhone(subId);
2526 if (phone != null) {
2527 return phone.getCdmaEriIconIndex();
2528 } else {
2529 return -1;
2530 }
2531 } finally {
2532 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002534 }
2535
2536 /**
2537 * Returns the CDMA ERI icon mode,
2538 * 0 - ON
2539 * 1 - FLASHING
2540 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002541 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002542 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2543 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2544 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002545 }
2546
Sanket Padawe356d7632015-06-22 14:03:32 -07002547 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002548 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2549 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002550 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002551 mApp, subId, callingPackage, callingFeatureId,
2552 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002553 return -1;
2554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002555
2556 final long identity = Binder.clearCallingIdentity();
2557 try {
2558 final Phone phone = getPhone(subId);
2559 if (phone != null) {
2560 return phone.getCdmaEriIconMode();
2561 } else {
2562 return -1;
2563 }
2564 } finally {
2565 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 }
2568
2569 /**
2570 * Returns the CDMA ERI text,
2571 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002572 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002573 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2574 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2575 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002576 }
2577
Sanket Padawe356d7632015-06-22 14:03:32 -07002578 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002579 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2580 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002581 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002582 mApp, subId, callingPackage, callingFeatureId,
2583 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002584 return null;
2585 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002586
2587 final long identity = Binder.clearCallingIdentity();
2588 try {
2589 final Phone phone = getPhone(subId);
2590 if (phone != null) {
2591 return phone.getCdmaEriText();
2592 } else {
2593 return null;
2594 }
2595 } finally {
2596 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002598 }
2599
2600 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002601 * Returns the CDMA MDN.
2602 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002603 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002604 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2606 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607
2608 final long identity = Binder.clearCallingIdentity();
2609 try {
2610 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002611 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 return phone.getLine1Number();
2613 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002614 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 return null;
2616 }
2617 } finally {
2618 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002619 }
2620 }
2621
2622 /**
2623 * Returns the CDMA MIN.
2624 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002625 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002626 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2628 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629
2630 final long identity = Binder.clearCallingIdentity();
2631 try {
2632 final Phone phone = getPhone(subId);
2633 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2634 return phone.getCdmaMin();
2635 } else {
2636 return null;
2637 }
2638 } finally {
2639 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002640 }
2641 }
2642
Hall Liud892bec2018-11-30 14:51:45 -08002643 @Override
2644 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2645 INumberVerificationCallback callback, String callingPackage) {
2646 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2647 != PERMISSION_GRANTED) {
2648 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2649 }
2650 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2651
2652 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2653 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2654 throw new SecurityException("Calling package must be configured in the device config");
2655 }
2656
2657 if (range == null) {
2658 throw new NullPointerException("Range must be non-null");
2659 }
2660
2661 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002662 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002663
2664 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2665 }
2666
Junda Liuca05d5d2014-08-14 22:36:34 -07002667 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668 * Returns true if CDMA provisioning needs to run.
2669 */
2670 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 final long identity = Binder.clearCallingIdentity();
2672 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002673 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674 } finally {
2675 Binder.restoreCallingIdentity(identity);
2676 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002677 }
2678
2679 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002680 * Sets the voice mail number of a given subId.
2681 */
2682 @Override
2683 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002684 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2685 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686
2687 final long identity = Binder.clearCallingIdentity();
2688 try {
2689 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2690 new Pair<String, String>(alphaTag, number), new Integer(subId));
2691 return success;
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
2694 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002695 }
2696
Ta-wei Yen87c49842016-05-13 21:19:52 -07002697 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002698 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2699 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002700 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2701 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002702 if (!TextUtils.equals(callingPackage, systemDialer)) {
2703 throw new SecurityException("caller must be system dialer");
2704 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705
2706 final long identity = Binder.clearCallingIdentity();
2707 try {
2708 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2709 if (phoneAccountHandle == null) {
2710 return null;
2711 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002712 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713 } finally {
2714 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002715 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002716 }
2717
2718 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002719 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2720 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002721 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002722 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002723 mApp, subId, callingPackage, callingFeatureId,
2724 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002725 return null;
2726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002728 final long identity = Binder.clearCallingIdentity();
2729 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002730 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002731 } finally {
2732 Binder.restoreCallingIdentity(identity);
2733 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002734 }
2735
2736 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002737 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2738 VisualVoicemailSmsFilterSettings settings) {
2739 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740
2741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002744 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002745 } finally {
2746 Binder.restoreCallingIdentity(identity);
2747 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002748 }
2749
2750 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002751 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2752 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753
2754 final long identity = Binder.clearCallingIdentity();
2755 try {
2756 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002757 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758 } finally {
2759 Binder.restoreCallingIdentity(identity);
2760 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002761 }
2762
2763 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002764 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2765 String callingPackage, int subId) {
2766 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767
2768 final long identity = Binder.clearCallingIdentity();
2769 try {
2770 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002771 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 } finally {
2773 Binder.restoreCallingIdentity(identity);
2774 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002775 }
2776
2777 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002778 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002779 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780
2781 final long identity = Binder.clearCallingIdentity();
2782 try {
2783 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002784 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 } finally {
2786 Binder.restoreCallingIdentity(identity);
2787 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002788 }
2789
2790 @Override
2791 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2792 String number, int port, String text, PendingIntent sentIntent) {
2793 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002794 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002795 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002796 SmsController smsController = PhoneFactory.getSmsController();
2797 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2798 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002799 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002800
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002801 /**
fionaxu0152e512016-11-14 13:36:14 -08002802 * Sets the voice activation state of a given subId.
2803 */
2804 @Override
2805 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2807 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808
2809 final long identity = Binder.clearCallingIdentity();
2810 try {
2811 final Phone phone = getPhone(subId);
2812 if (phone != null) {
2813 phone.setVoiceActivationState(activationState);
2814 } else {
2815 loge("setVoiceActivationState fails with invalid subId: " + subId);
2816 }
2817 } finally {
2818 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002819 }
2820 }
2821
2822 /**
2823 * Sets the data activation state of a given subId.
2824 */
2825 @Override
2826 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2828 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829
2830 final long identity = Binder.clearCallingIdentity();
2831 try {
2832 final Phone phone = getPhone(subId);
2833 if (phone != null) {
2834 phone.setDataActivationState(activationState);
2835 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002836 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002837 }
2838 } finally {
2839 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002840 }
2841 }
2842
2843 /**
2844 * Returns the voice activation state of a given subId.
2845 */
2846 @Override
2847 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002848 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849
fionaxu0152e512016-11-14 13:36:14 -08002850 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 if (phone != null) {
2854 return phone.getVoiceActivationState();
2855 } else {
2856 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2857 }
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002860 }
2861 }
2862
2863 /**
2864 * Returns the data activation state of a given subId.
2865 */
2866 @Override
2867 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002868 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869
fionaxu0152e512016-11-14 13:36:14 -08002870 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 if (phone != null) {
2874 return phone.getDataActivationState();
2875 } else {
2876 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2877 }
2878 } finally {
2879 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002880 }
2881 }
2882
2883 /**
Wink Saville36469e72014-06-11 15:17:00 -07002884 * Returns the unread count of voicemails for a subId
2885 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002886 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002887 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2888 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002889 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002890 mApp, subId, callingPackage, callingFeatureId,
2891 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002892 return 0;
2893 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894 final long identity = Binder.clearCallingIdentity();
2895 try {
2896 final Phone phone = getPhone(subId);
2897 if (phone != null) {
2898 return phone.getVoiceMessageCount();
2899 } else {
2900 return 0;
2901 }
2902 } finally {
2903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002905 }
2906
2907 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002908 * returns true, if the device is in a state where both voice and data
2909 * are supported simultaneously. This can change based on location or network condition.
2910 */
2911 @Override
2912 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002913 final long identity = Binder.clearCallingIdentity();
2914 try {
2915 final Phone phone = getPhone(subId);
2916 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
2919 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002920 }
2921
2922 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002923 * Send the dialer code if called from the current default dialer or the caller has
2924 * carrier privilege.
2925 * @param inputCode The dialer code to send
2926 */
2927 @Override
2928 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002929 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002930 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002931 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2932 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002933 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002934 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002935 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002936 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937
2938 final long identity = Binder.clearCallingIdentity();
2939 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002940 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 } finally {
2942 Binder.restoreCallingIdentity(identity);
2943 }
fionaxu235cc5e2017-03-06 22:25:57 -08002944 }
2945
Pengquan Menga1bb6272018-09-06 09:59:22 -07002946 @Override
2947 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002948 if (!isActiveSubscription(subId)) {
2949 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2950 }
2951
Pengquan Menga1bb6272018-09-06 09:59:22 -07002952 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2953 }
2954
Brad Ebinger35c841c2018-10-01 10:40:55 -07002955 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002956 public boolean isInEmergencySmsMode() {
2957 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 for (Phone phone : PhoneFactory.getPhones()) {
2961 if (phone.isInEmergencySmsMode()) {
2962 return true;
2963 }
2964 }
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
2967 }
2968 return false;
2969 }
2970
2971 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002972 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2973 throws RemoteException {
2974 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002975 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2976 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2977 "IMS not available on device.");
2978 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002979 final long token = Binder.clearCallingIdentity();
2980 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002981 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002982 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002983 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002984 } catch (ImsException e) {
2985 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002986 } finally {
2987 Binder.restoreCallingIdentity(token);
2988 }
2989 }
2990
2991 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002992 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2993 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002994 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2995 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2996 }
Meng Wangafbc5852019-09-19 17:37:13 -07002997 final long token = Binder.clearCallingIdentity();
2998 try {
2999 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3000 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3001 .removeRegistrationCallbackForSubscription(c, subId);
3002 } catch (ImsException e) {
3003 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3004 + "is inactive, ignoring unregister.");
3005 // If the subscription is no longer active, just return, since the callback
3006 // will already have been removed internally.
3007 } finally {
3008 Binder.restoreCallingIdentity(token);
3009 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003010 }
3011
Brad Ebingera34a6c22019-10-22 17:36:18 -07003012 /**
3013 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3014 */
3015 @Override
3016 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3017 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3018 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3019 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3020 "IMS not available on device.");
3021 }
3022 final long token = Binder.clearCallingIdentity();
3023 try {
3024 Phone phone = getPhone(subId);
3025 if (phone == null) {
3026 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3027 + subId + "'");
3028 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3029 }
3030 phone.getImsRegistrationState(regState -> {
3031 try {
3032 consumer.accept((regState == null)
3033 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3034 } catch (RemoteException e) {
3035 // Ignore if the remote process is no longer available to call back.
3036 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3037 }
3038 });
3039 } finally {
3040 Binder.restoreCallingIdentity(token);
3041 }
3042 }
3043
3044 /**
3045 * Get the transport type for the IMS service registration state.
3046 */
3047 @Override
3048 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3049 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3050 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3051 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3052 "IMS not available on device.");
3053 }
3054 final long token = Binder.clearCallingIdentity();
3055 try {
3056 Phone phone = getPhone(subId);
3057 if (phone == null) {
3058 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3059 + subId + "'");
3060 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3061 }
3062 phone.getImsRegistrationTech(regTech -> {
3063 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3064 int regTechConverted = (regTech == null)
3065 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3066 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3067 regTechConverted);
3068 try {
3069 consumer.accept(regTechConverted);
3070 } catch (RemoteException e) {
3071 // Ignore if the remote process is no longer available to call back.
3072 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3073 }
3074 });
3075 } finally {
3076 Binder.restoreCallingIdentity(token);
3077 }
3078 }
3079
Brad Ebinger35c841c2018-10-01 10:40:55 -07003080 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003081 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3082 throws RemoteException {
3083 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003084 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3085 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3086 "IMS not available on device.");
3087 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003088 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3089 final long token = Binder.clearCallingIdentity();
3090 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003091 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003092 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003093 } catch (ImsException e) {
3094 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003095 } finally {
3096 Binder.restoreCallingIdentity(token);
3097 }
3098 }
3099
3100 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003101 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3102 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003103 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3104 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3105 }
Meng Wangafbc5852019-09-19 17:37:13 -07003106
3107 final long token = Binder.clearCallingIdentity();
3108 try {
3109 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3110 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003111 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003112 } catch (ImsException e) {
3113 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3114 + "is inactive, ignoring unregister.");
3115 // If the subscription is no longer active, just return, since the callback
3116 // will already have been removed internally.
3117 } finally {
3118 Binder.restoreCallingIdentity(token);
3119 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003120 }
3121
3122 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003123 public boolean isCapable(int subId, int capability, int regTech) {
3124 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003125 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3126 final long token = Binder.clearCallingIdentity();
3127 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003128 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003129 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003130 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003131 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3132 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003133 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003134 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3135 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003136 } finally {
3137 Binder.restoreCallingIdentity(token);
3138 }
3139 }
3140
3141 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003142 public boolean isAvailable(int subId, int capability, int regTech) {
3143 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003144 final long token = Binder.clearCallingIdentity();
3145 try {
3146 Phone phone = getPhone(subId);
3147 if (phone == null) return false;
3148 return phone.isImsCapabilityAvailable(capability, regTech);
3149 } finally {
3150 Binder.restoreCallingIdentity(token);
3151 }
3152 }
3153
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003154 /**
3155 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3156 * subscription.
3157 * @param subId The subscription to use to check the configuration.
3158 * @param callback The callback that will be used to send the result.
3159 * @param capability The MmTelFeature capability that will be used to send the result.
3160 * @param transportType The transport type of the MmTelFeature capability.
3161 */
3162 @Override
3163 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3164 int transportType) {
3165 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3166 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3167 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3168 "IMS not available on device.");
3169 }
3170 final long token = Binder.clearCallingIdentity();
3171 try {
3172 int slotId = getSlotIndex(subId);
3173 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3174 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3175 + subId + "'");
3176 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3177 }
3178 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3179 transportType, aBoolean -> {
3180 try {
3181 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3182 } catch (RemoteException e) {
3183 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3184 + "running. Ignore");
3185 }
3186 });
3187 } finally {
3188 Binder.restoreCallingIdentity(token);
3189 }
3190 }
3191
Brad Ebinger35c841c2018-10-01 10:40:55 -07003192 @Override
3193 public boolean isAdvancedCallingSettingEnabled(int subId) {
3194 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3195 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3196 final long token = Binder.clearCallingIdentity();
3197 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003198 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003199 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003200 } catch (ImsException e) {
3201 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003202 } finally {
3203 Binder.restoreCallingIdentity(token);
3204 }
3205 }
3206
3207 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003208 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003210 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003211 final long identity = Binder.clearCallingIdentity();
3212 try {
3213 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003214 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003215 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003216 } catch (ImsException e) {
3217 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003218 } finally {
3219 Binder.restoreCallingIdentity(identity);
3220 }
3221 }
3222
3223 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003224 public boolean isVtSettingEnabled(int subId) {
3225 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003226 final long identity = Binder.clearCallingIdentity();
3227 try {
3228 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003229 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3230 } catch (ImsException e) {
3231 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003232 } finally {
3233 Binder.restoreCallingIdentity(identity);
3234 }
3235 }
3236
3237 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003238 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003240 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003244 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003245 } catch (ImsException e) {
3246 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003247 } finally {
3248 Binder.restoreCallingIdentity(identity);
3249 }
3250 }
3251
3252 @Override
3253 public boolean isVoWiFiSettingEnabled(int subId) {
3254 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3255 final long identity = Binder.clearCallingIdentity();
3256 try {
3257 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003258 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003259 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003260 } catch (ImsException e) {
3261 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003262 } finally {
3263 Binder.restoreCallingIdentity(identity);
3264 }
3265 }
3266
3267 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003268 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003270 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003271 final long identity = Binder.clearCallingIdentity();
3272 try {
3273 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003274 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003275 } catch (ImsException e) {
3276 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003277 } finally {
3278 Binder.restoreCallingIdentity(identity);
3279 }
3280 }
3281
3282 @Override
3283 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3284 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3285 final long identity = Binder.clearCallingIdentity();
3286 try {
3287 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003288 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003289 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003290 } catch (ImsException e) {
3291 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003292 } finally {
3293 Binder.restoreCallingIdentity(identity);
3294 }
3295 }
3296
3297 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003298 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003300 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003301 final long identity = Binder.clearCallingIdentity();
3302 try {
3303 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003304 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003305 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003306 } catch (ImsException e) {
3307 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003308 } finally {
3309 Binder.restoreCallingIdentity(identity);
3310 }
3311 }
3312
3313 @Override
3314 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3316 "setVoWiFiNonPersistent");
3317 final long identity = Binder.clearCallingIdentity();
3318 try {
3319 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003320 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003321 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003322 } catch (ImsException e) {
3323 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003324 } finally {
3325 Binder.restoreCallingIdentity(identity);
3326 }
3327 }
3328
3329 @Override
3330 public int getVoWiFiModeSetting(int subId) {
3331 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3332 final long identity = Binder.clearCallingIdentity();
3333 try {
3334 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003335 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003336 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003337 } catch (ImsException e) {
3338 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003339 } finally {
3340 Binder.restoreCallingIdentity(identity);
3341 }
3342 }
3343
3344 @Override
3345 public void setVoWiFiModeSetting(int subId, int mode) {
3346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3347 "setVoWiFiModeSetting");
3348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003351 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003352 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003353 } catch (ImsException e) {
3354 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003355 } finally {
3356 Binder.restoreCallingIdentity(identity);
3357 }
3358 }
3359
3360 @Override
3361 public int getVoWiFiRoamingModeSetting(int subId) {
3362 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3363 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 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003367 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003368 } catch (ImsException e) {
3369 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003370 } finally {
3371 Binder.restoreCallingIdentity(identity);
3372 }
3373 }
3374
3375 @Override
3376 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3378 "setVoWiFiRoamingModeSetting");
3379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003382 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003384 } catch (ImsException e) {
3385 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003386 } finally {
3387 Binder.restoreCallingIdentity(identity);
3388 }
3389 }
3390
3391 @Override
3392 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3394 "setRttCapabilityEnabled");
3395 final long identity = Binder.clearCallingIdentity();
3396 try {
3397 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003398 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3399 } catch (ImsException e) {
3400 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003401 } finally {
3402 Binder.restoreCallingIdentity(identity);
3403 }
3404 }
3405
3406 @Override
3407 public boolean isTtyOverVolteEnabled(int subId) {
3408 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003412 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003413 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003414 } catch (ImsException e) {
3415 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003416 } finally {
3417 Binder.restoreCallingIdentity(identity);
3418 }
3419 }
3420
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003421 @Override
3422 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3423 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3424 final long identity = Binder.clearCallingIdentity();
3425 try {
3426 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003427 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003428 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003429 } catch (ImsException e) {
3430 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003431 } finally {
3432 Binder.restoreCallingIdentity(identity);
3433 }
3434 }
3435
3436 @Override
3437 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3438 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3439 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003440 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3441 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3442 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003443 try {
3444 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003445 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003446 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003447 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003448 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3449 + "is inactive, ignoring unregister.");
3450 // If the subscription is no longer active, just return, since the callback will already
3451 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003452 } finally {
3453 Binder.restoreCallingIdentity(identity);
3454 }
3455 }
3456
3457 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003458 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3459 boolean isProvisioned) {
3460 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3461 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3462 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3463 }
3464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3465 "setProvisioningStatusForCapability");
3466 final long identity = Binder.clearCallingIdentity();
3467 try {
3468 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3469 Phone phone = getPhone(subId);
3470 if (phone == null) {
3471 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3472 + subId);
3473 return;
3474 }
3475 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3476 return;
3477 }
3478
3479 // this capability requires provisioning, route to the correct API.
3480 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3481 switch (capability) {
3482 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3483 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3484 ims.setVolteProvisioned(isProvisioned);
3485 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3486 ims.setWfcProvisioned(isProvisioned);
3487 }
3488 break;
3489 }
3490 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3491 // There is currently no difference in VT provisioning type.
3492 ims.setVtProvisioned(isProvisioned);
3493 break;
3494 }
3495 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3496 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3497 // change the capability of the feature instead if needed.
3498 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3499 == isProvisioned) {
3500 // No change in provisioning.
3501 return;
3502 }
3503 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3504 try {
3505 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003506 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003507 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3508 + ", Exception" + e.getMessage());
3509 }
3510 break;
3511 }
3512 default: {
3513 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3514 + capability + "', which does not require provisioning.");
3515 }
3516 }
3517
3518 } finally {
3519 Binder.restoreCallingIdentity(identity);
3520 }
3521 }
3522
3523 @Override
3524 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3525 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3526 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3527 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3528 }
3529 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3533 Phone phone = getPhone(subId);
3534 if (phone == null) {
3535 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3536 + subId);
3537 // We will fail with "true" as the provisioning status because this is the default
3538 // if we do not require provisioning.
3539 return true;
3540 }
3541
3542 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3543 return true;
3544 }
3545
3546 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3547 switch (capability) {
3548 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3549 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3550 return ims.isVolteProvisionedOnDevice();
3551 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3552 return ims.isWfcProvisionedOnDevice();
3553 }
3554 // This should never happen, since we are checking tech above to make sure it
3555 // is either LTE or IWLAN.
3556 throw new IllegalArgumentException("Invalid radio technology for voice "
3557 + "capability.");
3558 }
3559 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3560 // There is currently no difference in VT provisioning type.
3561 return ims.isVtProvisionedOnDevice();
3562 }
3563 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3564 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3565 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3566 }
3567 default: {
3568 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3569 + capability + "', which does not require provisioning.");
3570 }
3571 }
3572
3573 } finally {
3574 Binder.restoreCallingIdentity(identity);
3575 }
3576 }
3577
3578 @Override
3579 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3580 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3581 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3582 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3583 }
3584 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3585 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3586 return (provisionedBits & capability) > 0;
3587 }
3588
3589 @Override
3590 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3591 boolean isProvisioned) {
3592 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3593 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3594 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3595 }
3596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3597 "setProvisioningStatusForCapability");
3598 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3599 // If the current provisioning status for capability already matches isProvisioned,
3600 // do nothing.
3601 if (((provisionedBits & capability) > 0) == isProvisioned) {
3602 return;
3603 }
3604 if (isProvisioned) {
3605 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3606 } else {
3607 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3608 }
3609 }
3610
3611 /**
3612 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3613 * technology. The bitfield should mirror the bitfield defined by
3614 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3615 */
3616 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3617 String key = getMmTelProvisioningKey(subId, tech);
3618 // Default is no capabilities are provisioned.
3619 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3620 }
3621
3622 /**
3623 * Sets the MmTel capability provisioning bitfield (defined by
3624 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3625 * technology specified.
3626 *
3627 * Note: This is a synchronous command and should not be called on UI thread.
3628 */
3629 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3630 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3631 String key = getMmTelProvisioningKey(subId, tech);
3632 editor.putInt(key, newField);
3633 editor.commit();
3634 }
3635
3636 private static String getMmTelProvisioningKey(int subId, int tech) {
3637 // resulting key is provision_ims_mmtel_{subId}_{tech}
3638 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3639 }
3640
3641 /**
3642 * Query CarrierConfig to see if the specified capability requires provisioning for the
3643 * carrier associated with the subscription id.
3644 */
3645 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3646 int capability) {
3647 CarrierConfigManager configManager = new CarrierConfigManager(context);
3648 PersistableBundle c = configManager.getConfigForSubId(subId);
3649 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003650 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003651 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3652 false);
3653 boolean requireVoiceVtProvisioning = c.getBoolean(
3654 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3655
3656 // First check to make sure that the capability requires provisioning.
3657 switch (capability) {
3658 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3659 // intentional fallthrough
3660 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3661 if (requireVoiceVtProvisioning) {
3662 // Voice and Video requires provisioning
3663 return true;
3664 }
3665 break;
3666 }
3667 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3668 if (requireUtProvisioning) {
3669 // UT requires provisioning
3670 return true;
3671 }
3672 break;
3673 }
3674 }
3675 return false;
3676 }
3677
3678 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003679 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003680 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3681 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3682 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003683 enforceReadPrivilegedPermission("getImsProvisioningInt");
3684 final long identity = Binder.clearCallingIdentity();
3685 try {
3686 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003687 int slotId = getSlotIndex(subId);
3688 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3689 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3690 + subId + "' for key:" + key);
3691 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3692 }
3693 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003694 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003695 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3696 + subId + "' for key:" + key);
3697 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003698 } finally {
3699 Binder.restoreCallingIdentity(identity);
3700 }
3701 }
3702
3703 @Override
3704 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003705 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3706 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3707 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003708 enforceReadPrivilegedPermission("getImsProvisioningString");
3709 final long identity = Binder.clearCallingIdentity();
3710 try {
3711 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003712 int slotId = getSlotIndex(subId);
3713 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3714 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3715 + subId + "' for key:" + key);
3716 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3717 }
3718 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003719 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003720 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3721 + subId + "' for key:" + key);
3722 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003723 } finally {
3724 Binder.restoreCallingIdentity(identity);
3725 }
3726 }
3727
3728 @Override
3729 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003730 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3731 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3732 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3734 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003738 int slotId = getSlotIndex(subId);
3739 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3740 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3741 + subId + "' for key:" + key);
3742 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3743 }
3744 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003745 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003746 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3747 + "' for key:" + key);
3748 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003749 } finally {
3750 Binder.restoreCallingIdentity(identity);
3751 }
3752 }
3753
3754 @Override
3755 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003756 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3757 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3758 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3760 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003761 final long identity = Binder.clearCallingIdentity();
3762 try {
3763 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003764 int slotId = getSlotIndex(subId);
3765 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3766 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3767 + subId + "' for key:" + key);
3768 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3769 }
3770 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003771 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003772 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3773 + "' for key:" + key);
3774 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003775 } finally {
3776 Binder.restoreCallingIdentity(identity);
3777 }
3778 }
3779
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003780 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003781 int slotId = SubscriptionManager.getSlotIndex(subId);
3782 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003783 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3784 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003785 }
3786 return slotId;
3787 }
3788
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003789 private int getSlotIndex(int subId) {
3790 int slotId = SubscriptionManager.getSlotIndex(subId);
3791 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3792 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3793 }
3794 return slotId;
3795 }
3796
Wink Saville36469e72014-06-11 15:17:00 -07003797 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003798 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003799 */
3800 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003801 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3802 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003803 final int targetSdk = getTargetSdk(callingPackage);
3804 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003805 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003806 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003807 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003808 mApp, subId, callingPackage, callingFeatureId,
3809 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003810 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3811 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 final Phone phone = getPhone(subId);
3816 if (phone != null) {
3817 return phone.getServiceState().getDataNetworkType();
3818 } else {
3819 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3820 }
3821 } finally {
3822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003824 }
3825
3826 /**
3827 * Returns the data network type
3828 */
3829 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003830 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3831 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3832 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003833 }
3834
3835 /**
3836 * Returns the data network type for a subId
3837 */
3838 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003839 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3840 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003841 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003842 mApp, subId, callingPackage, callingFeatureId,
3843 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003844 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3845 }
3846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003847 final long identity = Binder.clearCallingIdentity();
3848 try {
3849 final Phone phone = getPhone(subId);
3850 if (phone != null) {
3851 return phone.getServiceState().getDataNetworkType();
3852 } else {
3853 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3854 }
3855 } finally {
3856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003858 }
3859
3860 /**
Wink Saville36469e72014-06-11 15:17:00 -07003861 * Returns the Voice network type for a subId
3862 */
3863 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003864 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3865 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003866 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003867 mApp, subId, callingPackage, callingFeatureId,
3868 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003869 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3870 }
3871
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 final Phone phone = getPhone(subId);
3875 if (phone != null) {
3876 return phone.getServiceState().getVoiceNetworkType();
3877 } else {
3878 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3879 }
3880 } finally {
3881 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003883 }
3884
3885 /**
3886 * @return true if a ICC card is present
3887 */
3888 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003889 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003890 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3891 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003892 }
3893
3894 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003895 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003896 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003897 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003898 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003899 final long identity = Binder.clearCallingIdentity();
3900 try {
3901 final Phone phone = PhoneFactory.getPhone(slotIndex);
3902 if (phone != null) {
3903 return phone.getIccCard().hasIccCard();
3904 } else {
3905 return false;
3906 }
3907 } finally {
3908 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003910 }
3911
3912 /**
3913 * Return if the current radio is LTE on CDMA. This
3914 * is a tri-state return value as for a period of time
3915 * the mode may be unknown.
3916 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003917 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003918 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003919 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003920 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003921 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003922 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3923 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3924 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003925 }
3926
Sanket Padawe356d7632015-06-22 14:03:32 -07003927 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003928 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3929 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003931 mApp, subId, callingPackage, callingFeatureId,
3932 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003933 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3934 }
3935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003936 final long identity = Binder.clearCallingIdentity();
3937 try {
3938 final Phone phone = getPhone(subId);
3939 if (phone == null) {
3940 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3941 } else {
3942 return phone.getLteOnCdmaMode();
3943 }
3944 } finally {
3945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003946 }
Wink Saville36469e72014-06-11 15:17:00 -07003947 }
3948
Wink Saville36469e72014-06-11 15:17:00 -07003949 /**
3950 * {@hide}
3951 * Returns Default subId, 0 in the case of single standby.
3952 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003953 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003954 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003955 }
3956
Shishir Agrawala9f32182016-04-12 12:00:16 -07003957 private int getSlotForDefaultSubscription() {
3958 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3959 }
3960
Wink Savilleb564aae2014-10-23 10:18:09 -07003961 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003962 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003963 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003964
Pengquan Menge92a50d2018-09-21 15:54:48 -07003965 private boolean isActiveSubscription(int subId) {
3966 return mSubscriptionController.isActiveSubId(subId);
3967 }
3968
Ihab Awadf2177b72013-11-25 13:33:23 -08003969 /**
3970 * @see android.telephony.TelephonyManager.WifiCallingChoices
3971 */
3972 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973 final long identity = Binder.clearCallingIdentity();
3974 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003975 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003976 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3977 getWhenToMakeWifiCallsDefaultPreference());
3978 } finally {
3979 Binder.restoreCallingIdentity(identity);
3980 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003981 }
3982
3983 /**
3984 * @see android.telephony.TelephonyManager.WifiCallingChoices
3985 */
3986 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987 final long identity = Binder.clearCallingIdentity();
3988 try {
3989 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003990 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003991 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3992 } finally {
3993 Binder.restoreCallingIdentity(identity);
3994 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003995 }
3996
Sailesh Nepald1e68152013-12-12 19:08:02 -08003997 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003998 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003999 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004000 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004001
Jordan Liu4c733742019-02-28 12:03:40 -08004002 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4003 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4004 if (phoneId == -1) {
4005 throw new IllegalArgumentException("Given slot index: " + slotIndex
4006 + " does not correspond to an active phone");
4007 }
4008 return PhoneFactory.getPhone(phoneId);
4009 }
4010
Shishir Agrawal566b7612013-10-28 14:41:00 -07004011 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004012 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4013 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4015 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004017 if (DBG) {
4018 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4019 }
4020 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4021 p2);
4022 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004023
Jordan Liu4c733742019-02-28 12:03:40 -08004024
4025 @Override
4026 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4027 int slotIndex, String callingPackage, String aid, int p2) {
4028 enforceModifyPermission();
4029 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4030 if (DBG) {
4031 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4032 }
4033 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4034 callingPackage, aid, p2);
4035 }
4036
4037 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4038 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004039 final long identity = Binder.clearCallingIdentity();
4040 try {
4041 if (TextUtils.equals(ISDR_AID, aid)) {
4042 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004043 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4044 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045 if (bestComponent == null
4046 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4047 loge("The calling package is not allowed to access ISD-R.");
4048 throw new SecurityException(
4049 "The calling package is not allowed to access ISD-R.");
4050 }
Derek Tan740e1672017-06-27 14:56:27 -07004051 }
Derek Tan740e1672017-06-27 14:56:27 -07004052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004054 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4055 null /* workSource */);
4056 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004057 return response;
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004061 }
4062
4063 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004064 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4066 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004067 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4068 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4069 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004070
Jordan Liu4c733742019-02-28 12:03:40 -08004071 @Override
4072 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4073 enforceModifyPermission();
4074 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4075 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4076 channel);
4077 }
4078
4079 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004080 final long identity = Binder.clearCallingIdentity();
4081 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082 if (channel < 0) {
4083 return false;
4084 }
Jordan Liu4c733742019-02-28 12:03:40 -08004085 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4086 null /* workSource */);
4087 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004088 return success;
4089 } finally {
4090 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004091 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004092 }
4093
4094 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004095 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004096 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4098 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004099 if (DBG) {
4100 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4101 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4102 + p3 + " data=" + data);
4103 }
4104 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4105 command, p1, p2, p3, data);
4106 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004107
Jordan Liu4c733742019-02-28 12:03:40 -08004108 @Override
4109 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4110 int command, int p1, int p2, int p3, String data) {
4111 enforceModifyPermission();
4112 if (DBG) {
4113 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4114 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4115 + p3 + " data=" + data);
4116 }
4117 return iccTransmitApduLogicalChannelWithPermission(
4118 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4119 data);
4120 }
4121
4122 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4123 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 final long identity = Binder.clearCallingIdentity();
4125 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004126 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127 return "";
4128 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004130 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004131 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4132 null /* workSource */);
4133 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004135 // Append the returned status code to the end of the response payload.
4136 String s = Integer.toHexString(
4137 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4138 if (response.payload != null) {
4139 s = IccUtils.bytesToHexString(response.payload) + s;
4140 }
4141 return s;
4142 } finally {
4143 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004144 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004145 }
Jake Hambye994d462014-02-03 13:10:13 -08004146
Evan Charltonc66da362014-05-16 14:06:40 -07004147 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004148 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4149 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4151 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004153 if (DBG) {
4154 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4155 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4156 }
4157 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4158 cla, command, p1, p2, p3, data);
4159 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004160
Jordan Liu4c733742019-02-28 12:03:40 -08004161 @Override
4162 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4163 int command, int p1, int p2, int p3, String data) {
4164 enforceModifyPermission();
4165 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4166 if (DBG) {
4167 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4168 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4169 + " data=" + data);
4170 }
4171
4172 return iccTransmitApduBasicChannelWithPermission(
4173 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4174 p2, p3, data);
4175 }
4176
4177 // open APDU basic channel assuming the caller has sufficient permissions
4178 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4179 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180 final long identity = Binder.clearCallingIdentity();
4181 try {
4182 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4183 && TextUtils.equals(ISDR_AID, data)) {
4184 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004185 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4186 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004187 if (bestComponent == null
4188 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4189 loge("The calling package is not allowed to select ISD-R.");
4190 throw new SecurityException(
4191 "The calling package is not allowed to select ISD-R.");
4192 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004193 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004196 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4197 null /* workSource */);
4198 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004200 // Append the returned status code to the end of the response payload.
4201 String s = Integer.toHexString(
4202 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4203 if (response.payload != null) {
4204 s = IccUtils.bytesToHexString(response.payload) + s;
4205 }
4206 return s;
4207 } finally {
4208 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004209 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004210 }
4211
4212 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004213 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004214 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4216 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004218 final long identity = Binder.clearCallingIdentity();
4219 try {
4220 if (DBG) {
4221 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4222 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4223 }
4224
4225 IccIoResult response =
4226 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4227 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4228 subId);
4229
4230 if (DBG) {
4231 log("Exchange SIM_IO [R]" + response);
4232 }
4233
4234 byte[] result = null;
4235 int length = 2;
4236 if (response.payload != null) {
4237 length = 2 + response.payload.length;
4238 result = new byte[length];
4239 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4240 } else {
4241 result = new byte[length];
4242 }
4243
4244 result[length - 1] = (byte) response.sw2;
4245 result[length - 2] = (byte) response.sw1;
4246 return result;
4247 } finally {
4248 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004249 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004250 }
4251
Nathan Haroldb3014052017-01-25 15:57:32 -08004252 /**
4253 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4254 * on a particular subscription
4255 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004256 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4257 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004258 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004259 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004260 return null;
4261 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004262
4263 final long identity = Binder.clearCallingIdentity();
4264 try {
4265 if (appType != TelephonyManager.APPTYPE_USIM
4266 && appType != TelephonyManager.APPTYPE_SIM) {
4267 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4268 return null;
4269 }
4270 Object response = sendRequest(
4271 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4272 if (response instanceof String[]) {
4273 return (String[]) response;
4274 }
yincheng zhao2737e882019-09-06 17:06:54 -07004275 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004277 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278 } finally {
4279 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004280 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004281 }
4282
yincheng zhao2737e882019-09-06 17:06:54 -07004283 /**
4284 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4285 * subscription.
4286 *
4287 * @param subId the id of the subscription.
4288 * @param appType the uicc app type, must be USIM or SIM.
4289 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4290 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004291 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004292 * @return number of fplmns that is successfully written to the SIM.
4293 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004294 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4295 String callingFeatureId) {
4296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4297 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004298 if (DBG) logv("no permissions for setForbiddenplmns");
4299 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4300 }
4301 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4302 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4303 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4304 }
4305 if (fplmns == null) {
4306 throw new IllegalArgumentException("Fplmn List provided is null");
4307 }
4308 for (String fplmn : fplmns) {
4309 if (!CellIdentity.isValidPlmn(fplmn)) {
4310 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4311 }
4312 }
4313 final long identity = Binder.clearCallingIdentity();
4314 try {
4315 Object response = sendRequest(
4316 CMD_SET_FORBIDDEN_PLMNS,
4317 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4318 subId);
4319 return (int) response;
4320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
4323 }
4324
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004325 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004326 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4328 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330 final long identity = Binder.clearCallingIdentity();
4331 try {
4332 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4333 if (response.payload == null) {
4334 return "";
4335 }
Evan Charltonc66da362014-05-16 14:06:40 -07004336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004337 // Append the returned status code to the end of the response payload.
4338 String s = Integer.toHexString(
4339 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4340 s = IccUtils.bytesToHexString(response.payload) + s;
4341 return s;
4342 } finally {
4343 Binder.restoreCallingIdentity(identity);
4344 }
Evan Charltonc66da362014-05-16 14:06:40 -07004345 }
4346
Jake Hambye994d462014-02-03 13:10:13 -08004347 /**
4348 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4349 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4350 *
4351 * @param itemID the ID of the item to read
4352 * @return the NV item as a String, or null on error.
4353 */
4354 @Override
4355 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004356 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4358 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004359
4360 final long identity = Binder.clearCallingIdentity();
4361 try {
4362 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004363 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004364 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4365 return value;
4366 } finally {
4367 Binder.restoreCallingIdentity(identity);
4368 }
Jake Hambye994d462014-02-03 13:10:13 -08004369 }
4370
4371 /**
4372 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4373 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4374 *
4375 * @param itemID the ID of the item to read
4376 * @param itemValue the value to write, as a String
4377 * @return true on success; false on any failure
4378 */
4379 @Override
4380 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004381 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4383 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004384
4385 final long identity = Binder.clearCallingIdentity();
4386 try {
4387 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4388 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004389 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004390 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4391 return success;
4392 } finally {
4393 Binder.restoreCallingIdentity(identity);
4394 }
Jake Hambye994d462014-02-03 13:10:13 -08004395 }
4396
4397 /**
4398 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4399 * Used for device configuration by some CDMA operators.
4400 *
4401 * @param preferredRoamingList byte array containing the new PRL
4402 * @return true on success; false on any failure
4403 */
4404 @Override
4405 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4407 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004408
4409 final long identity = Binder.clearCallingIdentity();
4410 try {
4411 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4412 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4413 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4414 return success;
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
4417 }
Jake Hambye994d462014-02-03 13:10:13 -08004418 }
4419
4420 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004421 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004422 * Used for device configuration by some CDMA operators.
4423 *
chen xu6dac5ab2018-10-26 17:39:23 -07004424 * @param slotIndex - device slot.
4425 *
Jake Hambye994d462014-02-03 13:10:13 -08004426 * @return true on success; false on any failure
4427 */
4428 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004429 public boolean resetModemConfig(int slotIndex) {
4430 Phone phone = PhoneFactory.getPhone(slotIndex);
4431 if (phone != null) {
4432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4433 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004434
chen xu6dac5ab2018-10-26 17:39:23 -07004435 final long identity = Binder.clearCallingIdentity();
4436 try {
4437 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4438 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4439 return success;
4440 } finally {
4441 Binder.restoreCallingIdentity(identity);
4442 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 }
chen xu6dac5ab2018-10-26 17:39:23 -07004444 return false;
4445 }
4446
4447 /**
4448 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4449 *
4450 * @param slotIndex - device slot.
4451 *
4452 * @return true on success; false on any failure
4453 */
4454 @Override
4455 public boolean rebootModem(int slotIndex) {
4456 Phone phone = PhoneFactory.getPhone(slotIndex);
4457 if (phone != null) {
4458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4459 mApp, phone.getSubId(), "rebootModem");
4460
4461 final long identity = Binder.clearCallingIdentity();
4462 try {
4463 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4464 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4465 return success;
4466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
4469 }
4470 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004471 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004472
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004473 public String[] getPcscfAddress(String apnType, String callingPackage,
4474 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004475 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4477 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004478 return new String[0];
4479 }
4480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 final long identity = Binder.clearCallingIdentity();
4482 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004483 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004484 } finally {
4485 Binder.restoreCallingIdentity(identity);
4486 }
Wink Saville36469e72014-06-11 15:17:00 -07004487 }
4488
Brad Ebinger51f743a2017-01-23 13:50:20 -08004489 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004490 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4491 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004492 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004493 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004494 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495
4496 final long identity = Binder.clearCallingIdentity();
4497 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004498 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004499 // may happen if the device does not support IMS.
4500 return;
4501 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004502 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004506 }
4507
4508 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004509 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4510 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004511 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004512 public void disableIms(int slotId) {
4513 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514
4515 final long identity = Binder.clearCallingIdentity();
4516 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004517 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004518 // may happen if the device does not support IMS.
4519 return;
4520 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004521 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004522 } finally {
4523 Binder.restoreCallingIdentity(identity);
4524 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004525 }
4526
4527 /**
4528 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4529 * feature or {@link null} if the service is not available. If the feature is available, the
4530 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4531 */
4532 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004533 IImsServiceFeatureCallback callback) {
4534 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004535
4536 final long identity = Binder.clearCallingIdentity();
4537 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004538 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004539 // may happen if the device does not support IMS.
4540 return null;
4541 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004542 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004543 } finally {
4544 Binder.restoreCallingIdentity(identity);
4545 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004546 }
4547
4548 /**
4549 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4550 * feature during emergency calling or {@link null} if the service is not available. If the
4551 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4552 * listener for feature updates.
4553 */
4554 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556
4557 final long identity = Binder.clearCallingIdentity();
4558 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004559 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004560 // may happen if the device does not support IMS.
4561 return null;
4562 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004563 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004564 } finally {
4565 Binder.restoreCallingIdentity(identity);
4566 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004567 }
4568
Brad Ebinger5f64b052017-12-14 14:26:15 -08004569 /**
4570 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004571 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004572 */
4573 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4574 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575
4576 final long identity = Binder.clearCallingIdentity();
4577 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004578 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004579 // may happen if the device does not support IMS.
4580 return null;
4581 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004582 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004583 } finally {
4584 Binder.restoreCallingIdentity(identity);
4585 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004586 }
4587
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004588 /**
4589 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004590 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004591 */
4592 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4593 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004594
4595 final long identity = Binder.clearCallingIdentity();
4596 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004597 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004598 // may happen if the device does not support IMS.
4599 return null;
4600 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004601 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004602 } finally {
4603 Binder.restoreCallingIdentity(identity);
4604 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004605 }
4606
Brad Ebinger884c07b2018-02-15 16:17:40 -08004607 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004608 * Sets the ImsService Package Name that Telephony will bind to.
4609 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004610 * @param slotIndex the slot ID that the ImsService should bind for.
4611 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004612 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004613 * @param featureTypes An integer array of feature types associated with a packageName.
4614 * @param packageName The name of the package that the current configuration will be replaced
4615 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004616 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004617 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004618 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4619 int[] featureTypes, String packageName) {
4620 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4621 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4623 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004624 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004625
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004626 final long identity = Binder.clearCallingIdentity();
4627 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004628 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004629 // may happen if the device does not support IMS.
4630 return false;
4631 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004632 Map<Integer, String> featureConfig = new HashMap<>();
4633 for (int featureType : featureTypes) {
4634 featureConfig.put(featureType, packageName);
4635 }
4636 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4637 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004638 } finally {
4639 Binder.restoreCallingIdentity(identity);
4640 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004641 }
4642
4643 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004644 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004645 *
4646 * @param slotId The slot that the ImsService is associated with.
4647 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4648 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004649 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004650 * @return the package name of the ImsService configuration.
4651 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004652 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4653 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004654 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004655 TelephonyPermissions
4656 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4657 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4658 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004660 final long identity = Binder.clearCallingIdentity();
4661 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004662 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004663 // may happen if the device does not support IMS.
4664 return "";
4665 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004666 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004667 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4668 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004669 } finally {
4670 Binder.restoreCallingIdentity(identity);
4671 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004672 }
4673
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004674 /**
4675 * Get the MmTelFeature state associated with the requested subscription id.
4676 * @param subId The subscription that the MmTelFeature is associated with.
4677 * @param callback A callback with an integer containing the
4678 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4679 */
4680 @Override
4681 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4682 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4683 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4684 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4685 "IMS not available on device.");
4686 }
4687 final long token = Binder.clearCallingIdentity();
4688 try {
4689 int slotId = getSlotIndex(subId);
4690 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4691 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4692 + subId + "'");
4693 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4694 }
4695 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4696 try {
4697 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4698 } catch (RemoteException e) {
4699 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4700 + "Ignore");
4701 }
4702 });
4703 } finally {
4704 Binder.restoreCallingIdentity(token);
4705 }
4706 }
4707
Wink Saville36469e72014-06-11 15:17:00 -07004708 public void setImsRegistrationState(boolean registered) {
4709 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004710
4711 final long identity = Binder.clearCallingIdentity();
4712 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004713 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004714 } finally {
4715 Binder.restoreCallingIdentity(identity);
4716 }
Wink Saville36469e72014-06-11 15:17:00 -07004717 }
4718
4719 /**
Stuart Scott54788802015-03-30 13:18:01 -07004720 * Set the network selection mode to automatic.
4721 *
4722 */
4723 @Override
4724 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4726 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727
Pengquan Menge92a50d2018-09-21 15:54:48 -07004728 if (!isActiveSubscription(subId)) {
4729 return;
4730 }
4731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004732 final long identity = Binder.clearCallingIdentity();
4733 try {
4734 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4735 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
4738 }
Stuart Scott54788802015-03-30 13:18:01 -07004739 }
4740
Pengquan Mengea84e042018-09-20 14:57:26 -07004741 /**
4742 * Ask the radio to connect to the input network and change selection mode to manual.
4743 *
4744 * @param subId the id of the subscription.
4745 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4746 * the operator to attach to.
4747 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4748 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4749 * normal network selection next time.
4750 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004751 */
4752 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004753 public boolean setNetworkSelectionModeManual(
4754 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4756 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004757
4758 if (!isActiveSubscription(subId)) {
4759 return false;
4760 }
4761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 final long identity = Binder.clearCallingIdentity();
4763 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004764 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004766 if (DBG) {
4767 log("setNetworkSelectionModeManual: subId: " + subId
4768 + " operator: " + operatorInfo);
4769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004770 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
4773 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004774 }
4775
4776 /**
4777 * Scans for available networks.
4778 */
4779 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004780 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4781 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4783 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004784 LocationAccessPolicy.LocationPermissionResult locationResult =
4785 LocationAccessPolicy.checkLocationPermission(mApp,
4786 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4787 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004788 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004789 .setCallingPid(Binder.getCallingPid())
4790 .setCallingUid(Binder.getCallingUid())
4791 .setMethod("getCellNetworkScanResults")
4792 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4793 .build());
4794 switch (locationResult) {
4795 case DENIED_HARD:
4796 throw new SecurityException("Not allowed to access scan results -- location");
4797 case DENIED_SOFT:
4798 return null;
4799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004800
Pengquan Menga1bb6272018-09-06 09:59:22 -07004801 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004802 try {
4803 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004804 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004805 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004806 } finally {
4807 Binder.restoreCallingIdentity(identity);
4808 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004809 }
4810
4811 /**
yinxub1bed742017-04-17 11:45:04 -07004812 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004813 *
yinxub1bed742017-04-17 11:45:04 -07004814 * @param subId id of the subscription
4815 * @param request contains the radio access networks with bands/channels to scan
4816 * @param messenger callback messenger for scan results or errors
4817 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004818 * @return the id of the requested scan which can be used to stop the scan.
4819 */
4820 @Override
4821 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004822 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4824 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004825 LocationAccessPolicy.LocationPermissionResult locationResult =
4826 LocationAccessPolicy.checkLocationPermission(mApp,
4827 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4828 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004829 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004830 .setCallingPid(Binder.getCallingPid())
4831 .setCallingUid(Binder.getCallingUid())
4832 .setMethod("requestNetworkScan")
4833 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4834 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004835 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004836 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004837 if (e != null) {
4838 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4839 throw e;
4840 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004841 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004842 return TelephonyScanManager.INVALID_SCAN_ID;
4843 }
4844 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004845 }
Hall Liu912dfd32019-04-25 14:02:26 -07004846 int callingUid = Binder.getCallingUid();
4847 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004848 final long identity = Binder.clearCallingIdentity();
4849 try {
4850 return mNetworkScanRequestTracker.startNetworkScan(
4851 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004852 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004853 } finally {
4854 Binder.restoreCallingIdentity(identity);
4855 }
yinxu504e1392017-04-12 16:03:22 -07004856 }
4857
Hall Liub2ac8ef2019-02-28 15:56:23 -08004858 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004859 NetworkScanRequest request, int subId) {
4860 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4861 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4862 boolean hasNetworkScanPermission =
4863 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4864 == PERMISSION_GRANTED;
4865
4866 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4867 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4868 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004869 }
4870
4871 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4872 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004873 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4874 return new SecurityException("Specific channels must not be"
4875 + " scanned without location access.");
4876 }
4877 }
4878 }
4879
Hall Liub2ac8ef2019-02-28 15:56:23 -08004880 return null;
4881 }
4882
yinxu504e1392017-04-12 16:03:22 -07004883 /**
4884 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004885 *
4886 * @param subId id of the subscription
4887 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004888 */
4889 @Override
4890 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4892 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004893
Hall Liu912dfd32019-04-25 14:02:26 -07004894 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895 final long identity = Binder.clearCallingIdentity();
4896 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004897 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004898 } finally {
4899 Binder.restoreCallingIdentity(identity);
4900 }
yinxu504e1392017-04-12 16:03:22 -07004901 }
4902
4903 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004904 * Get the calculated preferred network type.
4905 * Used for debugging incorrect network type.
4906 *
4907 * @return the preferred network type, defined in RILConstants.java.
4908 */
4909 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004910 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004911 final Phone defaultPhone = getDefaultPhone();
4912 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004913 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004914 return RILConstants.PREFERRED_NETWORK_MODE;
4915 }
4916
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917 final long identity = Binder.clearCallingIdentity();
4918 try {
4919 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004920 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921 } finally {
4922 Binder.restoreCallingIdentity(identity);
4923 }
Junda Liu84d15a22014-07-02 11:21:04 -07004924 }
4925
4926 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004927 * Get the preferred network type.
4928 * Used for device configuration by some CDMA operators.
4929 *
4930 * @return the preferred network type, defined in RILConstants.java.
4931 */
4932 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004933 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004934 TelephonyPermissions
4935 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4936 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004937
4938 final long identity = Binder.clearCallingIdentity();
4939 try {
4940 if (DBG) log("getPreferredNetworkType");
4941 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4942 int networkType = (result != null ? result[0] : -1);
4943 if (DBG) log("getPreferredNetworkType: " + networkType);
4944 return networkType;
4945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004948 }
4949
4950 /**
4951 * Set the preferred network type.
4952 * Used for device configuration by some CDMA operators.
4953 *
4954 * @param networkType the preferred network type, defined in RILConstants.java.
4955 * @return true on success; false on any failure.
4956 */
4957 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004958 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4960 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004961
4962 final long identity = Binder.clearCallingIdentity();
4963 try {
4964 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4965 Boolean success = (Boolean) sendRequest(
4966 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4967 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4968 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004969 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4971 }
4972 return success;
4973 } finally {
4974 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004975 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004976 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004977
4978 /**
Miaoa84611c2019-03-15 09:21:10 +08004979 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004980 *
Miaoa84611c2019-03-15 09:21:10 +08004981 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004982 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004983 * @hide
4984 */
4985 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004986 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004987 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004989 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004990 try {
Miaoa84611c2019-03-15 09:21:10 +08004991 if (phone != null) {
4992 return phone.hasMatchedTetherApnSetting();
4993 } else {
4994 return false;
4995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996 } finally {
4997 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004998 }
Junda Liu475951f2014-11-07 16:45:03 -08004999 }
5000
5001 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005002 * Set mobile data enabled
5003 * Used by the user through settings etc to turn on/off mobile data
5004 *
5005 * @param enable {@code true} turn turn data on, else {@code false}
5006 */
5007 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005008 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5010 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011
5012 final long identity = Binder.clearCallingIdentity();
5013 try {
5014 int phoneId = mSubscriptionController.getPhoneId(subId);
5015 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5016 Phone phone = PhoneFactory.getPhone(phoneId);
5017 if (phone != null) {
5018 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005019 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005021 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022 }
5023 } finally {
5024 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005025 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005026 }
5027
5028 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005029 * Get the user enabled state of Mobile Data.
5030 *
5031 * TODO: remove and use isUserDataEnabled.
5032 * This can't be removed now because some vendor codes
5033 * calls through ITelephony directly while they should
5034 * use TelephonyManager.
5035 *
5036 * @return true on enabled
5037 */
5038 @Override
5039 public boolean getDataEnabled(int subId) {
5040 return isUserDataEnabled(subId);
5041 }
5042
5043 /**
5044 * Get whether mobile data is enabled per user setting.
5045 *
5046 * There are other factors deciding whether mobile data is actually enabled, but they are
5047 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005048 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005049 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005050 *
5051 * @return {@code true} if data is enabled else {@code false}
5052 */
5053 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005054 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005055 try {
5056 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5057 null);
5058 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5060 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005062
5063 final long identity = Binder.clearCallingIdentity();
5064 try {
5065 int phoneId = mSubscriptionController.getPhoneId(subId);
5066 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5067 Phone phone = PhoneFactory.getPhone(phoneId);
5068 if (phone != null) {
5069 boolean retVal = phone.isUserDataEnabled();
5070 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5071 return retVal;
5072 } else {
5073 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5074 return false;
5075 }
5076 } finally {
5077 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005078 }
5079 }
5080
5081 /**
5082 * Get whether mobile data is enabled.
5083 *
5084 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5085 * whether mobile data is actually enabled.
5086 *
5087 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5088 *
5089 * @return {@code true} if data is enabled else {@code false}
5090 */
5091 @Override
5092 public boolean isDataEnabled(int subId) {
5093 try {
5094 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5095 null);
5096 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5098 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005099 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005100
5101 final long identity = Binder.clearCallingIdentity();
5102 try {
5103 int phoneId = mSubscriptionController.getPhoneId(subId);
5104 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5105 Phone phone = PhoneFactory.getPhone(phoneId);
5106 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005107 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005108 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5109 return retVal;
5110 } else {
5111 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5112 return false;
5113 }
5114 } finally {
5115 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005116 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005117 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005118
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005119 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5120 Phone phone) {
5121 //load access rules from carrier configs, and check those as well: b/139133814
5122 SubscriptionController subController = SubscriptionController.getInstance();
5123 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5124 || subController == null) return privilegeFromSim;
5125
5126 int uid = Binder.getCallingUid();
5127 PackageManager pkgMgr = phone.getContext().getPackageManager();
5128 String[] packages = pkgMgr.getPackagesForUid(uid);
5129
5130 final long identity = Binder.clearCallingIdentity();
5131 try {
5132 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5133 SubscriptionManager subManager = (SubscriptionManager)
5134 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5135 for (String pkg : packages) {
5136 if (subManager.canManageSubscription(subInfo, pkg)) {
5137 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5138 }
5139 }
5140 return privilegeFromSim;
5141 } finally {
5142 Binder.restoreCallingIdentity(identity);
5143 }
5144 }
5145
5146 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5147 String pkgName) {
5148 //load access rules from carrier configs, and check those as well: b/139133814
5149 SubscriptionController subController = SubscriptionController.getInstance();
5150 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5151 || subController == null) return privilegeFromSim;
5152
5153 final long identity = Binder.clearCallingIdentity();
5154 try {
5155 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5156 SubscriptionManager subManager = (SubscriptionManager)
5157 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5158 return subManager.canManageSubscription(subInfo, pkgName)
5159 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5160 } finally {
5161 Binder.restoreCallingIdentity(identity);
5162 }
5163 }
5164
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005165 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005166 public int getCarrierPrivilegeStatus(int subId) {
5167 final Phone phone = getPhone(subId);
5168 if (phone == null) {
5169 loge("getCarrierPrivilegeStatus: Invalid subId");
5170 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5171 }
5172 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005173 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005174 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005175 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5176 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005177
5178 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5179 card.getCarrierPrivilegeStatusForCurrentTransaction(
5180 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005181 }
Junda Liu29340342014-07-10 15:23:27 -07005182
5183 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005184 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005185 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005186 final Phone phone = getPhone(subId);
5187 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005188 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005189 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5190 }
5191 UiccProfile profile =
5192 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5193 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005194 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005195 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5196 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005197 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005198 profile.getCarrierPrivilegeStatusForUid(
5199 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005200 }
5201
5202 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005203 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5204 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005205 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005206 }
5207
5208 int phoneId = SubscriptionManager.getPhoneId(subId);
5209 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005210 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005211 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005212 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5213 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005214 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5215 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5216 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005217 }
5218
5219 @Override
5220 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005221 if (TextUtils.isEmpty(pkgName))
5222 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005223 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5224 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5225 UiccCard card = UiccController.getInstance().getUiccCard(i);
5226 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005227 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005228 continue;
5229 }
5230
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005231 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5232 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5233 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005234 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5235 break;
5236 }
5237 }
5238
5239 return result;
Junda Liu29340342014-07-10 15:23:27 -07005240 }
Derek Tan89e89d42014-07-08 17:00:10 -07005241
5242 @Override
Junda Liue64de782015-04-16 17:19:16 -07005243 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5244 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5245 loge("phoneId " + phoneId + " is not valid.");
5246 return null;
5247 }
5248 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005249 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005250 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005251 return null ;
5252 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005253 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005254 }
5255
Amith Yamasani6e118872016-02-19 12:53:51 -08005256 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005257 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005258 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005259 List<String> privilegedPackages = new ArrayList<>();
5260 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005261 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5262 // has UICC in that slot.
5263 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005264 if (card.hasCarrierPrivilegeRules()) {
5265 if (packages == null) {
5266 // Only check packages in user 0 for now
5267 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005268 PackageManager.MATCH_DISABLED_COMPONENTS
5269 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005270 | PackageManager.GET_SIGNING_CERTIFICATES,
5271 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005272 }
5273 for (int p = packages.size() - 1; p >= 0; p--) {
5274 PackageInfo pkgInfo = packages.get(p);
5275 if (pkgInfo != null && pkgInfo.packageName != null
5276 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005277 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005278 privilegedPackages.add(pkgInfo.packageName);
5279 }
5280 }
5281 }
5282 }
5283 return privilegedPackages;
5284 }
5285
chen xuf7e9fe82019-05-09 19:31:02 -07005286 @Override
5287 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005288 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5289
5290 final long identity = Binder.clearCallingIdentity();
5291
chen xuf7e9fe82019-05-09 19:31:02 -07005292 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005293 try {
5294 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5295 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5296 }
5297 } finally {
5298 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005299 }
5300 return privilegedPackages;
5301 }
5302
Wink Savilleb564aae2014-10-23 10:18:09 -07005303 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005304 final Phone phone = getPhone(subId);
5305 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005306 if (card == null) {
5307 loge("getIccId: No UICC");
5308 return null;
5309 }
5310 String iccId = card.getIccId();
5311 if (TextUtils.isEmpty(iccId)) {
5312 loge("getIccId: ICC ID is null or empty.");
5313 return null;
5314 }
5315 return iccId;
5316 }
5317
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005318 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005319 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5320 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005321 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005322 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 final long identity = Binder.clearCallingIdentity();
5325 try {
5326 final String iccId = getIccId(subId);
5327 final Phone phone = getPhone(subId);
5328 if (phone == null) {
5329 return false;
5330 }
5331 final String subscriberId = phone.getSubscriberId();
5332
5333 if (DBG_MERGE) {
5334 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5335 + subscriberId + " to " + number);
5336 }
5337
5338 if (TextUtils.isEmpty(iccId)) {
5339 return false;
5340 }
5341
5342 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5343
5344 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5345 if (alphaTag == null) {
5346 editor.remove(alphaTagPrefKey);
5347 } else {
5348 editor.putString(alphaTagPrefKey, alphaTag);
5349 }
5350
5351 // Record both the line number and IMSI for this ICCID, since we need to
5352 // track all merged IMSIs based on line number
5353 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5354 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5355 if (number == null) {
5356 editor.remove(numberPrefKey);
5357 editor.remove(subscriberPrefKey);
5358 } else {
5359 editor.putString(numberPrefKey, number);
5360 editor.putString(subscriberPrefKey, subscriberId);
5361 }
5362
5363 editor.commit();
5364 return true;
5365 } finally {
5366 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005367 }
Derek Tan7226c842014-07-02 17:42:23 -07005368 }
5369
5370 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005371 public String getLine1NumberForDisplay(int subId, String callingPackage,
5372 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005373 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005375 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005376 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005377 return null;
5378 }
Derek Tan97ebb422014-09-05 16:55:38 -07005379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 final long identity = Binder.clearCallingIdentity();
5381 try {
5382 String iccId = getIccId(subId);
5383 if (iccId != null) {
5384 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5385 if (DBG_MERGE) {
5386 log("getLine1NumberForDisplay returning "
5387 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5388 }
5389 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005390 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5392 return null;
5393 } finally {
5394 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005395 }
Derek Tan7226c842014-07-02 17:42:23 -07005396 }
5397
5398 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005399 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5400 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005401 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005402 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005403 return null;
5404 }
Derek Tan97ebb422014-09-05 16:55:38 -07005405
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 final long identity = Binder.clearCallingIdentity();
5407 try {
5408 String iccId = getIccId(subId);
5409 if (iccId != null) {
5410 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5411 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5412 }
5413 return null;
5414 } finally {
5415 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005416 }
Derek Tan7226c842014-07-02 17:42:23 -07005417 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005418
5419 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005420 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5421 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005422 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5423 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005424 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005425 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005426 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005427 return null;
5428 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005429
Jordan Liub49b04b2019-05-06 14:45:15 -07005430 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5431 // the process, where TelephonyManager was instantiated.
5432 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005433 final long identity = Binder.clearCallingIdentity();
5434 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005435 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005436 final TelephonyManager tele = TelephonyManager.from(context);
5437 final SubscriptionManager sub = SubscriptionManager.from(context);
5438
5439 // Figure out what subscribers are currently active
5440 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441
Jordan Liub49b04b2019-05-06 14:45:15 -07005442 // Only consider subs which match the current subId
5443 // This logic can be simplified. See b/131189269 for progress.
5444 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005445 activeSubscriberIds.add(tele.getSubscriberId(subId));
5446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447
5448 // First pass, find a number override for an active subscriber
5449 String mergeNumber = null;
5450 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5451 for (String key : prefs.keySet()) {
5452 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5453 final String subscriberId = (String) prefs.get(key);
5454 if (activeSubscriberIds.contains(subscriberId)) {
5455 final String iccId = key.substring(
5456 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5457 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5458 mergeNumber = (String) prefs.get(numberKey);
5459 if (DBG_MERGE) {
5460 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5461 + " for active subscriber " + subscriberId);
5462 }
5463 if (!TextUtils.isEmpty(mergeNumber)) {
5464 break;
5465 }
5466 }
5467 }
5468 }
5469
5470 // Shortcut when no active merged subscribers
5471 if (TextUtils.isEmpty(mergeNumber)) {
5472 return null;
5473 }
5474
5475 // Second pass, find all subscribers under that line override
5476 final ArraySet<String> result = new ArraySet<>();
5477 for (String key : prefs.keySet()) {
5478 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5479 final String number = (String) prefs.get(key);
5480 if (mergeNumber.equals(number)) {
5481 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5482 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5483 final String subscriberId = (String) prefs.get(subscriberKey);
5484 if (!TextUtils.isEmpty(subscriberId)) {
5485 result.add(subscriberId);
5486 }
5487 }
5488 }
5489 }
5490
5491 final String[] resultArray = result.toArray(new String[result.size()]);
5492 Arrays.sort(resultArray);
5493 if (DBG_MERGE) {
5494 Slog.d(LOG_TAG,
5495 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5496 }
5497 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005498 } finally {
5499 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005500 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005501 }
5502
5503 @Override
zoey chen38003472019-12-13 17:16:31 +08005504 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5505 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005506
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 final TelephonyManager telephonyManager = mApp.getSystemService(
5510 TelephonyManager.class);
5511 String subscriberId = telephonyManager.getSubscriberId(subId);
5512 if (subscriberId == null) {
5513 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005514 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005515 + subId);
5516 }
5517 return null;
5518 }
5519
5520 final SubscriptionInfo info = SubscriptionController.getInstance()
5521 .getSubscriptionInfo(subId);
5522 final ParcelUuid groupUuid = info.getGroupUuid();
5523 // If it doesn't belong to any group, return just subscriberId of itself.
5524 if (groupUuid == null) {
5525 return new String[]{subscriberId};
5526 }
5527
5528 // Get all subscriberIds from the group.
5529 final List<String> mergedSubscriberIds = new ArrayList<>();
5530 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005531 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5532 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005533 for (SubscriptionInfo subInfo : groupInfos) {
5534 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5535 if (subscriberId != null) {
5536 mergedSubscriberIds.add(subscriberId);
5537 }
5538 }
5539
5540 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
5543
5544 }
5545 }
5546
5547 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005548 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005549 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005550 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551
5552 final long identity = Binder.clearCallingIdentity();
5553 try {
5554 final Phone phone = getPhone(subId);
5555 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5556 } finally {
5557 Binder.restoreCallingIdentity(identity);
5558 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005559 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005560
5561 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005562 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005563 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5564 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005565 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5566 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567
5568 final long identity = Binder.clearCallingIdentity();
5569 try {
5570 final Phone phone = getPhone(subId);
5571 if (phone == null) {
5572 return false;
5573 }
5574 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5575 cdmaNonRoamingList);
5576 } finally {
5577 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005578 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005579 }
5580
5581 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005582 @Deprecated
5583 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5584 enforceModifyPermission();
5585
5586 int returnValue = 0;
5587 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005588 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005589 if(result.exception == null) {
5590 if (result.result != null) {
5591 byte[] responseData = (byte[])(result.result);
5592 if(responseData.length > oemResp.length) {
5593 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5594 responseData.length + "bytes. Buffer Size is " +
5595 oemResp.length + "bytes.");
5596 }
5597 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5598 returnValue = responseData.length;
5599 }
5600 } else {
5601 CommandException ex = (CommandException) result.exception;
5602 returnValue = ex.getCommandError().ordinal();
5603 if(returnValue > 0) returnValue *= -1;
5604 }
5605 } catch (RuntimeException e) {
5606 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5607 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5608 if(returnValue > 0) returnValue *= -1;
5609 }
5610
5611 return returnValue;
5612 }
5613
5614 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005615 public void setRadioCapability(RadioAccessFamily[] rafs) {
5616 try {
5617 ProxyController.getInstance().setRadioCapability(rafs);
5618 } catch (RuntimeException e) {
5619 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5620 }
5621 }
5622
5623 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005624 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005625 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005626 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005627 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005628 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005629 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630 final long identity = Binder.clearCallingIdentity();
5631 try {
chen xub97461a2018-10-26 14:17:57 -07005632 TelephonyPermissions
5633 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5634 mApp, phone.getSubId(), "getRadioAccessFamily");
5635 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636 } finally {
5637 Binder.restoreCallingIdentity(identity);
5638 }
chen xub97461a2018-10-26 14:17:57 -07005639 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005640 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005641
5642 @Override
5643 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005644 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005645 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646
5647 final long identity = Binder.clearCallingIdentity();
5648 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005649 ImsManager.getInstance(defaultPhone.getContext(),
5650 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005651 } finally {
5652 Binder.restoreCallingIdentity(identity);
5653 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005654 }
5655
5656 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005657 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005658 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005659 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5660 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005661 return false;
5662 }
Svet Ganovb320e182015-04-16 12:30:10 -07005663
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 final long identity = Binder.clearCallingIdentity();
5665 try {
5666 // Check the user preference and the system-level IMS setting. Even if the user has
5667 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5668 // In the long run, we may instead need to check if there exists a connection service
5669 // which can support video calling.
5670 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005671 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672 return imsManager.isVtEnabledByPlatform()
5673 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5674 && imsManager.isVtEnabledByUser();
5675 } finally {
5676 Binder.restoreCallingIdentity(identity);
5677 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005678 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005679
Andrew Leea1239f22015-03-02 17:44:07 -08005680 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005681 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5682 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005684 mApp, subId, callingPackage, callingFeatureId,
5685 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 return false;
5687 }
5688
5689 final long identity = Binder.clearCallingIdentity();
5690 try {
5691 CarrierConfigManager configManager =
5692 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005693 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5695 } finally {
5696 Binder.restoreCallingIdentity(identity);
5697 }
Andrew Leea1239f22015-03-02 17:44:07 -08005698 }
5699
5700 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005701 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005703 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 return false;
5705 }
5706
5707 final long identity = Binder.clearCallingIdentity();
5708 try {
5709 CarrierConfigManager configManager =
5710 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005711 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5713 } finally {
5714 Binder.restoreCallingIdentity(identity);
5715 }
Andrew Leea1239f22015-03-02 17:44:07 -08005716 }
5717
Andrew Lee9431b832015-03-09 18:46:45 -07005718 @Override
5719 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005720 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005721 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005722 }
5723
5724 @Override
5725 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 final long identity = Binder.clearCallingIdentity();
5727 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005728 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729 } finally {
5730 Binder.restoreCallingIdentity(identity);
5731 }
Andrew Lee9431b832015-03-09 18:46:45 -07005732 }
5733
Hall Liuf6668912018-10-31 17:05:23 -07005734 /**
5735 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5736 * support for the feature and device firmware support.
5737 *
5738 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5739 */
5740 @Override
5741 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005743 final Phone phone = getPhone(subscriptionId);
5744 if (phone == null) {
5745 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5746 return false;
5747 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005749 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5751 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005752 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005753 return isCarrierSupported && isDeviceSupported;
5754 } finally {
5755 Binder.restoreCallingIdentity(identity);
5756 }
Hall Liu98187582018-01-22 19:15:32 -08005757 }
5758
Hall Liuf6668912018-10-31 17:05:23 -07005759 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005760 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5761 * RTT setting, will return true if the device and carrier both support RTT.
5762 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005763 */
5764 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 final long identity = Binder.clearCallingIdentity();
5766 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00005767 boolean isRttSupported = isRttSupported(subscriptionId);
5768 boolean isUserRttSettingOn = Settings.Secure.getInt(
5769 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5770 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5771 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5772 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 } finally {
5774 Binder.restoreCallingIdentity(identity);
5775 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005776 }
5777
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005778 @Deprecated
5779 @Override
5780 public String getDeviceId(String callingPackage) {
5781 return getDeviceIdWithFeature(callingPackage, null);
5782 }
5783
Sanket Padawe7310cc72015-01-14 09:53:20 -08005784 /**
5785 * Returns the unique device ID of phone, for example, the IMEI for
5786 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5787 *
5788 * <p>Requires Permission:
5789 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5790 */
5791 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005792 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005793 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005794 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005795 return null;
5796 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005797 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005798 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005799 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005800 return null;
5801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005802
5803 final long identity = Binder.clearCallingIdentity();
5804 try {
5805 return phone.getDeviceId();
5806 } finally {
5807 Binder.restoreCallingIdentity(identity);
5808 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005809 }
5810
Ping Sunc67b7c22016-03-02 19:16:45 +08005811 /**
5812 * {@hide}
5813 * Returns the IMS Registration Status on a particular subid
5814 *
5815 * @param subId
5816 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005817 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005818 Phone phone = getPhone(subId);
5819 if (phone != null) {
5820 return phone.isImsRegistered();
5821 } else {
5822 return false;
5823 }
5824 }
5825
Santos Cordon7a1885b2015-02-03 11:15:19 -08005826 @Override
5827 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005828 final long identity = Binder.clearCallingIdentity();
5829 try {
5830 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5831 } finally {
5832 Binder.restoreCallingIdentity(identity);
5833 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005834 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005835
Tyler Gunnf70ed162019-04-03 15:28:53 -07005836 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005837 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005838 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005839 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005840 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005841 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5842 }
5843 final long identity = Binder.clearCallingIdentity();
5844 try {
5845 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5846 } finally {
5847 Binder.restoreCallingIdentity(identity);
5848 }
5849 }
5850
5851 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005852 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5853 final long identity = Binder.clearCallingIdentity();
5854 try {
5855 Phone phone = getPhone(subscriptionId);
5856 if (phone == null) {
5857 return null;
5858 }
5859 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5860 } finally {
5861 Binder.restoreCallingIdentity(identity);
5862 }
5863 }
5864
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005865 /**
5866 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005867 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005868 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005869 final long identity = Binder.clearCallingIdentity();
5870 try {
5871 Phone phone = getPhone(subId);
5872 if (phone != null) {
5873 return phone.isWifiCallingEnabled();
5874 } else {
5875 return false;
5876 }
5877 } finally {
5878 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005879 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005880 }
5881
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005882 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005883 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005884 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005885 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005886 final long identity = Binder.clearCallingIdentity();
5887 try {
5888 Phone phone = getPhone(subId);
5889 if (phone != null) {
5890 return phone.isVideoEnabled();
5891 } else {
5892 return false;
5893 }
5894 } finally {
5895 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005896 }
5897 }
5898
5899 /**
5900 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5901 * defined in {@link ImsRegistrationImplBase}.
5902 */
5903 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005904 final long identity = Binder.clearCallingIdentity();
5905 try {
5906 Phone phone = getPhone(subId);
5907 if (phone != null) {
5908 return phone.getImsRegistrationTech();
5909 } else {
5910 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5911 }
5912 } finally {
5913 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005914 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005915 }
5916
Stuart Scott8eef64f2015-04-08 15:13:54 -07005917 @Override
5918 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08005919 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005920 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5921 return;
5922 }
5923
Svet Ganovcc087f82015-05-12 20:35:54 -07005924 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005925
Svet Ganovcc087f82015-05-12 20:35:54 -07005926 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005927 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5928 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005929 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005930 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005931 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005932 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5933 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005934 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005935 // There has been issues when Sms raw table somehow stores orphan
5936 // fragments. They lead to garbled message when new fragments come
5937 // in and combined with those stale ones. In case this happens again,
5938 // user can reset all network settings which will clean up this table.
5939 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005940 // Clean up IMS settings as well here.
5941 int slotId = getSlotIndex(subId);
5942 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5943 ImsManager.getInstance(mApp, slotId).factoryReset();
5944 }
Naina Nallurid63128d2019-09-17 14:10:30 -07005945
5946 // Erase modem config if erase modem on network setting is enabled.
5947 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5948 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5949 if (configValue != null && Boolean.parseBoolean(configValue)) {
5950 sendEraseModemConfig(getDefaultPhone());
5951 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005952 } finally {
5953 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005954 }
5955 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005956
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005957 private void cleanUpSmsRawTable(Context context) {
5958 ContentResolver resolver = context.getContentResolver();
5959 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5960 resolver.delete(uri, null, null);
5961 }
5962
Narayan Kamath1c496c22015-04-16 14:40:19 +01005963 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005964 public String getSimLocaleForSubscriber(int subId) {
5965 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5966 final Phone phone = getPhone(subId);
5967 if (phone == null) {
5968 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005969 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 final long identity = Binder.clearCallingIdentity();
5972 try {
chen xu5d3637b2019-01-21 23:31:38 -08005973 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005974 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08005975 if (info == null) {
5976 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5977 return null;
5978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 // Try and fetch the locale from the carrier properties or from the SIM language
5980 // preferences (EF-PL and EF-LI)...
5981 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005983 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5984 if (localeFromDefaultSim != null) {
5985 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5986 if (DBG) log("Using locale from subId: " + subId + " locale: "
5987 + localeFromDefaultSim);
5988 return localeFromDefaultSim.toLanguageTag();
5989 } else {
5990 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 }
5992 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 // The SIM language preferences only store a language (e.g. fr = French), not an
5995 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5996 // the SIM and carrier preferences does not include a country we add the country
5997 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08005998 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006000 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 return mccLocale.toLanguageTag();
6002 }
6003
6004 if (DBG) log("No locale found - returning null");
6005 return null;
6006 } finally {
6007 Binder.restoreCallingIdentity(identity);
6008 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006009 }
6010
6011 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006012 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6013 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006014 }
6015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 /**
6017 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6018 */
6019 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006020 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6021 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006022 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006023
Chenjie Yu1ba97252018-01-11 18:16:20 -08006024 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006025 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006026
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006027 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006028 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6029 * representing the state of the modem.
6030 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006031 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6032 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006033 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006034 */
6035 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006036 public void requestModemActivityInfo(ResultReceiver result) {
6037 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006038 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039
6040 final long identity = Binder.clearCallingIdentity();
6041 try {
6042 ModemActivityInfo ret = null;
6043 synchronized (mLastModemActivityInfo) {
6044 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6045 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006046 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006047 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006049 int[] txTimeMs = info.getTransmitTimeMillis();
6050 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006052 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 }
6054 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006055 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6056 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057 mLastModemActivityInfo.setIdleTimeMillis(
6058 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006059 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6060 mLastModemActivityInfo.setReceiveTimeMillis(
6061 info.getReceiveTimeMillis() + mLastModemActivityInfo
6062 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006063 }
Chen Xud78231e2019-09-10 18:49:52 -07006064
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6066 mLastModemActivityInfo.getSleepTimeMillis(),
6067 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006068 mLastModemActivityInfo.getTransmitTimeMillis(),
6069 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 Bundle bundle = new Bundle();
6072 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6073 result.send(0, bundle);
6074 } finally {
6075 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006076 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006077 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006078
Siddharth Rayb8114062018-06-17 15:02:38 -07006079 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6080 // less than total activity duration.
6081 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6082 if (info == null) {
6083 return false;
6084 }
6085 int activityDurationMs =
6086 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6087 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006088 int[] txTimeMs = info.getTransmitTimeMillis();
6089 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6090 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006091 }
6092 return (info.isValid()
6093 && (info.getSleepTimeMillis() <= activityDurationMs)
6094 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006095 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006096 && (totalTxTimeMs <= activityDurationMs));
6097 }
6098
Jack Yu85bd38a2015-11-09 11:34:32 -08006099 /**
6100 * {@hide}
6101 * Returns the service state information on specified subscription.
6102 */
6103 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006104 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6105 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006106 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006107 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006108 return null;
6109 }
6110
Hall Liuf19c44f2018-11-27 14:38:17 -08006111 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6112 LocationAccessPolicy.checkLocationPermission(mApp,
6113 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6114 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006115 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006116 .setCallingPid(Binder.getCallingPid())
6117 .setCallingUid(Binder.getCallingUid())
6118 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006119 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006120 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6121 .build());
6122
6123 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6124 LocationAccessPolicy.checkLocationPermission(mApp,
6125 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6126 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006127 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006128 .setCallingPid(Binder.getCallingPid())
6129 .setCallingUid(Binder.getCallingUid())
6130 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006131 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006132 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6133 .build());
6134 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6135 boolean hasFinePermission =
6136 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6137 boolean hasCoarsePermission =
6138 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6139
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140 final long identity = Binder.clearCallingIdentity();
6141 try {
6142 final Phone phone = getPhone(subId);
6143 if (phone == null) {
6144 return null;
6145 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006146
Hall Liuf19c44f2018-11-27 14:38:17 -08006147 ServiceState ss = phone.getServiceState();
6148
6149 // Scrub out the location info in ServiceState depending on what level of access
6150 // the caller has.
6151 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006152 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6153 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154 } finally {
6155 Binder.restoreCallingIdentity(identity);
6156 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006157 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006158
6159 /**
6160 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6161 *
6162 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6163 * voicemail ringtone.
6164 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6165 * PhoneAccount.
6166 */
6167 @Override
6168 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 final long identity = Binder.clearCallingIdentity();
6170 try {
6171 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6172 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006173 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006174 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6177 } finally {
6178 Binder.restoreCallingIdentity(identity);
6179 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006180 }
6181
6182 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006183 * Sets the per-account voicemail ringtone.
6184 *
6185 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6186 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6187 *
6188 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6189 * voicemail ringtone.
6190 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6191 * PhoneAccount.
6192 */
6193 @Override
6194 public void setVoicemailRingtoneUri(String callingPackage,
6195 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006196 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006197 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006198 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6199 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6201 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6202 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204
6205 final long identity = Binder.clearCallingIdentity();
6206 try {
6207 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6208 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006209 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006210 }
6211 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6212 } finally {
6213 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006214 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006215 }
6216
6217 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006218 * Returns whether vibration is set for voicemail notification in Phone settings.
6219 *
6220 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6221 * voicemail vibration setting.
6222 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6223 */
6224 @Override
6225 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226 final long identity = Binder.clearCallingIdentity();
6227 try {
6228 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6229 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006230 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006232
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6234 } finally {
6235 Binder.restoreCallingIdentity(identity);
6236 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006237 }
6238
Youhan Wange64578a2016-05-02 15:32:42 -07006239 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006240 * Sets the per-account voicemail vibration.
6241 *
6242 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6243 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6244 *
6245 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6246 * voicemail vibration setting.
6247 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6248 * specific PhoneAccount.
6249 */
6250 @Override
6251 public void setVoicemailVibrationEnabled(String callingPackage,
6252 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006253 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006254 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006255 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6256 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6258 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6259 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006260 }
6261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262 final long identity = Binder.clearCallingIdentity();
6263 try {
6264 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6265 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006266 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 }
6268 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6269 } finally {
6270 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006271 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006272 }
6273
6274 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006275 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6276 *
6277 * @throws SecurityException if the caller does not have the required permission
6278 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006279 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006280 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006281 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006282 }
6283
6284 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006285 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6286 * permission.
6287 *
6288 * @throws SecurityException if the caller does not have the required permission
6289 */
6290 private void enforceSendSmsPermission() {
6291 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6292 }
6293
6294 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006295 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006296 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006297 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006298 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006299 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300 final long identity = Binder.clearCallingIdentity();
6301 try {
6302 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006303 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006304 if (componentName == null) {
6305 throw new SecurityException(
6306 "Caller not current active visual voicemail package[null]");
6307 }
6308 String vvmPackage = componentName.getPackageName();
6309 if (!callingPackage.equals(vvmPackage)) {
6310 throw new SecurityException("Caller not current active visual voicemail package["
6311 + vvmPackage + "]");
6312 }
6313 } finally {
6314 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006315 }
6316 }
6317
6318 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006319 * Return the application ID for the app type.
6320 *
6321 * @param subId the subscription ID that this request applies to.
6322 * @param appType the uicc app type.
6323 * @return Application ID for specificied app type, or null if no uicc.
6324 */
6325 @Override
6326 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006327 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006328 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329
6330 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006331 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 if (phone == null) {
6333 return null;
6334 }
6335 String aid = null;
6336 try {
6337 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6338 .getApplicationByType(appType).getAid();
6339 } catch (Exception e) {
6340 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6341 }
6342 return aid;
6343 } finally {
6344 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006345 }
Youhan Wange64578a2016-05-02 15:32:42 -07006346 }
6347
Youhan Wang4001d252016-05-11 10:29:41 -07006348 /**
6349 * Return the Electronic Serial Number.
6350 *
6351 * @param subId the subscription ID that this request applies to.
6352 * @return ESN or null if error.
6353 */
6354 @Override
6355 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006356 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006357 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358
6359 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006360 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006361 if (phone == null) {
6362 return null;
6363 }
6364 String esn = null;
6365 try {
6366 esn = phone.getEsn();
6367 } catch (Exception e) {
6368 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6369 }
6370 return esn;
6371 } finally {
6372 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006373 }
Youhan Wang4001d252016-05-11 10:29:41 -07006374 }
6375
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006376 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006377 * Return the Preferred Roaming List Version.
6378 *
6379 * @param subId the subscription ID that this request applies to.
6380 * @return PRLVersion or null if error.
6381 */
6382 @Override
6383 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006384 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006385 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386
6387 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006388 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389 if (phone == null) {
6390 return null;
6391 }
6392 String cdmaPrlVersion = null;
6393 try {
6394 cdmaPrlVersion = phone.getCdmaPrlVersion();
6395 } catch (Exception e) {
6396 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6397 }
6398 return cdmaPrlVersion;
6399 } finally {
6400 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006401 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006402 }
6403
6404 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006405 * Get snapshot of Telephony histograms
6406 * @return List of Telephony histograms
6407 * @hide
6408 */
6409 @Override
6410 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6412 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413
6414 final long identity = Binder.clearCallingIdentity();
6415 try {
6416 return RIL.getTelephonyRILTimingHistograms();
6417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006420 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006421
6422 /**
6423 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006424 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6425 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006426 * Require system privileges. In the future we may add this to carrier APIs.
6427 *
Michele Berionne482f8202018-11-27 18:57:59 -08006428 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006429 */
6430 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006431 @TelephonyManager.SetCarrierRestrictionResult
6432 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006433 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006434 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006435
Michele Berionne482f8202018-11-27 18:57:59 -08006436 if (carrierRestrictionRules == null) {
6437 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006438 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440 final long identity = Binder.clearCallingIdentity();
6441 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006442 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006443 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006444 } finally {
6445 Binder.restoreCallingIdentity(identity);
6446 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006447 }
6448
6449 /**
6450 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006451 * Get the allowed carrier list and the excluded carrier list, including the priority between
6452 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006453 * Require system privileges. In the future we may add this to carrier APIs.
6454 *
Michele Berionne482f8202018-11-27 18:57:59 -08006455 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006456 */
6457 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006458 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006459 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006460 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006461
6462 final long identity = Binder.clearCallingIdentity();
6463 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006464 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6465 if (response instanceof CarrierRestrictionRules) {
6466 return (CarrierRestrictionRules) response;
6467 }
6468 // Response is an Exception of some kind,
6469 // which is signalled to the user as a NULL retval
6470 return null;
6471 } catch (Exception e) {
6472 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6473 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006474 } finally {
6475 Binder.restoreCallingIdentity(identity);
6476 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006477 }
6478
fionaxu59545b42016-05-25 15:53:37 -07006479 /**
6480 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6481 * @param subId the subscription ID that this action applies to.
6482 * @param enabled control enable or disable metered apns.
6483 * {@hide}
6484 */
6485 @Override
6486 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6487 enforceModifyPermission();
6488 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489
6490 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006491 if (phone == null) {
6492 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6493 return;
6494 }
6495 try {
6496 phone.carrierActionSetMeteredApnsEnabled(enabled);
6497 } catch (Exception e) {
6498 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006499 } finally {
6500 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006501 }
6502 }
6503
6504 /**
6505 * Action set from carrier signalling broadcast receivers to enable/disable radio
6506 * @param subId the subscription ID that this action applies to.
6507 * @param enabled control enable or disable radio.
6508 * {@hide}
6509 */
6510 @Override
6511 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6512 enforceModifyPermission();
6513 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514
6515 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006516 if (phone == null) {
6517 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6518 return;
6519 }
6520 try {
6521 phone.carrierActionSetRadioEnabled(enabled);
6522 } catch (Exception e) {
6523 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006524 } finally {
6525 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006526 }
6527 }
6528
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006529 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006530 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6531 * network status based on which carrier apps could apply actions accordingly,
6532 * enable/disable default url handler for example.
6533 *
6534 * @param subId the subscription ID that this action applies to.
6535 * @param report control start/stop reporting the default network status.
6536 * {@hide}
6537 */
6538 @Override
6539 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6540 enforceModifyPermission();
6541 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542
6543 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006544 if (phone == null) {
6545 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6546 return;
6547 }
6548 try {
6549 phone.carrierActionReportDefaultNetworkStatus(report);
6550 } catch (Exception e) {
6551 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552 } finally {
6553 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006554 }
6555 }
6556
6557 /**
fionaxud9622282017-07-17 17:51:30 -07006558 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6559 * @param subId the subscription ID that this action applies to.
6560 * {@hide}
6561 */
6562 @Override
6563 public void carrierActionResetAll(int subId) {
6564 enforceModifyPermission();
6565 final Phone phone = getPhone(subId);
6566 if (phone == null) {
6567 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6568 return;
6569 }
6570 try {
6571 phone.carrierActionResetAll();
6572 } catch (Exception e) {
6573 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6574 }
6575 }
6576
6577 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006578 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6579 * bug report is being generated.
6580 */
6581 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006582 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006583 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6584 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006585 writer.println("Permission Denial: can't dump Phone from pid="
6586 + Binder.getCallingPid()
6587 + ", uid=" + Binder.getCallingUid()
6588 + "without permission "
6589 + android.Manifest.permission.DUMP);
6590 return;
6591 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006592 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006593 }
Jack Yueb89b242016-06-22 13:27:47 -07006594
Brad Ebingerdac2f002018-04-03 15:17:52 -07006595 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006596 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6597 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6598 @NonNull String[] args) {
6599 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6600 this, in.getFileDescriptor(), out.getFileDescriptor(),
6601 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006602 }
6603
Jack Yueb89b242016-06-22 13:27:47 -07006604 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006605 * Get aggregated video call data usage since boot.
6606 *
6607 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6608 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006609 * {@hide}
6610 */
6611 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006612 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006613 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6614 null);
6615
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616 final long identity = Binder.clearCallingIdentity();
6617 try {
6618 // NetworkStatsService keeps tracking the active network interface and identity. It
6619 // records the delta with the corresponding network identity.
6620 // We just return the total video call data usage snapshot since boot.
6621 Phone phone = getPhone(subId);
6622 if (phone != null) {
6623 return phone.getVtDataUsage(perUidStats);
6624 }
6625 return null;
6626 } finally {
6627 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006628 }
Jack Yueb89b242016-06-22 13:27:47 -07006629 }
Jack Yu75ab2952016-07-08 14:29:33 -07006630
6631 /**
6632 * Policy control of data connection. Usually used when data limit is passed.
6633 * @param enabled True if enabling the data, otherwise disabling.
6634 * @param subId Subscription index
6635 * {@hide}
6636 */
6637 @Override
6638 public void setPolicyDataEnabled(boolean enabled, int subId) {
6639 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006640
6641 final long identity = Binder.clearCallingIdentity();
6642 try {
6643 Phone phone = getPhone(subId);
6644 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006645 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006646 }
6647 } finally {
6648 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006649 }
6650 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006651
6652 /**
6653 * Get Client request stats
6654 * @return List of Client Request Stats
6655 * @hide
6656 */
6657 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006658 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6659 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006661 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006662 return null;
6663 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006664 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006665
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006666 final long identity = Binder.clearCallingIdentity();
6667 try {
6668 if (phone != null) {
6669 return phone.getClientRequestStats();
6670 }
6671
6672 return null;
6673 } finally {
6674 Binder.restoreCallingIdentity(identity);
6675 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006676 }
6677
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006678 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006679 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006680 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006681 }
Jack Yueb4124c2017-02-16 15:32:43 -08006682
6683 /**
Grace Chen70990072017-03-24 17:21:30 -07006684 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006685 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006686 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006687 * @param state State of SIM (power down, power up, pass through)
6688 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6689 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6690 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006691 *
6692 **/
6693 @Override
Grace Chen70990072017-03-24 17:21:30 -07006694 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006695 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006696 Phone phone = PhoneFactory.getPhone(slotIndex);
6697
vagdeviaf9a5b92018-08-15 16:01:53 -07006698 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 final long identity = Binder.clearCallingIdentity();
6701 try {
6702 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006703 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006704 }
6705 } finally {
6706 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006707 }
6708 }
Shuo Qiandd210312017-04-12 22:11:33 +00006709
Tyler Gunn65d45c22017-06-05 11:22:26 -07006710 private boolean isUssdApiAllowed(int subId) {
6711 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006712 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006713 if (configManager == null) {
6714 return false;
6715 }
6716 PersistableBundle pb = configManager.getConfigForSubId(subId);
6717 if (pb == null) {
6718 return false;
6719 }
6720 return pb.getBoolean(
6721 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6722 }
6723
Shuo Qiandd210312017-04-12 22:11:33 +00006724 /**
6725 * Check if phone is in emergency callback mode
6726 * @return true if phone is in emergency callback mode
6727 * @param subId sub id
6728 */
goneil9c5f4872017-12-05 14:07:56 -08006729 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006730 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006731 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006732 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733
6734 final long identity = Binder.clearCallingIdentity();
6735 try {
6736 if (phone != null) {
6737 return phone.isInEcm();
6738 } else {
6739 return false;
6740 }
6741 } finally {
6742 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006743 }
6744 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006745
6746 /**
6747 * Get the current signal strength information for the given subscription.
6748 * Because this information is not updated when the device is in a low power state
6749 * it should not be relied-upon to be current.
6750 * @param subId Subscription index
6751 * @return the most recent cached signal strength info from the modem
6752 */
6753 @Override
6754 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006755 final long identity = Binder.clearCallingIdentity();
6756 try {
6757 Phone p = getPhone(subId);
6758 if (p == null) {
6759 return null;
6760 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762 return p.getSignalStrength();
6763 } finally {
6764 Binder.restoreCallingIdentity(identity);
6765 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006766 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006767
Pengquan Meng77b7f132018-08-22 14:49:57 -07006768 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006769 * Get the current modem radio state for the given slot.
6770 * @param slotIndex slot index.
6771 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006772 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006773 * @return the current radio power state from the modem
6774 */
6775 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006776 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006777 Phone phone = PhoneFactory.getPhone(slotIndex);
6778 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006779 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6780 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006781 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6782 }
6783
6784 final long identity = Binder.clearCallingIdentity();
6785 try {
6786 return phone.getRadioPowerState();
6787 } finally {
6788 Binder.restoreCallingIdentity(identity);
6789 }
6790 }
6791 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6792 }
6793
6794 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006795 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6796 *
6797 * <p>Requires one of the following permissions:
6798 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6799 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6800 * privileges.
6801 *
6802 * @param subId subscription id
6803 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6804 * {@code false}.
6805 */
6806 @Override
6807 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006808 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6809 null /* message */);
6810
Pengquan Menga1bb6272018-09-06 09:59:22 -07006811 boolean isEnabled = false;
6812 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006813 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006814 Phone phone = getPhone(subId);
6815 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006816 } catch (Exception e) {
6817 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6818 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006819 } finally {
6820 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006821 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006822 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006823 }
6824
6825
6826 /**
6827 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6828 *
6829 * <p> Requires permission:
6830 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6831 * privileges.
6832 *
6833 * @param subId subscription id
6834 * @param isEnabled {@code true} means enable, {@code false} means disable.
6835 */
6836 @Override
6837 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6839 mApp, subId, "setDataRoamingEnabled");
6840
Pengquan Menga1bb6272018-09-06 09:59:22 -07006841 final long identity = Binder.clearCallingIdentity();
6842 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006843 Phone phone = getPhone(subId);
6844 if (phone != null) {
6845 phone.setDataRoamingEnabled(isEnabled);
6846 }
6847 } finally {
6848 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006849 }
6850 }
6851
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006852 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006853 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006854 TelephonyPermissions
6855 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006856 mApp, subId, "isManualNetworkSelectionAllowed");
6857
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006858 boolean isAllowed = true;
6859 final long identity = Binder.clearCallingIdentity();
6860 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006861 Phone phone = getPhone(subId);
6862 if (phone != null) {
6863 isAllowed = phone.isCspPlmnEnabled();
6864 }
6865 } finally {
6866 Binder.restoreCallingIdentity(identity);
6867 }
6868 return isAllowed;
6869 }
6870
6871 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006872 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006873 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006874 try {
6875 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006876 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006877 } catch (SecurityException e) {
6878 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6879 // has carrier privileges on an active UICC
6880 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6881 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006882 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006883 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006884 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006885
6886 final long identity = Binder.clearCallingIdentity();
6887 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006888 UiccController uiccController = UiccController.getInstance();
6889 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006890 if (hasReadPermission) {
6891 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006892 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006893
6894 // Remove private info if the caller doesn't have access
6895 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6896 for (UiccCardInfo cardInfo : cardInfos) {
6897 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6898 // is available
6899 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6900 if (card == null || card.getUiccProfile() == null) {
6901 // assume no access if the card or profile is unavailable
6902 filteredInfos.add(cardInfo.getUnprivileged());
6903 continue;
6904 }
6905 UiccProfile profile = card.getUiccProfile();
6906 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6907 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6908 filteredInfos.add(cardInfo);
6909 } else {
6910 filteredInfos.add(cardInfo.getUnprivileged());
6911 }
6912 }
6913 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006914 } finally {
6915 Binder.restoreCallingIdentity(identity);
6916 }
6917 }
6918
6919 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006920 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006921 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006923 final long identity = Binder.clearCallingIdentity();
6924 try {
6925 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6926 if (slots == null) {
6927 Rlog.i(LOG_TAG, "slots is null.");
6928 return null;
6929 }
6930
6931 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6932 for (int i = 0; i < slots.length; i++) {
6933 UiccSlot slot = slots[i];
6934 if (slot == null) {
6935 continue;
6936 }
6937
Jordan Liu7be7e652019-05-06 18:55:02 +00006938 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 UiccCard card = slot.getUiccCard();
6940 if (card != null) {
6941 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006942 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006943 cardId = slot.getEid();
6944 if (TextUtils.isEmpty(cardId)) {
6945 cardId = slot.getIccId();
6946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947 }
6948
Jordan Liu857451f2019-05-09 16:35:35 -07006949 if (cardId != null) {
6950 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6951 // if cardId is an EID, it's all digits so this is fine
6952 cardId = IccUtils.stripTrailingFs(cardId);
6953 }
6954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006955 int cardState = 0;
6956 switch (slot.getCardState()) {
6957 case CARDSTATE_ABSENT:
6958 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6959 break;
6960 case CARDSTATE_PRESENT:
6961 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6962 break;
6963 case CARDSTATE_ERROR:
6964 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6965 break;
6966 case CARDSTATE_RESTRICTED:
6967 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6968 break;
6969 default:
6970 break;
6971
6972 }
6973
6974 infos[i] = new UiccSlotInfo(
6975 slot.isActive(),
6976 slot.isEuicc(),
6977 cardId,
6978 cardState,
6979 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006980 slot.isExtendedApduSupported(),
6981 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 }
6983 return infos;
6984 } finally {
6985 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006986 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006987 }
6988
6989 @Override
6990 public boolean switchSlots(int[] physicalSlots) {
6991 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992
6993 final long identity = Binder.clearCallingIdentity();
6994 try {
6995 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6996 } finally {
6997 Binder.restoreCallingIdentity(identity);
6998 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006999 }
Jack Yu4c988042018-02-27 15:30:01 -08007000
7001 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007002 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007003 final long identity = Binder.clearCallingIdentity();
7004 try {
7005 return UiccController.getInstance().getCardIdForDefaultEuicc();
7006 } finally {
7007 Binder.restoreCallingIdentity(identity);
7008 }
7009 }
7010
7011 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007012 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7013 enforceModifyPermission();
7014 final Phone phone = getPhone(subId);
7015 if (phone == null) {
7016 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7017 return;
7018 }
7019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007020 final long identity = Binder.clearCallingIdentity();
7021 try {
7022 phone.setRadioIndicationUpdateMode(filters, mode);
7023 } finally {
7024 Binder.restoreCallingIdentity(identity);
7025 }
Jack Yu4c988042018-02-27 15:30:01 -08007026 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007027
7028 /**
goneil47ffb6e2018-04-06 15:40:58 -07007029 * A test API to reload the UICC profile.
7030 *
7031 * <p>Requires that the calling app has permission
7032 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7033 * @hide
7034 */
7035 @Override
7036 public void refreshUiccProfile(int subId) {
7037 enforceModifyPermission();
7038
7039 final long identity = Binder.clearCallingIdentity();
7040 try {
7041 Phone phone = getPhone(subId);
7042 if (phone == null) {
7043 return;
7044 }
7045 UiccCard uiccCard = phone.getUiccCard();
7046 if (uiccCard == null) {
7047 return;
7048 }
7049 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7050 if (uiccProfile == null) {
7051 return;
7052 }
7053 uiccProfile.refresh();
7054 } finally {
7055 Binder.restoreCallingIdentity(identity);
7056 }
7057 }
7058
7059 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007060 * Returns false if the mobile data is disabled by default, otherwise return true.
7061 */
7062 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007063 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007064 }
7065
7066 /**
7067 * Returns true if the data roaming is enabled by default, i.e the system property
7068 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7069 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7070 */
7071 private boolean getDefaultDataRoamingEnabled(int subId) {
7072 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007073 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007074 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007075 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7076 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7077 return isDataRoamingEnabled;
7078 }
7079
7080 /**
7081 * Returns the default network type for the given {@code subId}, if the default network type is
7082 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7083 */
7084 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007085 List<Integer> list = TelephonyProperties.default_network();
7086 int phoneId = mSubscriptionController.getPhoneId(subId);
7087 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7088 return list.get(phoneId);
7089 }
7090 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007091 }
fionaxua13278b2018-03-21 00:08:13 -07007092
7093 @Override
7094 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007095 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007096 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097
7098 final long identity = Binder.clearCallingIdentity();
7099 try {
7100 final Phone phone = getPhone(subId);
7101 if (phone == null) {
7102 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7103 return;
7104 }
chen xueaba88a2019-03-15 13:15:10 -07007105 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7106 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107 } finally {
7108 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007109 }
fionaxua13278b2018-03-21 00:08:13 -07007110 }
7111
7112 @Override
7113 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007114 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007115
7116 final long identity = Binder.clearCallingIdentity();
7117 try {
7118 final Phone phone = getPhone(subId);
7119 if (phone == null) {
7120 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7121 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7122 }
7123 return phone.getCarrierIdListVersion();
7124 } finally {
7125 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007126 }
fionaxua13278b2018-03-21 00:08:13 -07007127 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007128
7129 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007130 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7131 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007133 mApp, subId, callingPackage, callingFeatureId,
7134 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007135 return -1;
7136 }
7137
7138 final long identity = Binder.clearCallingIdentity();
7139 try {
7140 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7141 } finally {
7142 Binder.restoreCallingIdentity(identity);
7143 }
7144 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007145
7146 @Override
7147 public int getCdmaRoamingMode(int subId) {
7148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7149 mApp, subId, "getCdmaRoamingMode");
7150
7151 final long identity = Binder.clearCallingIdentity();
7152 try {
7153 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7154 } finally {
7155 Binder.restoreCallingIdentity(identity);
7156 }
7157 }
7158
7159 @Override
7160 public boolean setCdmaRoamingMode(int subId, int mode) {
7161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7162 mApp, subId, "setCdmaRoamingMode");
7163
7164 final long identity = Binder.clearCallingIdentity();
7165 try {
7166 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7167 } finally {
7168 Binder.restoreCallingIdentity(identity);
7169 }
7170 }
7171
7172 @Override
7173 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7175 mApp, subId, "setCdmaSubscriptionMode");
7176
7177 final long identity = Binder.clearCallingIdentity();
7178 try {
7179 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
7182 }
7183 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007184
sqianc5eccab2018-10-19 18:46:41 -07007185 @Override
sqian8c685422019-02-22 15:55:18 -08007186 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007187 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007189 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7190 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007191 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7192 }
7193 final long identity = Binder.clearCallingIdentity();
7194 try {
sqian854d44b2018-12-12 16:48:18 -08007195 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7196 for (Phone phone: PhoneFactory.getPhones()) {
7197 if (phone.getEmergencyNumberTracker() != null
7198 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7199 emergencyNumberListInternal.put(
7200 phone.getSubId(),
7201 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7202 }
sqian11b7a0e2018-12-05 18:48:28 -08007203 }
sqian854d44b2018-12-12 16:48:18 -08007204 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007205 } finally {
7206 Binder.restoreCallingIdentity(identity);
7207 }
sqianc5eccab2018-10-19 18:46:41 -07007208 }
7209
7210 @Override
sqian8c685422019-02-22 15:55:18 -08007211 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007212 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007213 if (!exactMatch) {
7214 TelephonyPermissions
7215 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007216 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007217 }
7218 final long identity = Binder.clearCallingIdentity();
7219 try {
sqian854d44b2018-12-12 16:48:18 -08007220 for (Phone phone: PhoneFactory.getPhones()) {
7221 if (phone.getEmergencyNumberTracker() != null
7222 && phone.getEmergencyNumberTracker() != null) {
7223 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7224 number, exactMatch)) {
7225 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007226 }
7227 }
sqian11b7a0e2018-12-05 18:48:28 -08007228 }
7229 return false;
7230 } finally {
7231 Binder.restoreCallingIdentity(identity);
7232 }
7233 }
7234
sqianf4ca7ed2019-01-15 18:32:07 -08007235 /**
7236 * Update emergency number list for test mode.
7237 */
7238 @Override
7239 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7240 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7241 "updateEmergencyNumberListTestMode");
7242
7243 final long identity = Binder.clearCallingIdentity();
7244 try {
7245 for (Phone phone: PhoneFactory.getPhones()) {
7246 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7247 if (tracker != null) {
7248 tracker.executeEmergencyNumberTestModeCommand(action, num);
7249 }
7250 }
7251 } finally {
7252 Binder.restoreCallingIdentity(identity);
7253 }
7254 }
7255
7256 /**
7257 * Get the full emergency number list for test mode.
7258 */
7259 @Override
7260 public List<String> getEmergencyNumberListTestMode() {
7261 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7262 "getEmergencyNumberListTestMode");
7263
7264 final long identity = Binder.clearCallingIdentity();
7265 try {
7266 Set<String> emergencyNumbers = new HashSet<>();
7267 for (Phone phone: PhoneFactory.getPhones()) {
7268 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7269 if (tracker != null) {
7270 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7271 emergencyNumbers.add(num.getNumber());
7272 }
7273 }
7274 }
7275 return new ArrayList<>(emergencyNumbers);
7276 } finally {
7277 Binder.restoreCallingIdentity(identity);
7278 }
7279 }
7280
chen xud6b45bd2018-10-30 22:27:10 -07007281 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007282 public int getEmergencyNumberDbVersion(int subId) {
7283 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7284
7285 final long identity = Binder.clearCallingIdentity();
7286 try {
7287 final Phone phone = getPhone(subId);
7288 if (phone == null) {
7289 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7290 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7291 }
7292 return phone.getEmergencyNumberDbVersion();
7293 } finally {
7294 Binder.restoreCallingIdentity(identity);
7295 }
7296 }
7297
7298 @Override
7299 public void notifyOtaEmergencyNumberDbInstalled() {
7300 enforceModifyPermission();
7301
7302 final long identity = Binder.clearCallingIdentity();
7303 try {
7304 for (Phone phone: PhoneFactory.getPhones()) {
7305 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7306 if (tracker != null) {
7307 tracker.updateOtaEmergencyNumberDatabase();
7308 }
7309 }
7310 } finally {
7311 Binder.restoreCallingIdentity(identity);
7312 }
7313 }
7314
7315 @Override
7316 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7317 enforceActiveEmergencySessionPermission();
7318
7319 final long identity = Binder.clearCallingIdentity();
7320 try {
7321 for (Phone phone: PhoneFactory.getPhones()) {
7322 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7323 if (tracker != null) {
7324 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7325 }
7326 }
7327 } finally {
7328 Binder.restoreCallingIdentity(identity);
7329 }
7330 }
7331
7332 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007333 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7334 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7335 Phone phone = getPhone(subId);
7336 if (phone == null) {
7337 return null;
7338 }
7339 final long identity = Binder.clearCallingIdentity();
7340 try {
7341 UiccProfile profile = UiccController.getInstance()
7342 .getUiccProfileForPhone(phone.getPhoneId());
7343 if (profile != null) {
7344 return profile.getCertsFromCarrierPrivilegeAccessRules();
7345 }
7346 } finally {
7347 Binder.restoreCallingIdentity(identity);
7348 }
7349 return null;
7350 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007351
7352 /**
7353 * Enable or disable a modem stack.
7354 */
7355 @Override
7356 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7357 enforceModifyPermission();
7358
7359 final long identity = Binder.clearCallingIdentity();
7360 try {
7361 Phone phone = PhoneFactory.getPhone(slotIndex);
7362 if (phone == null) {
7363 return false;
7364 } else {
7365 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7366 }
7367 } finally {
7368 Binder.restoreCallingIdentity(identity);
7369 }
7370 }
Michelecea4cf22018-12-21 15:00:11 -08007371
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007372 /**
7373 * Whether a modem stack is enabled or not.
7374 */
7375 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007376 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7377 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007378 Phone phone = PhoneFactory.getPhone(slotIndex);
7379 if (phone == null) return false;
7380
7381 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007382 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7383 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007384 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7385 }
7386
7387 final long identity = Binder.clearCallingIdentity();
7388 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007389 try {
7390 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7391 } catch (NoSuchElementException ex) {
7392 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7393 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007394 } finally {
7395 Binder.restoreCallingIdentity(identity);
7396 }
7397 }
7398
Michelecea4cf22018-12-21 15:00:11 -08007399 @Override
Michele0ea7d782019-03-19 14:58:42 -07007400 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007401 enforceModifyPermission();
7402
7403 final long identity = Binder.clearCallingIdentity();
7404 try {
7405 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007406 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007407 .commit();
7408 } finally {
7409 Binder.restoreCallingIdentity(identity);
7410 }
7411 }
7412
7413 @Override
Michele0ea7d782019-03-19 14:58:42 -07007414 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007415 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007416 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007417 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7418 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007419 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007420 }
Michelecea4cf22018-12-21 15:00:11 -08007421
7422 final long identity = Binder.clearCallingIdentity();
7423 try {
Michele0ea7d782019-03-19 14:58:42 -07007424 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007425 } finally {
7426 Binder.restoreCallingIdentity(identity);
7427 }
7428 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007429
Michele0ea7d782019-03-19 14:58:42 -07007430 @TelephonyManager.IsMultiSimSupportedResult
7431 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007432 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7433 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7434 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007435 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7436 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007437 }
7438 // Check if the hardware supports multisim functionality. If usage of multisim is not
7439 // supported by the modem, indicate that it is restricted.
7440 PhoneCapability staticCapability =
7441 mPhoneConfigurationManager.getStaticPhoneCapability();
7442 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007443 loge("isMultiSimSupportedInternal: no static configuration available");
7444 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007445 }
7446 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007447 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7448 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007449 }
7450 // Check if support of multiple SIMs is restricted by carrier
7451 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007452 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007453 }
7454
Michele0ea7d782019-03-19 14:58:42 -07007455 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007456 }
7457
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007458 /**
7459 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007460 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7461 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7462 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007463 * @param numOfSims number of active sims we want to switch to
7464 */
7465 @Override
7466 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007467 if (numOfSims == 1) {
7468 enforceModifyPermission();
7469 } else {
7470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7471 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7472 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007473 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007474
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007475 try {
Michele30b57b22019-03-01 12:01:14 -08007476 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007477 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007478 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7479 return;
7480 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007481 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7482 } finally {
7483 Binder.restoreCallingIdentity(identity);
7484 }
7485 }
7486
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007487 @Override
7488 public boolean isApplicationOnUicc(int subId, int appType) {
7489 enforceReadPrivilegedPermission("isApplicationOnUicc");
7490 Phone phone = getPhone(subId);
7491 if (phone == null) {
7492 return false;
7493 }
7494 final long identity = Binder.clearCallingIdentity();
7495 try {
7496 UiccCard uiccCard = phone.getUiccCard();
7497 if (uiccCard == null) {
7498 return false;
7499 }
7500 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7501 if (uiccProfile == null) {
7502 return false;
7503 }
7504 if (TelephonyManager.APPTYPE_SIM <= appType
7505 && appType <= TelephonyManager.APPTYPE_ISIM) {
7506 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7507 }
7508 return false;
7509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
7512 }
7513
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007514 /**
chen xub4baa772019-04-03 10:23:41 -07007515 * Get whether making changes to modem configurations will trigger reboot.
7516 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007517 */
7518 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007519 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7520 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007521 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007522 mApp, subId, callingPackage, callingFeatureId,
7523 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007524 return false;
7525 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007526 final long identity = Binder.clearCallingIdentity();
7527 try {
7528 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7529 } finally {
7530 Binder.restoreCallingIdentity(identity);
7531 }
7532 }
7533
Nathan Harold29f5f052019-02-15 13:41:57 -08007534 private void updateModemStateMetrics() {
7535 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7536 // TODO: check the state for each modem if the api is ready.
7537 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7538 }
7539
Pengquan Meng3889a572019-01-23 11:16:29 -08007540 @Override
7541 public int[] getSlotsMapping() {
7542 enforceReadPrivilegedPermission("getSlotsMapping");
7543
7544 final long identity = Binder.clearCallingIdentity();
7545 try {
7546 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7547 // All logical slots should have a mapping to a physical slot.
7548 int[] logicalSlotsMapping = new int[phoneCount];
7549 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7550 for (int i = 0; i < slotInfos.length; i++) {
7551 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7552 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7553 }
7554 }
7555 return logicalSlotsMapping;
7556 } finally {
7557 Binder.restoreCallingIdentity(identity);
7558 }
7559 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007560
7561 /**
7562 * Get the IRadio HAL Version
7563 */
7564 @Override
7565 public int getRadioHalVersion() {
7566 Phone phone = getDefaultPhone();
7567 if (phone == null) return -1;
7568 HalVersion hv = phone.getHalVersion();
7569 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7570 return hv.major * 100 + hv.minor;
7571 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007572
7573 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007574 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7575 * corresponding network requests on a subId.
7576 *
7577 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007578 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007579 * 2) APN is un-metered for this subscription, or
7580 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007581 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007582 *
7583 * @return whether data is allowed for a apn type.
7584 *
7585 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007586 */
7587 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007588 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007589 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7590 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007591
7592 // Now that all security checks passes, perform the operation as ourselves.
7593 final long identity = Binder.clearCallingIdentity();
7594 try {
7595 Phone phone = getPhone(subId);
7596 if (phone == null) return false;
7597
Jack Yu41407ee2019-05-13 16:54:09 -07007598 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007599 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7600 } finally {
7601 Binder.restoreCallingIdentity(identity);
7602 }
7603 }
7604
7605 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007606 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007607 enforceReadPrivilegedPermission("isApnMetered");
7608
7609 // Now that all security checks passes, perform the operation as ourselves.
7610 final long identity = Binder.clearCallingIdentity();
7611 try {
7612 Phone phone = getPhone(subId);
7613 if (phone == null) return true; // By default return true.
7614
Jack Yu41407ee2019-05-13 16:54:09 -07007615 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007616 } finally {
7617 Binder.restoreCallingIdentity(identity);
7618 }
7619 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007620
7621 @Override
changbetty7157e9e2019-12-06 18:16:37 +08007622 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7623 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7624 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7625 if (iccRecords == null) {
7626 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7627 return false;
7628 }
7629 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7630 }
7631
7632 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007633 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7634 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7635 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7636 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7637 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7638 }
7639 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7640 Intent intent = new Intent();
7641 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7642 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7643 // Bring up choose default SMS subscription dialog right now
7644 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7645 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7646 mApp.startActivity(intent);
7647 }
chen xud5ca2d52019-05-28 15:20:57 -07007648
7649 @Override
7650 public String getMmsUAProfUrl(int subId) {
7651 //TODO investigate if this API should require proper permission check in R b/133791609
7652 final long identity = Binder.clearCallingIdentity();
7653 try {
7654 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7655 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7656 } finally {
7657 Binder.restoreCallingIdentity(identity);
7658 }
7659 }
7660
7661 @Override
7662 public String getMmsUserAgent(int subId) {
7663 //TODO investigate if this API should require proper permission check in R b/133791609
7664 final long identity = Binder.clearCallingIdentity();
7665 try {
7666 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7667 .getString(com.android.internal.R.string.config_mms_user_agent);
7668 } finally {
7669 Binder.restoreCallingIdentity(identity);
7670 }
7671 }
Jack Yub07d4972019-05-28 16:12:25 -07007672
7673 @Override
7674 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7675 enforceModifyPermission();
7676
7677 // Now that all security checks passes, perform the operation as ourselves.
7678 final long identity = Binder.clearCallingIdentity();
7679 try {
7680 Phone phone = getPhone(subId);
7681 if (phone == null) return false;
7682
7683 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7684 } finally {
7685 Binder.restoreCallingIdentity(identity);
7686 }
7687 }
7688
7689 @Override
7690 public boolean isDataAllowedInVoiceCall(int subId) {
7691 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7692
7693 // Now that all security checks passes, perform the operation as ourselves.
7694 final long identity = Binder.clearCallingIdentity();
7695 try {
7696 Phone phone = getPhone(subId);
7697 if (phone == null) return false;
7698
7699 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
7702 }
7703 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007704
changbettyd5c246e2019-12-24 15:40:37 +08007705 @Override
7706 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
7707 enforceModifyPermission();
7708
7709 // Now that all security checks passes, perform the operation as ourselves.
7710 final long identity = Binder.clearCallingIdentity();
7711 try {
7712 Phone phone = getPhone(subId);
7713 if (phone == null) return false;
7714
7715 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
7716 } finally {
7717 Binder.restoreCallingIdentity(identity);
7718 }
7719 }
7720
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007721 /**
7722 * Updates whether conference event pacakge handling is enabled.
7723 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7724 * otherwise.
7725 */
7726 @Override
7727 public void setCepEnabled(boolean isCepEnabled) {
7728 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7729
7730 final long identity = Binder.clearCallingIdentity();
7731 try {
7732 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7733 for (Phone phone : PhoneFactory.getPhones()) {
7734 Phone defaultPhone = phone.getImsPhone();
7735 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7736 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7737 ImsPhoneCallTracker imsPhoneCallTracker =
7738 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7739 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7740 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7741 + imsPhone.getMsisdn());
7742 }
7743 }
7744 } finally {
7745 Binder.restoreCallingIdentity(identity);
7746 }
7747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007748}