blob: 07b0e4a47f4472de8c86dfd3182c97ed01cdffc5 [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;
Tyler Gunnf70ed162019-04-03 15:28:53 -070025import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070028import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070029import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.content.Context;
31import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070032import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070033import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070037import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080050import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070051import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070054import android.os.ShellCallback;
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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070071import android.telephony.CellInfoGsm;
72import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070073import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070074import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070075import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070076import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080077import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070078import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080079import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070080import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080081import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080082import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070083import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080084import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070085import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080087import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080088import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080089import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070090import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080092import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080093import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000094import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070095import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070096import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070097import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.data.ApnSetting;
99import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -0700100import android.telephony.gsm.GsmCellLocation;
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;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100136import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700137import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700138import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700140import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800141import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700142import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700143import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700144import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700145import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700146import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700147import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700148import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700149import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800150import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800151import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700152import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800153import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700154import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800155import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700156import com.android.internal.telephony.imsphone.ImsPhone;
157import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800158import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700159import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.uicc.IccIoResult;
161import 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;
fionaxu7ed723d2017-05-30 18:58:54 -0700168import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800169import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700170import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700171import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800172import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700173import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700174import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800175
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700176import java.io.FileDescriptor;
177import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800179import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800180import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800181import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800182import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100183import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800184import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700185import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800186import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187
188/**
189 * Implementation of the ITelephony interface.
190 */
Santos Cordon117fee72014-05-16 17:56:12 -0700191public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 private static final String LOG_TAG = "PhoneInterfaceManager";
193 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
194 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800195 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197 // Message codes used with mMainThreadHandler
198 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700199 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
200 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201 private static final int CMD_OPEN_CHANNEL = 9;
202 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
203 private static final int CMD_CLOSE_CHANNEL = 11;
204 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800205 private static final int CMD_NV_READ_ITEM = 13;
206 private static final int EVENT_NV_READ_ITEM_DONE = 14;
207 private static final int CMD_NV_WRITE_ITEM = 15;
208 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
209 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
210 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700211 private static final int CMD_RESET_MODEM_CONFIG = 19;
212 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800213 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
214 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
215 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
216 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800217 private static final int CMD_SEND_ENVELOPE = 25;
218 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000219 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
220 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700221 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
222 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
223 private static final int CMD_EXCHANGE_SIM_IO = 31;
224 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800225 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
226 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700227 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
228 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700229 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
230 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700231 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
232 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
233 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
234 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700235 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
236 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
237 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
238 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700239 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
241 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000242 private static final int CMD_SWITCH_SLOTS = 50;
243 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700244 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
245 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
246 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
247 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
248 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
249 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
250 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
251 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700252 private static final int CMD_GET_ALL_CELL_INFO = 60;
253 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
254 private static final int CMD_GET_CELL_LOCATION = 62;
255 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700256 private static final int CMD_MODEM_REBOOT = 64;
257 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700258 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
259 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800260 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
261 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700262 private static final int CMD_GET_MODEM_STATUS = 70;
263 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700264 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
265 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700266 private static final int CMD_ERASE_MODEM_CONFIG = 74;
267 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800269 // Parameters of select command.
270 private static final int SELECT_COMMAND = 0xA4;
271 private static final int SELECT_P1 = 0x04;
272 private static final int SELECT_P2 = 0;
273 private static final int SELECT_P3 = 0x10;
274
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 /** The singleton instance. */
276 private static PhoneInterfaceManager sInstance;
277
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700280 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private AppOpsManager mAppOps;
282 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800283 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700285 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286
Derek Tan97ebb422014-09-05 16:55:38 -0700287 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
288 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800289 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800290 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700291
Michelecea4cf22018-12-21 15:00:11 -0800292 // String to store multi SIM allowed
293 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
294
Derek Tan740e1672017-06-27 14:56:27 -0700295 // The AID of ISD-R.
296 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
297
yinxub1bed742017-04-17 11:45:04 -0700298 private NetworkScanRequestTracker mNetworkScanRequestTracker;
299
David Kelly5e06a7f2018-03-12 14:10:59 +0000300 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
301 private static final int MANUFACTURER_CODE_LENGTH = 8;
302
Derek Tan89e89d42014-07-08 17:00:10 -0700303 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700304 * Experiment flag to enable erase modem config on reset network, default value is false
305 */
306 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
307 "reset_network_erase_modem_config_enabled";
308
309 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700310 * A request object to use for transmitting data to an ICC.
311 */
312 private static final class IccAPDUArgument {
313 public int channel, cla, command, p1, p2, p3;
314 public String data;
315
316 public IccAPDUArgument(int channel, int cla, int command,
317 int p1, int p2, int p3, String data) {
318 this.channel = channel;
319 this.cla = cla;
320 this.command = command;
321 this.p1 = p1;
322 this.p2 = p2;
323 this.p3 = p3;
324 this.data = data;
325 }
326 }
327
328 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700329 * A request object to use for transmitting data to an ICC.
330 */
331 private static final class ManualNetworkSelectionArgument {
332 public OperatorInfo operatorInfo;
333 public boolean persistSelection;
334
335 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
336 this.operatorInfo = operatorInfo;
337 this.persistSelection = persistSelection;
338 }
339 }
340
341 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
343 * request after sending. The main thread will notify the request when it is complete.
344 */
345 private static final class MainThreadRequest {
346 /** The argument to use for the request */
347 public Object argument;
348 /** The result of the request that is run on the main thread */
349 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800350 // The subscriber id that this request applies to. Defaults to
351 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
352 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353
Nathan Harold92bed182018-10-12 18:16:49 -0700354 // In cases where subId is unavailable, the caller needs to specify the phone.
355 public Phone phone;
356
vagdeviaf9a5b92018-08-15 16:01:53 -0700357 public WorkSource workSource;
358
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 public MainThreadRequest(Object argument) {
360 this.argument = argument;
361 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800362
Nathan Harold92bed182018-10-12 18:16:49 -0700363 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
364 this.argument = argument;
365 if (phone != null) {
366 this.phone = phone;
367 }
368 this.workSource = workSource;
369 }
370
vagdeviaf9a5b92018-08-15 16:01:53 -0700371 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800372 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800373 if (subId != null) {
374 this.subId = subId;
375 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700376 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 }
379
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800380 private static final class IncomingThirdPartyCallArgs {
381 public final ComponentName component;
382 public final String callId;
383 public final String callerDisplayName;
384
385 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
386 String callerDisplayName) {
387 this.component = component;
388 this.callId = callId;
389 this.callerDisplayName = callerDisplayName;
390 }
391 }
392
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 /**
394 * A handler that processes messages on the main thread in the phone process. Since many
395 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
396 * inbound binder threads to the main thread in the phone process. The Binder thread
397 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
398 * on, which will be notified when the operation completes and will contain the result of the
399 * request.
400 *
401 * <p>If a MainThreadRequest object is provided in the msg.obj field,
402 * note that request.result must be set to something non-null for the calling thread to
403 * unblock.
404 */
405 private final class MainThreadHandler extends Handler {
406 @Override
407 public void handleMessage(Message msg) {
408 MainThreadRequest request;
409 Message onCompleted;
410 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800411 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800413 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414
415 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700416 case CMD_HANDLE_USSD_REQUEST: {
417 request = (MainThreadRequest) msg.obj;
418 final Phone phone = getPhoneFromRequest(request);
419 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
420 String ussdRequest = ussdObject.first;
421 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700422
Pengquan Menga1bb6272018-09-06 09:59:22 -0700423 if (!isUssdApiAllowed(request.subId)) {
424 // Carrier does not support use of this API, return failure.
425 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
426 UssdResponse response = new UssdResponse(ussdRequest, null);
427 Bundle returnData = new Bundle();
428 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
429 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700430
Pengquan Menga1bb6272018-09-06 09:59:22 -0700431 request.result = true;
432 notifyRequester(request);
433 return;
434 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700435
Pengquan Menga1bb6272018-09-06 09:59:22 -0700436 try {
437 request.result = phone != null
438 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
439 } catch (CallStateException cse) {
440 request.result = false;
441 }
442 // Wake up the requesting thread
443 notifyRequester(request);
444 break;
pkanwar32d516d2016-10-14 19:37:38 -0700445 }
446
Yorke Lee716f67e2015-06-17 15:39:16 -0700447 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700449 final Phone phone = getPhoneFromRequest(request);
450 request.result = phone != null ?
451 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
452 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700453 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800461 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700462 if (uiccCard == null) {
463 loge("iccTransmitApduLogicalChannel: No UICC");
464 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
468 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700469 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 iccArgument.channel, iccArgument.cla, iccArgument.command,
471 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700473 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 break;
475
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 ar = (AsyncResult) msg.obj;
478 request = (MainThreadRequest) ar.userObj;
479 if (ar.exception == null && ar.result != null) {
480 request.result = ar.result;
481 } else {
482 request.result = new IccIoResult(0x6F, 0, (byte[])null);
483 if (ar.result == null) {
484 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800485 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700486 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800487 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 } else {
489 loge("iccTransmitApduLogicalChannel: Unknown exception");
490 }
491 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700493 break;
494
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
496 request = (MainThreadRequest) msg.obj;
497 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800498 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 if (uiccCard == null) {
500 loge("iccTransmitApduBasicChannel: No UICC");
501 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 } else {
504 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
505 request);
506 uiccCard.iccTransmitApduBasicChannel(
507 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
508 iccArgument.p3, iccArgument.data, onCompleted);
509 }
510 break;
511
512 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
513 ar = (AsyncResult) msg.obj;
514 request = (MainThreadRequest) ar.userObj;
515 if (ar.exception == null && ar.result != null) {
516 request.result = ar.result;
517 } else {
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
519 if (ar.result == null) {
520 loge("iccTransmitApduBasicChannel: Empty response");
521 } else if (ar.exception instanceof CommandException) {
522 loge("iccTransmitApduBasicChannel: CommandException: " +
523 ar.exception);
524 } else {
525 loge("iccTransmitApduBasicChannel: Unknown exception");
526 }
527 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 break;
530
531 case CMD_EXCHANGE_SIM_IO:
532 request = (MainThreadRequest) msg.obj;
533 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800534 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 if (uiccCard == null) {
536 loge("iccExchangeSimIO: No UICC");
537 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700538 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 } else {
540 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
541 request);
542 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
543 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
544 iccArgument.data, onCompleted);
545 }
546 break;
547
548 case EVENT_EXCHANGE_SIM_IO_DONE:
549 ar = (AsyncResult) msg.obj;
550 request = (MainThreadRequest) ar.userObj;
551 if (ar.exception == null && ar.result != null) {
552 request.result = ar.result;
553 } else {
554 request.result = new IccIoResult(0x6f, 0, (byte[])null);
555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 break;
558
Derek Tan4d5e5c12014-02-04 11:54:58 -0800559 case CMD_SEND_ENVELOPE:
560 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800561 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 if (uiccCard == null) {
563 loge("sendEnvelopeWithStatus: No UICC");
564 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 } else {
567 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
568 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
569 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800570 break;
571
572 case EVENT_SEND_ENVELOPE_DONE:
573 ar = (AsyncResult) msg.obj;
574 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700575 if (ar.exception == null && ar.result != null) {
576 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
579 if (ar.result == null) {
580 loge("sendEnvelopeWithStatus: Empty response");
581 } else if (ar.exception instanceof CommandException) {
582 loge("sendEnvelopeWithStatus: CommandException: " +
583 ar.exception);
584 } else {
585 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
586 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800587 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800589 break;
590
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 case CMD_OPEN_CHANNEL:
592 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800593 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800594 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 if (uiccCard == null) {
596 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800597 request.result = new IccOpenLogicalChannelResponse(-1,
598 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 } else {
601 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800602 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
603 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 break;
606
607 case EVENT_OPEN_CHANNEL_DONE:
608 ar = (AsyncResult) msg.obj;
609 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 int[] result = (int[]) ar.result;
613 int channelId = result[0];
614 byte[] selectResponse = null;
615 if (result.length > 1) {
616 selectResponse = new byte[result.length - 1];
617 for (int i = 1; i < result.length; ++i) {
618 selectResponse[i - 1] = (byte) result[i];
619 }
620 }
621 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 if (ar.result == null) {
625 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 if (ar.exception != null) {
628 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
629 }
630
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700631 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700632 if (ar.exception instanceof CommandException) {
633 CommandException.Error error =
634 ((CommandException) (ar.exception)).getCommandError();
635 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700636 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700637 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700638 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 }
640 }
641 openChannelResp = new IccOpenLogicalChannelResponse(
642 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700644 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 break;
647
648 case CMD_CLOSE_CHANNEL:
649 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800650 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 if (uiccCard == null) {
652 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900653 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
657 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
658 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 break;
660
661 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800662 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
663 break;
664
665 case CMD_NV_READ_ITEM:
666 request = (MainThreadRequest) msg.obj;
667 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800668 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
669 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800670 break;
671
672 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 ar = (AsyncResult) msg.obj;
674 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800675 if (ar.exception == null && ar.result != null) {
676 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800678 request.result = "";
679 if (ar.result == null) {
680 loge("nvReadItem: Empty response");
681 } else if (ar.exception instanceof CommandException) {
682 loge("nvReadItem: CommandException: " +
683 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800685 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 }
687 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700688 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 break;
690
Jake Hambye994d462014-02-03 13:10:13 -0800691 case CMD_NV_WRITE_ITEM:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
694 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800695 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700696 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800697 break;
698
699 case EVENT_NV_WRITE_ITEM_DONE:
700 handleNullReturnEvent(msg, "nvWriteItem");
701 break;
702
703 case CMD_NV_WRITE_CDMA_PRL:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800706 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800707 break;
708
709 case EVENT_NV_WRITE_CDMA_PRL_DONE:
710 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
711 break;
712
chen xu6dac5ab2018-10-26 17:39:23 -0700713 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800714 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700715 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800716 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800717 break;
718
chen xu6dac5ab2018-10-26 17:39:23 -0700719 case EVENT_RESET_MODEM_CONFIG_DONE:
720 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800721 break;
722
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 case CMD_GET_PREFERRED_NETWORK_TYPE:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700726 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 break;
728
729 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
730 ar = (AsyncResult) msg.obj;
731 request = (MainThreadRequest) ar.userObj;
732 if (ar.exception == null && ar.result != null) {
733 request.result = ar.result; // Integer
734 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800735 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800736 if (ar.result == null) {
737 loge("getPreferredNetworkType: Empty response");
738 } else if (ar.exception instanceof CommandException) {
739 loge("getPreferredNetworkType: CommandException: " +
740 ar.exception);
741 } else {
742 loge("getPreferredNetworkType: Unknown exception");
743 }
744 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800746 break;
747
748 case CMD_SET_PREFERRED_NETWORK_TYPE:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
751 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700752 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800753 break;
754
755 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
756 handleNullReturnEvent(msg, "setPreferredNetworkType");
757 break;
758
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000759 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
760 request = (MainThreadRequest)msg.obj;
761 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800762 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000763 break;
764
765 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
766 ar = (AsyncResult)msg.obj;
767 request = (MainThreadRequest)ar.userObj;
768 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000770 break;
771
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800772 case CMD_SET_VOICEMAIL_NUMBER:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
775 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800776 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
777 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800778 break;
779
780 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
781 handleNullReturnEvent(msg, "setVoicemailNumber");
782 break;
783
Stuart Scott54788802015-03-30 13:18:01 -0700784 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
785 request = (MainThreadRequest) msg.obj;
786 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
787 request);
788 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
789 break;
790
791 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
792 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
793 break;
794
Shishir Agrawal302c8692015-06-19 13:49:39 -0700795 case CMD_PERFORM_NETWORK_SCAN:
796 request = (MainThreadRequest) msg.obj;
797 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
798 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
799 break;
800
801 case EVENT_PERFORM_NETWORK_SCAN_DONE:
802 ar = (AsyncResult) msg.obj;
803 request = (MainThreadRequest) ar.userObj;
804 CellNetworkScanResult cellScanResult;
805 if (ar.exception == null && ar.result != null) {
806 cellScanResult = new CellNetworkScanResult(
807 CellNetworkScanResult.STATUS_SUCCESS,
808 (List<OperatorInfo>) ar.result);
809 } else {
810 if (ar.result == null) {
811 loge("getCellNetworkScanResults: Empty response");
812 }
813 if (ar.exception != null) {
814 loge("getCellNetworkScanResults: Exception: " + ar.exception);
815 }
816 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
817 if (ar.exception instanceof CommandException) {
818 CommandException.Error error =
819 ((CommandException) (ar.exception)).getCommandError();
820 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
821 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
822 } else if (error == CommandException.Error.GENERIC_FAILURE) {
823 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
824 }
825 }
826 cellScanResult = new CellNetworkScanResult(errorCode, null);
827 }
828 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700829 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 break;
831
832 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
833 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700834 ManualNetworkSelectionArgument selArg =
835 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700836 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
837 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700838 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
839 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 break;
841
842 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700843 ar = (AsyncResult) msg.obj;
844 request = (MainThreadRequest) ar.userObj;
845 if (ar.exception == null) {
846 request.result = true;
847 } else {
848 request.result = false;
849 loge("setNetworkSelectionModeManual " + ar.exception);
850 }
851 notifyRequester(request);
852 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700853 break;
854
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700855 case CMD_GET_MODEM_ACTIVITY_INFO:
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700858 if (defaultPhone != null) {
859 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
860 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700861 break;
862
863 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
864 ar = (AsyncResult) msg.obj;
865 request = (MainThreadRequest) ar.userObj;
866 if (ar.exception == null && ar.result != null) {
867 request.result = ar.result;
868 } else {
869 if (ar.result == null) {
870 loge("queryModemActivityInfo: Empty response");
871 } else if (ar.exception instanceof CommandException) {
872 loge("queryModemActivityInfo: CommandException: " +
873 ar.exception);
874 } else {
875 loge("queryModemActivityInfo: Unknown exception");
876 }
877 }
Amit Mahajand4766222016-01-28 15:28:28 -0800878 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
879 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800880 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800881 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700882 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700883 break;
884
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 case CMD_SET_ALLOWED_CARRIERS:
886 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800887 CarrierRestrictionRules argument =
888 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800890 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 break;
892
893 case EVENT_SET_ALLOWED_CARRIERS_DONE:
894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result;
898 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800899 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
900 if (ar.exception instanceof CommandException) {
901 loge("setAllowedCarriers: CommandException: " + ar.exception);
902 CommandException.Error error =
903 ((CommandException) (ar.exception)).getCommandError();
904 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
905 request.result =
906 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
907 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700908 } else {
909 loge("setAllowedCarriers: Unknown exception");
910 }
911 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700912 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700913 break;
914
915 case CMD_GET_ALLOWED_CARRIERS:
916 request = (MainThreadRequest) msg.obj;
917 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800918 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700919 break;
920
921 case EVENT_GET_ALLOWED_CARRIERS_DONE:
922 ar = (AsyncResult) msg.obj;
923 request = (MainThreadRequest) ar.userObj;
924 if (ar.exception == null && ar.result != null) {
925 request.result = ar.result;
926 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800927 request.result = new IllegalStateException(
928 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700929 if (ar.result == null) {
930 loge("getAllowedCarriers: Empty response");
931 } else if (ar.exception instanceof CommandException) {
932 loge("getAllowedCarriers: CommandException: " +
933 ar.exception);
934 } else {
935 loge("getAllowedCarriers: Unknown exception");
936 }
937 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700938 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700939 break;
940
Nathan Haroldb3014052017-01-25 15:57:32 -0800941 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
942 ar = (AsyncResult) msg.obj;
943 request = (MainThreadRequest) ar.userObj;
944 if (ar.exception == null && ar.result != null) {
945 request.result = ar.result;
946 } else {
947 request.result = new IllegalArgumentException(
948 "Failed to retrieve Forbidden Plmns");
949 if (ar.result == null) {
950 loge("getForbiddenPlmns: Empty response");
951 } else {
952 loge("getForbiddenPlmns: Unknown exception");
953 }
954 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700955 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800956 break;
957
958 case CMD_GET_FORBIDDEN_PLMNS:
959 request = (MainThreadRequest) msg.obj;
960 uiccCard = getUiccCardFromRequest(request);
961 if (uiccCard == null) {
962 loge("getForbiddenPlmns() UiccCard is null");
963 request.result = new IllegalArgumentException(
964 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700965 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800966 break;
967 }
968 Integer appType = (Integer) request.argument;
969 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
970 if (uiccApp == null) {
971 loge("getForbiddenPlmns() no app with specified type -- "
972 + appType);
973 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700974 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800975 break;
976 } else {
977 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
978 + " specified type -- " + appType);
979 }
980 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
981 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
982 onCompleted);
983 break;
984
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000985 case CMD_SWITCH_SLOTS:
986 request = (MainThreadRequest) msg.obj;
987 int[] physicalSlots = (int[]) request.argument;
988 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
989 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
990 break;
991
992 case EVENT_SWITCH_SLOTS_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700996 notifyRequester(request);
997 break;
998 case CMD_GET_NETWORK_SELECTION_MODE:
999 request = (MainThreadRequest) msg.obj;
1000 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1001 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1002 break;
1003
1004 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1005 ar = (AsyncResult) msg.obj;
1006 request = (MainThreadRequest) ar.userObj;
1007 if (ar.exception != null) {
1008 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1009 } else {
1010 int mode = ((int[]) ar.result)[0];
1011 if (mode == 0) {
1012 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1013 } else {
1014 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1015 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001016 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001017 notifyRequester(request);
1018 break;
1019 case CMD_GET_CDMA_ROAMING_MODE:
1020 request = (MainThreadRequest) msg.obj;
1021 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1022 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1023 break;
1024 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception != null) {
1028 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1029 } else {
1030 request.result = ((int[]) ar.result)[0];
1031 }
1032 notifyRequester(request);
1033 break;
1034 case CMD_SET_CDMA_ROAMING_MODE:
1035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1037 int mode = (int) request.argument;
1038 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1039 break;
1040 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 request.result = ar.exception == null;
1044 notifyRequester(request);
1045 break;
1046 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1049 int subscriptionMode = (int) request.argument;
1050 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1051 break;
1052 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1053 ar = (AsyncResult) msg.obj;
1054 request = (MainThreadRequest) ar.userObj;
1055 request.result = ar.exception == null;
1056 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001057 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001058 case CMD_GET_ALL_CELL_INFO:
1059 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001061 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 case EVENT_GET_ALL_CELL_INFO_DONE:
1064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001066 // If a timeout occurs, the response will be null
1067 request.result = (ar.exception == null && ar.result != null)
1068 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001069 synchronized (request) {
1070 request.notifyAll();
1071 }
1072 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001073 case CMD_REQUEST_CELL_INFO_UPDATE:
1074 request = (MainThreadRequest) msg.obj;
1075 request.phone.requestCellInfoUpdate(request.workSource,
1076 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1077 break;
1078 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1079 ar = (AsyncResult) msg.obj;
1080 request = (MainThreadRequest) ar.userObj;
1081 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1082 try {
1083 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001085 cb.onError(
1086 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1087 ar.exception.getClass().getName(),
1088 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001089 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001090 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001091 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 } else {
1093 // use the result as returned
1094 cb.onCellInfo((List<CellInfo>) ar.result);
1095 }
1096 } catch (RemoteException re) {
1097 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1098 }
1099 break;
1100 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001101 request = (MainThreadRequest) msg.obj;
1102 WorkSource ws = (WorkSource) request.argument;
1103 Phone phone = getPhoneFromRequest(request);
1104 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1105 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001106 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001107 ar = (AsyncResult) msg.obj;
1108 request = (MainThreadRequest) ar.userObj;
1109 if (ar.exception == null) {
1110 request.result = ar.result;
1111 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001112 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001113 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1114 ? new CdmaCellLocation() : new GsmCellLocation();
1115 }
1116
1117 synchronized (request) {
1118 request.notifyAll();
1119 }
1120 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001121 case CMD_MODEM_REBOOT:
1122 request = (MainThreadRequest) msg.obj;
1123 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001124 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001125 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001126 case EVENT_CMD_MODEM_REBOOT_DONE:
1127 handleNullReturnEvent(msg, "rebootModem");
1128 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001129 case CMD_REQUEST_ENABLE_MODEM:
1130 request = (MainThreadRequest) msg.obj;
1131 boolean enable = (boolean) request.argument;
1132 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001133 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001134 PhoneConfigurationManager.getInstance()
1135 .enablePhone(request.phone, enable, onCompleted);
1136 break;
1137 case EVENT_ENABLE_MODEM_DONE:
1138 ar = (AsyncResult) msg.obj;
1139 request = (MainThreadRequest) ar.userObj;
1140 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001141 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001142 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001143 if ((boolean) request.result) {
1144 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1145 updateModemStateMetrics();
1146 } else {
1147 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1148 + ar.exception);
1149 }
1150 notifyRequester(request);
1151 break;
1152 case CMD_GET_MODEM_STATUS:
1153 request = (MainThreadRequest) msg.obj;
1154 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1155 PhoneConfigurationManager.getInstance()
1156 .getPhoneStatusFromModem(request.phone, onCompleted);
1157 break;
1158 case EVENT_GET_MODEM_STATUS_DONE:
1159 ar = (AsyncResult) msg.obj;
1160 request = (MainThreadRequest) ar.userObj;
1161 int id = request.phone.getPhoneId();
1162 if (ar.exception == null && ar.result != null) {
1163 request.result = ar.result;
1164 //update the cache as modem status has changed
1165 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1166 (boolean) request.result);
1167 } else {
1168 // Return true if modem status cannot be retrieved. For most cases,
1169 // modem status is on. And for older version modems, GET_MODEM_STATUS
1170 // and disable modem are not supported. Modem is always on.
1171 // TODO: this should be fixed in R to support a third
1172 // status UNKNOWN b/131631629
1173 request.result = true;
1174 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1175 + ar.exception);
1176 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001177 notifyRequester(request);
1178 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001179 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1180 ar = (AsyncResult) msg.obj;
1181 request = (MainThreadRequest) ar.userObj;
1182 if (ar.exception == null && ar.result != null) {
1183 request.result = ar.result;
1184 } else {
1185 request.result = -1;
1186 loge("Failed to set Forbidden Plmns");
1187 if (ar.result == null) {
1188 loge("setForbidenPlmns: Empty response");
1189 } else if (ar.exception != null) {
1190 loge("setForbiddenPlmns: Exception: " + ar.exception);
1191 request.result = -1;
1192 } else {
1193 loge("setForbiddenPlmns: Unknown exception");
1194 }
1195 }
1196 notifyRequester(request);
1197 break;
1198 case CMD_SET_FORBIDDEN_PLMNS:
1199 request = (MainThreadRequest) msg.obj;
1200 uiccCard = getUiccCardFromRequest(request);
1201 if (uiccCard == null) {
1202 loge("setForbiddenPlmns: UiccCard is null");
1203 request.result = -1;
1204 notifyRequester(request);
1205 break;
1206 }
1207 Pair<Integer, List<String>> setFplmnsArgs =
1208 (Pair<Integer, List<String>>) request.argument;
1209 appType = setFplmnsArgs.first;
1210 List<String> fplmns = setFplmnsArgs.second;
1211 uiccApp = uiccCard.getApplicationByType(appType);
1212 if (uiccApp == null) {
1213 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1214 request.result = -1;
1215 loge("Failed to get UICC App");
1216 notifyRequester(request);
1217 } else {
1218 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1219 ((SIMRecords) uiccApp.getIccRecords())
1220 .setForbiddenPlmns(onCompleted, fplmns);
1221 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001222 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001223 case CMD_ERASE_MODEM_CONFIG:
1224 request = (MainThreadRequest) msg.obj;
1225 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1226 defaultPhone.eraseModemConfig(onCompleted);
1227 break;
1228 case EVENT_ERASE_MODEM_CONFIG_DONE:
1229 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001230 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 default:
1232 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1233 break;
1234 }
1235 }
Jake Hambye994d462014-02-03 13:10:13 -08001236
Pengquan Menga1bb6272018-09-06 09:59:22 -07001237 private void notifyRequester(MainThreadRequest request) {
1238 synchronized (request) {
1239 request.notifyAll();
1240 }
1241 }
1242
Jake Hambye994d462014-02-03 13:10:13 -08001243 private void handleNullReturnEvent(Message msg, String command) {
1244 AsyncResult ar = (AsyncResult) msg.obj;
1245 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1246 if (ar.exception == null) {
1247 request.result = true;
1248 } else {
1249 request.result = false;
1250 if (ar.exception instanceof CommandException) {
1251 loge(command + ": CommandException: " + ar.exception);
1252 } else {
1253 loge(command + ": Unknown exception");
1254 }
1255 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001256 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 }
1259
1260 /**
1261 * Posts the specified command to be executed on the main thread,
1262 * waits for the request to complete, and returns the result.
1263 * @see #sendRequestAsync
1264 */
1265 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001266 return sendRequest(
1267 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001268 }
1269
1270 /**
1271 * Posts the specified command to be executed on the main thread,
1272 * waits for the request to complete, and returns the result.
1273 * @see #sendRequestAsync
1274 */
1275 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1276 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001277 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001278 }
1279
1280 /**
1281 * Posts the specified command to be executed on the main thread,
1282 * waits for the request to complete, and returns the result.
1283 * @see #sendRequestAsync
1284 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001285 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001286 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001287 }
1288
1289 /**
1290 * Posts the specified command to be executed on the main thread,
1291 * waits for the request to complete, and returns the result.
1292 * @see #sendRequestAsync
1293 */
Nathan Harold92bed182018-10-12 18:16:49 -07001294 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1295 return sendRequest(command, argument, subId, null, workSource);
1296 }
1297
1298 /**
1299 * Posts the specified command to be executed on the main thread,
1300 * waits for the request to complete, and returns the result.
1301 * @see #sendRequestAsync
1302 */
1303 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1304 return sendRequest(
1305 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1306 }
1307
1308 /**
1309 * Posts the specified command to be executed on the main thread,
1310 * waits for the request to complete, and returns the result.
1311 * @see #sendRequestAsync
1312 */
1313 private Object sendRequest(
1314 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1316 throw new RuntimeException("This method will deadlock if called from the main thread.");
1317 }
1318
Nathan Harold92bed182018-10-12 18:16:49 -07001319 MainThreadRequest request = null;
1320 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1321 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1322 } else if (phone != null) {
1323 request = new MainThreadRequest(argument, phone, workSource);
1324 } else {
1325 request = new MainThreadRequest(argument, subId, workSource);
1326 }
1327
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 Message msg = mMainThreadHandler.obtainMessage(command, request);
1329 msg.sendToTarget();
1330
1331 // Wait for the request to complete
1332 synchronized (request) {
1333 while (request.result == null) {
1334 try {
1335 request.wait();
1336 } catch (InterruptedException e) {
1337 // Do nothing, go back and wait until the request is complete
1338 }
1339 }
1340 }
1341 return request.result;
1342 }
1343
1344 /**
1345 * Asynchronous ("fire and forget") version of sendRequest():
1346 * Posts the specified command to be executed on the main thread, and
1347 * returns immediately.
1348 * @see #sendRequest
1349 */
1350 private void sendRequestAsync(int command) {
1351 mMainThreadHandler.sendEmptyMessage(command);
1352 }
1353
1354 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001355 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001356 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001357 */
1358 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 sendRequestAsync(command, argument, null, null);
1360 }
1361
1362 /**
1363 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1364 * @see {@link #sendRequest(int,Object)}
1365 */
1366 private void sendRequestAsync(
1367 int command, Object argument, Phone phone, WorkSource workSource) {
1368 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001369 Message msg = mMainThreadHandler.obtainMessage(command, request);
1370 msg.sendToTarget();
1371 }
1372
1373 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 * Initialize the singleton PhoneInterfaceManager instance.
1375 * This is only done once, at startup, from PhoneApp.onCreate().
1376 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001377 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 synchronized (PhoneInterfaceManager.class) {
1379 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001380 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 } else {
1382 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1383 }
1384 return sInstance;
1385 }
1386 }
1387
1388 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001389 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001390 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001392 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1394 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001395 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001396 mTelephonySharedPreferences =
1397 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001398 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001399 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001400
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001401 publish();
1402 }
1403
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001404 private Phone getDefaultPhone() {
1405 Phone thePhone = getPhone(getDefaultSubscription());
1406 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1407 }
1408
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001409 private void publish() {
1410 if (DBG) log("publish: " + this);
1411
1412 ServiceManager.addService("phone", this);
1413 }
1414
Stuart Scott584921c2015-01-15 17:10:34 -08001415 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001416 if (request.phone != null) {
1417 return request.phone;
1418 } else {
1419 return getPhoneFromSubId(request.subId);
1420 }
1421 }
1422
1423 private Phone getPhoneFromSubId(int subId) {
1424 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1425 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001426 }
1427
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001428 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1429 Phone phone = getPhoneFromRequest(request);
1430 return phone == null ? null :
1431 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1432 }
1433
Wink Saville36469e72014-06-11 15:17:00 -07001434 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001435 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001436 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001438
Naina Nallurid63128d2019-09-17 14:10:30 -07001439 private void sendEraseModemConfig(Phone phone) {
1440 if (phone != null) {
1441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1442 mApp, phone.getSubId(), "eraseModemConfig");
1443 final long identity = Binder.clearCallingIdentity();
1444 try {
1445 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1446 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1447 } finally {
1448 Binder.restoreCallingIdentity(identity);
1449 }
1450 }
1451 }
1452
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001453 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001455 }
1456
Wink Savilleb564aae2014-10-23 10:18:09 -07001457 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458 if (DBG) log("dial: " + number);
1459 // No permission check needed here: This is just a wrapper around the
1460 // ACTION_DIAL intent, which is available to any app since it puts up
1461 // the UI before it does anything.
1462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001463 final long identity = Binder.clearCallingIdentity();
1464 try {
1465 String url = createTelUrl(number);
1466 if (url == null) {
1467 return;
1468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001470 // PENDING: should we just silently fail if phone is offhook or ringing?
1471 PhoneConstants.State state = mCM.getState(subId);
1472 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1473 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1474 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1475 mApp.startActivity(intent);
1476 }
1477 } finally {
1478 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479 }
1480 }
1481
1482 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001483 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001484 }
1485
Wink Savilleb564aae2014-10-23 10:18:09 -07001486 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001487 if (DBG) log("call: " + number);
1488
1489 // This is just a wrapper around the ACTION_CALL intent, but we still
1490 // need to do a permission check since we're calling startActivity()
1491 // from the context of the phone app.
1492 enforceCallPermission();
1493
Jordan Liu1617b712019-07-10 15:06:26 -07001494 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001495 != AppOpsManager.MODE_ALLOWED) {
1496 return;
1497 }
1498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001499 final long identity = Binder.clearCallingIdentity();
1500 try {
1501 String url = createTelUrl(number);
1502 if (url == null) {
1503 return;
1504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001506 boolean isValid = false;
1507 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1508 if (slist != null) {
1509 for (SubscriptionInfo subInfoRecord : slist) {
1510 if (subInfoRecord.getSubscriptionId() == subId) {
1511 isValid = true;
1512 break;
1513 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001514 }
Wink Saville08874612014-08-31 19:19:58 -07001515 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001516 if (!isValid) {
1517 return;
1518 }
Wink Saville08874612014-08-31 19:19:58 -07001519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001520 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1521 intent.putExtra(SUBSCRIPTION_KEY, subId);
1522 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1523 mApp.startActivity(intent);
1524 } finally {
1525 Binder.restoreCallingIdentity(identity);
1526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527 }
1528
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001530 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001531 }
1532
Wink Savilleb564aae2014-10-23 10:18:09 -07001533 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001534 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001535 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1536 }
1537
1538 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001539 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001540 }
1541
Wink Savilleb564aae2014-10-23 10:18:09 -07001542 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001543 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001544 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1545 }
1546
1547 /** {@hide} */
1548 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001549 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001550 }
1551
Wink Savilleb564aae2014-10-23 10:18:09 -07001552 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001554
1555 final long identity = Binder.clearCallingIdentity();
1556 try {
1557 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1558 checkSimPin.start();
1559 return checkSimPin.unlockSim(null, pin);
1560 } finally {
1561 Binder.restoreCallingIdentity(identity);
1562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 }
1564
Wink Saville9de0f752013-10-22 19:04:03 -07001565 /** {@hide} */
1566 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001567 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001568 }
1569
Wink Savilleb564aae2014-10-23 10:18:09 -07001570 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001572
1573 final long identity = Binder.clearCallingIdentity();
1574 try {
1575 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1576 checkSimPuk.start();
1577 return checkSimPuk.unlockSim(puk, pin);
1578 } finally {
1579 Binder.restoreCallingIdentity(identity);
1580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 }
1582
1583 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001584 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001585 * a synchronous one.
1586 */
1587 private static class UnlockSim extends Thread {
1588
1589 private final IccCard mSimCard;
1590
1591 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001592 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1593 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594
1595 // For replies from SimCard interface
1596 private Handler mHandler;
1597
1598 // For async handler to identify request type
1599 private static final int SUPPLY_PIN_COMPLETE = 100;
1600
1601 public UnlockSim(IccCard simCard) {
1602 mSimCard = simCard;
1603 }
1604
1605 @Override
1606 public void run() {
1607 Looper.prepare();
1608 synchronized (UnlockSim.this) {
1609 mHandler = new Handler() {
1610 @Override
1611 public void handleMessage(Message msg) {
1612 AsyncResult ar = (AsyncResult) msg.obj;
1613 switch (msg.what) {
1614 case SUPPLY_PIN_COMPLETE:
1615 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1616 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001617 mRetryCount = msg.arg1;
1618 if (ar.exception != null) {
1619 if (ar.exception instanceof CommandException &&
1620 ((CommandException)(ar.exception)).getCommandError()
1621 == CommandException.Error.PASSWORD_INCORRECT) {
1622 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1623 } else {
1624 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1625 }
1626 } else {
1627 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 mDone = true;
1630 UnlockSim.this.notifyAll();
1631 }
1632 break;
1633 }
1634 }
1635 };
1636 UnlockSim.this.notifyAll();
1637 }
1638 Looper.loop();
1639 }
1640
1641 /*
1642 * Use PIN or PUK to unlock SIM card
1643 *
1644 * If PUK is null, unlock SIM card with PIN
1645 *
1646 * If PUK is not null, unlock SIM card with PUK and set PIN code
1647 */
Wink Saville9de0f752013-10-22 19:04:03 -07001648 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649
1650 while (mHandler == null) {
1651 try {
1652 wait();
1653 } catch (InterruptedException e) {
1654 Thread.currentThread().interrupt();
1655 }
1656 }
1657 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1658
1659 if (puk == null) {
1660 mSimCard.supplyPin(pin, callback);
1661 } else {
1662 mSimCard.supplyPuk(puk, pin, callback);
1663 }
1664
1665 while (!mDone) {
1666 try {
1667 Log.d(LOG_TAG, "wait for done");
1668 wait();
1669 } catch (InterruptedException e) {
1670 // Restore the interrupted status
1671 Thread.currentThread().interrupt();
1672 }
1673 }
1674 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001675 int[] resultArray = new int[2];
1676 resultArray[0] = mResult;
1677 resultArray[1] = mRetryCount;
1678 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 }
1680 }
1681
1682 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001683 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001684
1685 }
1686
Wink Savilleb564aae2014-10-23 10:18:09 -07001687 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 // No permission check needed here: this call is harmless, and it's
1689 // needed for the ServiceState.requestStateUpdate() call (which is
1690 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001691 final long identity = Binder.clearCallingIdentity();
1692 try {
1693 final Phone phone = getPhone(subId);
1694 if (phone != null) {
1695 phone.updateServiceLocation();
1696 }
1697 } finally {
1698 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001700 }
1701
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001702 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001703 @Override
1704 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001705 return isRadioOnWithFeature(callingPackage, null);
1706 }
1707
1708
1709 @Override
1710 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1711 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1712 callingFeatureId);
1713 }
1714
1715 @Deprecated
1716 @Override
1717 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1718 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001719 }
1720
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001721 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001722 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1723 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001725 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001726 return false;
1727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001728
1729 final long identity = Binder.clearCallingIdentity();
1730 try {
1731 return isRadioOnForSubscriber(subId);
1732 } finally {
1733 Binder.restoreCallingIdentity(identity);
1734 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001735 }
1736
1737 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001738 final long identity = Binder.clearCallingIdentity();
1739 try {
1740 final Phone phone = getPhone(subId);
1741 if (phone != null) {
1742 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1743 } else {
1744 return false;
1745 }
1746 } finally {
1747 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 }
1750
1751 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001752 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753 }
Wink Saville36469e72014-06-11 15:17:00 -07001754
Wink Savilleb564aae2014-10-23 10:18:09 -07001755 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001757
1758 final long identity = Binder.clearCallingIdentity();
1759 try {
1760 final Phone phone = getPhone(subId);
1761 if (phone != null) {
1762 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1763 }
1764 } finally {
1765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001766 }
Wink Saville36469e72014-06-11 15:17:00 -07001767 }
1768
1769 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001770 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001771 }
1772
Wink Savilleb564aae2014-10-23 10:18:09 -07001773 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001774 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001775
1776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 final Phone phone = getPhone(subId);
1779 if (phone == null) {
1780 return false;
1781 }
1782 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1783 toggleRadioOnOffForSubscriber(subId);
1784 }
1785 return true;
1786 } finally {
1787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
Wink Saville36469e72014-06-11 15:17:00 -07001790
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001791 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001792 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001793 /*
1794 * If any of the Radios are available, it will need to be
1795 * shutdown. So return true if any Radio is available.
1796 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 final long identity = Binder.clearCallingIdentity();
1798 try {
1799 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1800 Phone phone = PhoneFactory.getPhone(i);
1801 if (phone != null && phone.isRadioAvailable()) return true;
1802 }
1803 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1804 return false;
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001807 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001808 }
1809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001810 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001811 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001812 enforceModifyPermission();
1813
1814 final long identity = Binder.clearCallingIdentity();
1815 try {
1816 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1817 logv("Shutting down Phone " + i);
1818 shutdownRadioUsingPhoneId(i);
1819 }
1820 } finally {
1821 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001822 }
1823 }
1824
1825 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001826 Phone phone = PhoneFactory.getPhone(phoneId);
1827 if (phone != null && phone.isRadioAvailable()) {
1828 phone.shutdownRadio();
1829 }
1830 }
1831
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834
1835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1838 if (defaultPhone != null) {
1839 defaultPhone.setRadioPower(turnOn);
1840 return true;
1841 } else {
1842 loge("There's no default phone.");
1843 return false;
1844 }
1845 } finally {
1846 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001847 }
Wink Saville36469e72014-06-11 15:17:00 -07001848 }
1849
Wink Savilleb564aae2014-10-23 10:18:09 -07001850 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001852
1853 final long identity = Binder.clearCallingIdentity();
1854 try {
1855 final Phone phone = getPhone(subId);
1856 if (phone != null) {
1857 phone.setRadioPower(turnOn);
1858 return true;
1859 } else {
1860 return false;
1861 }
1862 } finally {
1863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001865 }
1866
Wink Saville36469e72014-06-11 15:17:00 -07001867 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001868 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 public boolean enableDataConnectivity() {
1870 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001871
1872 final long identity = Binder.clearCallingIdentity();
1873 try {
1874 int subId = mSubscriptionController.getDefaultDataSubId();
1875 final Phone phone = getPhone(subId);
1876 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001877 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001878 return true;
1879 } else {
1880 return false;
1881 }
1882 } finally {
1883 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 }
1886
Wink Saville36469e72014-06-11 15:17:00 -07001887 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 public boolean disableDataConnectivity() {
1890 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001891
1892 final long identity = Binder.clearCallingIdentity();
1893 try {
1894 int subId = mSubscriptionController.getDefaultDataSubId();
1895 final Phone phone = getPhone(subId);
1896 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001897 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898 return true;
1899 } else {
1900 return false;
1901 }
1902 } finally {
1903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001908 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001909 final long identity = Binder.clearCallingIdentity();
1910 try {
1911 final Phone phone = getPhone(subId);
1912 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001913 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001914 } else {
1915 return false;
1916 }
1917 } finally {
1918 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 }
1921
1922 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001923 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001924 }
1925
pkanwarae03a6b2016-11-06 20:37:09 -08001926 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001927 enforceCallPermission();
1928
1929 final long identity = Binder.clearCallingIdentity();
1930 try {
1931 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1932 return;
1933 }
1934 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1935 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1936 } finally {
1937 Binder.restoreCallingIdentity(identity);
1938 }
pkanwar32d516d2016-10-14 19:37:38 -07001939 };
1940
Wink Savilleb564aae2014-10-23 10:18:09 -07001941 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001943
1944 final long identity = Binder.clearCallingIdentity();
1945 try {
1946 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1947 return false;
1948 }
1949 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1950 } finally {
1951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001956 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001957 }
1958
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001959 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001960 final long identity = Binder.clearCallingIdentity();
1961 try {
1962 Phone phone = PhoneFactory.getPhone(slotIndex);
1963 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1964 PhoneConstantConversions.convertCallState(phone.getState());
1965 } finally {
1966 Binder.restoreCallingIdentity(identity);
1967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 }
1969
Sanket Padawe356d7632015-06-22 14:03:32 -07001970 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001971 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001972 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1973 }
1974
1975 @Override
1976 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001977 final long identity = Binder.clearCallingIdentity();
1978 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001979 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001980 if (phone != null) {
1981 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1982 } else {
1983 return PhoneConstantConversions.convertDataState(
1984 PhoneConstants.DataState.DISCONNECTED);
1985 }
1986 } finally {
1987 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990
Sanket Padawe356d7632015-06-22 14:03:32 -07001991 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001992 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001993 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1994 }
1995
1996 @Override
1997 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001998 final long identity = Binder.clearCallingIdentity();
1999 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002000 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002001 if (phone != null) {
2002 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2003 } else {
2004 return TelephonyManager.DATA_ACTIVITY_NONE;
2005 }
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010
2011 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002012 public Bundle getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002013 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002014 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002015
2016 LocationAccessPolicy.LocationPermissionResult locationResult =
2017 LocationAccessPolicy.checkLocationPermission(mApp,
2018 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2019 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002020 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002021 .setCallingPid(Binder.getCallingPid())
2022 .setCallingUid(Binder.getCallingUid())
2023 .setMethod("getCellLocation")
2024 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2025 .build());
2026 switch (locationResult) {
2027 case DENIED_HARD:
2028 throw new SecurityException("Not allowed to access cell location");
2029 case DENIED_SOFT:
2030 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 }
2032
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002033 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002034 final long identity = Binder.clearCallingIdentity();
2035 try {
2036 if (DBG_LOC) log("getCellLocation: is active user");
2037 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002038 int subId = mSubscriptionController.getDefaultDataSubId();
2039 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2040 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002041 return data;
2042 } finally {
2043 Binder.restoreCallingIdentity(identity);
2044 }
Svetoslav64fad262015-04-14 14:35:21 -07002045 }
2046
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002048 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2049 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002050 if (!TextUtils.isEmpty(callingPackage)) {
2051 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002052 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2053 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002054 return "";
2055 }
2056 }
2057
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002058 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2059 // registered cell info, so return a NULL country instead.
2060 final long identity = Binder.clearCallingIdentity();
2061 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002062 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2063 // Get default phone in this case.
2064 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2065 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002066 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002067 // Todo: fix this when we can get the actual cellular network info when the device
2068 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002069 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002070 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2071 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002072 return "";
2073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002074 Phone phone = PhoneFactory.getPhone(phoneId);
2075 if (phone != null) {
2076 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002077 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 if (sst != null) {
2079 LocaleTracker lt = sst.getLocaleTracker();
2080 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002081 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2082 return lt.getCurrentCountry();
2083 } else if (emergencyNumberTracker != null) {
2084 return emergencyNumberTracker.getEmergencyCountryIso();
2085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002086 }
2087 }
2088 }
2089 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002090 } finally {
2091 Binder.restoreCallingIdentity(identity);
2092 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002093 }
2094
2095 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002096 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002097 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002098 }
2099
Sanket Padawe356d7632015-06-22 14:03:32 -07002100 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002101 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 mApp.enforceCallingOrSelfPermission(
2103 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002104
2105 final long identity = Binder.clearCallingIdentity();
2106 try {
2107 final Phone phone = getPhone(subId);
2108 if (phone != null) {
2109 phone.enableLocationUpdates();
2110 }
2111 } finally {
2112 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 }
2115
2116 @Override
2117 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002118 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002119 }
2120
Sanket Padawe356d7632015-06-22 14:03:32 -07002121 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002122 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 mApp.enforceCallingOrSelfPermission(
2124 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002125
2126 final long identity = Binder.clearCallingIdentity();
2127 try {
2128 final Phone phone = getPhone(subId);
2129 if (phone != null) {
2130 phone.disableLocationUpdates();
2131 }
2132 } finally {
2133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 }
2136
Nathan Harold31d7ff32018-10-15 20:20:30 -07002137 /**
2138 * Returns the target SDK version number for a given package name.
2139 *
Nathan Haroldec184742019-07-10 17:04:16 -07002140 * This call MUST be invoked before clearing the calling UID.
2141 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002142 * @return target SDK if the package is found or INT_MAX.
2143 */
2144 private int getTargetSdk(String packageName) {
2145 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002146 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002147 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002148 if (ai != null) return ai.targetSdkVersion;
2149 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002150 loge("Failed to get package info for pkg="
2151 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002152 }
2153 return Integer.MAX_VALUE;
2154 }
2155
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 @Override
2157 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002158 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2159 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002160 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002161 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2162 throw new SecurityException(
2163 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2164 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002165
Jordan Liu1617b712019-07-10 15:06:26 -07002166 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2168 return null;
2169 }
Svetoslav64fad262015-04-14 14:35:21 -07002170
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002171 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002173 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002174 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175
Nathan Haroldf180aac2018-06-01 18:43:55 -07002176 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2177 for (CellInfo ci : info) {
2178 if (ci instanceof CellInfoGsm) {
2179 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2180 } else if (ci instanceof CellInfoWcdma) {
2181 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002184 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002187 private List<CellInfo> getCachedCellInfo() {
2188 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2189 for (Phone phone : PhoneFactory.getPhones()) {
2190 List<CellInfo> info = phone.getAllCellInfo();
2191 if (info != null) cellInfos.addAll(info);
2192 }
2193 return cellInfos;
2194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195
2196 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002197 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002198 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002199 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002200
2201 LocationAccessPolicy.LocationPermissionResult locationResult =
2202 LocationAccessPolicy.checkLocationPermission(mApp,
2203 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2204 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002205 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002206 .setCallingPid(Binder.getCallingPid())
2207 .setCallingUid(Binder.getCallingUid())
2208 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002209 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002210 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2211 .build());
2212 switch (locationResult) {
2213 case DENIED_HARD:
2214 throw new SecurityException("Not allowed to access cell info");
2215 case DENIED_SOFT:
2216 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002219 final int targetSdk = getTargetSdk(callingPackage);
2220 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2221 return getCachedCellInfo();
2222 }
2223
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002224 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002225 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002226 final long identity = Binder.clearCallingIdentity();
2227 try {
2228 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2229 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002230 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002231 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002232 if (info != null) cellInfos.addAll(info);
2233 }
2234 return cellInfos;
2235 } finally {
2236 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 }
2238 }
2239
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002240 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002241 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2242 String callingFeatureId) {
2243 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2244 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002245 }
2246
2247 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002248 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2249 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002250 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002251 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002252 }
2253
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002254 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2255 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002256 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002257 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002258
2259 LocationAccessPolicy.LocationPermissionResult locationResult =
2260 LocationAccessPolicy.checkLocationPermission(mApp,
2261 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2262 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002263 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002264 .setCallingPid(Binder.getCallingPid())
2265 .setCallingUid(Binder.getCallingUid())
2266 .setMethod("requestCellInfoUpdate")
2267 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2268 .build());
2269 switch (locationResult) {
2270 case DENIED_HARD:
2271 throw new SecurityException("Not allowed to access cell info");
2272 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002273 try {
2274 cb.onCellInfo(new ArrayList<CellInfo>());
2275 } catch (RemoteException re) {
2276 // Drop without consequences
2277 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002278 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002279 }
2280
Nathan Harolda939a962019-05-09 10:13:47 -07002281
2282 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002283 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2284
2285 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2286 }
2287
2288 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002290 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002291 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292
2293 final long identity = Binder.clearCallingIdentity();
2294 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002295 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002296 } finally {
2297 Binder.restoreCallingIdentity(identity);
2298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 }
2300
Shishir Agrawala9f32182016-04-12 12:00:16 -07002301 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002302 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002303 Phone phone = PhoneFactory.getPhone(slotIndex);
2304 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002305 return null;
2306 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002307 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002308 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002309 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002310 return null;
2311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002312
2313 final long identity = Binder.clearCallingIdentity();
2314 try {
2315 return phone.getImei();
2316 } finally {
2317 Binder.restoreCallingIdentity(identity);
2318 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002319 }
2320
2321 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002322 public String getTypeAllocationCodeForSlot(int slotIndex) {
2323 Phone phone = PhoneFactory.getPhone(slotIndex);
2324 String tac = null;
2325 if (phone != null) {
2326 String imei = phone.getImei();
2327 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2328 }
2329 return tac;
2330 }
2331
2332 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002333 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002334 Phone phone = PhoneFactory.getPhone(slotIndex);
2335 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002336 return null;
2337 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002338
Jeff Davidson913390f2018-02-23 17:11:49 -08002339 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002340 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002341 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002342 return null;
2343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344
2345 final long identity = Binder.clearCallingIdentity();
2346 try {
2347 return phone.getMeid();
2348 } finally {
2349 Binder.restoreCallingIdentity(identity);
2350 }
Jack Yu2af8d712017-03-15 17:14:14 -07002351 }
2352
2353 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002354 public String getManufacturerCodeForSlot(int slotIndex) {
2355 Phone phone = PhoneFactory.getPhone(slotIndex);
2356 String manufacturerCode = null;
2357 if (phone != null) {
2358 String meid = phone.getMeid();
2359 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2360 }
2361 return manufacturerCode;
2362 }
2363
2364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002365 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2366 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002367 Phone phone = PhoneFactory.getPhone(slotIndex);
2368 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002369 return null;
2370 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002371 int subId = phone.getSubId();
2372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002373 mApp, subId, callingPackage, callingFeatureId,
2374 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002375 return null;
2376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377
2378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 return phone.getDeviceSvn();
2381 } finally {
2382 Binder.restoreCallingIdentity(identity);
2383 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002384 }
2385
fionaxu43304da2017-11-27 22:51:16 -08002386 @Override
2387 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 final Phone phone = getPhone(subId);
2391 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2392 } finally {
2393 Binder.restoreCallingIdentity(identity);
2394 }
fionaxu43304da2017-11-27 22:51:16 -08002395 }
2396
2397 @Override
2398 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002399 final long identity = Binder.clearCallingIdentity();
2400 try {
2401 final Phone phone = getPhone(subId);
2402 return phone == null ? null : phone.getCarrierName();
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
2405 }
fionaxu43304da2017-11-27 22:51:16 -08002406 }
2407
calvinpanffe225e2018-11-01 19:43:06 +08002408 @Override
chen xu0026ca62019-03-06 15:28:50 -08002409 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002410 final long identity = Binder.clearCallingIdentity();
2411 try {
2412 final Phone phone = getPhone(subId);
2413 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002414 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002415 } finally {
2416 Binder.restoreCallingIdentity(identity);
2417 }
2418 }
2419
2420 @Override
chen xu0026ca62019-03-06 15:28:50 -08002421 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002422 final long identity = Binder.clearCallingIdentity();
2423 try {
2424 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002425 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
2429 }
2430
chen xu651eec72018-11-11 19:03:44 -08002431 @Override
chen xu864e11c2018-12-06 22:10:03 -08002432 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2433 if (!isSubscriptionMccMnc) {
2434 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2435 }
chen xu651eec72018-11-11 19:03:44 -08002436 final Phone phone = PhoneFactory.getPhone(slotIndex);
2437 if (phone == null) {
2438 return TelephonyManager.UNKNOWN_CARRIER_ID;
2439 }
2440 final long identity = Binder.clearCallingIdentity();
2441 try {
2442 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
2445 }
2446 }
2447
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 //
2449 // Internal helper methods.
2450 //
2451
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002452 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2454 *
2455 * @throws SecurityException if the caller does not have the required permission
2456 */
2457 private void enforceModifyPermission() {
2458 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2459 }
2460
Shuo Qian3b6ee772019-11-13 17:43:31 -08002461 private void enforceActiveEmergencySessionPermission() {
2462 mApp.enforceCallingOrSelfPermission(
2463 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2464 }
2465
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 /**
2467 * Make sure the caller has the CALL_PHONE permission.
2468 *
2469 * @throws SecurityException if the caller does not have the required permission
2470 */
2471 private void enforceCallPermission() {
2472 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2473 }
2474
paulhu5a773602019-08-23 19:17:33 +08002475 private void enforceSettingsPermission() {
2476 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002477 }
2478
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 private String createTelUrl(String number) {
2480 if (TextUtils.isEmpty(number)) {
2481 return null;
2482 }
2483
Jake Hambye994d462014-02-03 13:10:13 -08002484 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
Ihab Awadf9e92732013-12-05 18:02:52 -08002487 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2489 }
2490
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002491 private static void logv(String msg) {
2492 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2493 }
2494
Ihab Awadf9e92732013-12-05 18:02:52 -08002495 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2497 }
2498
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002499 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002501 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002502 }
2503
Sanket Padawe356d7632015-06-22 14:03:32 -07002504 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002505 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 final Phone phone = PhoneFactory.getPhone(slotIndex);
2509 if (phone == null) {
2510 return PhoneConstants.PHONE_TYPE_NONE;
2511 } else {
2512 return phone.getPhoneType();
2513 }
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
2519 /**
2520 * Returns the CDMA ERI icon index to display
2521 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002522 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002523 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2524 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2525 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002526 }
2527
Sanket Padawe356d7632015-06-22 14:03:32 -07002528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002529 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2530 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002532 mApp, subId, callingPackage, callingFeatureId,
2533 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002534 return -1;
2535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002536
2537 final long identity = Binder.clearCallingIdentity();
2538 try {
2539 final Phone phone = getPhone(subId);
2540 if (phone != null) {
2541 return phone.getCdmaEriIconIndex();
2542 } else {
2543 return -1;
2544 }
2545 } finally {
2546 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002548 }
2549
2550 /**
2551 * Returns the CDMA ERI icon mode,
2552 * 0 - ON
2553 * 1 - FLASHING
2554 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002555 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002556 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2557 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2558 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002559 }
2560
Sanket Padawe356d7632015-06-22 14:03:32 -07002561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002562 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2563 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002565 mApp, subId, callingPackage, callingFeatureId,
2566 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002567 return -1;
2568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 final Phone phone = getPhone(subId);
2573 if (phone != null) {
2574 return phone.getCdmaEriIconMode();
2575 } else {
2576 return -1;
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 }
2582
2583 /**
2584 * Returns the CDMA ERI text,
2585 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002586 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002587 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2588 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2589 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002590 }
2591
Sanket Padawe356d7632015-06-22 14:03:32 -07002592 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002593 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2594 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002596 mApp, subId, callingPackage, callingFeatureId,
2597 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002598 return null;
2599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600
2601 final long identity = Binder.clearCallingIdentity();
2602 try {
2603 final Phone phone = getPhone(subId);
2604 if (phone != null) {
2605 return phone.getCdmaEriText();
2606 } else {
2607 return null;
2608 }
2609 } finally {
2610 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 }
2613
2614 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002615 * Returns the CDMA MDN.
2616 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002617 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002618 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2620 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621
2622 final long identity = Binder.clearCallingIdentity();
2623 try {
2624 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002625 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 return phone.getLine1Number();
2627 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002628 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629 return null;
2630 }
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002633 }
2634 }
2635
2636 /**
2637 * Returns the CDMA MIN.
2638 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002639 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002640 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2642 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643
2644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 final Phone phone = getPhone(subId);
2647 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2648 return phone.getCdmaMin();
2649 } else {
2650 return null;
2651 }
2652 } finally {
2653 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002654 }
2655 }
2656
Hall Liud892bec2018-11-30 14:51:45 -08002657 @Override
2658 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2659 INumberVerificationCallback callback, String callingPackage) {
2660 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2661 != PERMISSION_GRANTED) {
2662 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2663 }
2664 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2665
2666 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2667 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2668 throw new SecurityException("Calling package must be configured in the device config");
2669 }
2670
2671 if (range == null) {
2672 throw new NullPointerException("Range must be non-null");
2673 }
2674
2675 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002676 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002677
2678 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2679 }
2680
Junda Liuca05d5d2014-08-14 22:36:34 -07002681 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 * Returns true if CDMA provisioning needs to run.
2683 */
2684 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685 final long identity = Binder.clearCallingIdentity();
2686 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002687 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 } finally {
2689 Binder.restoreCallingIdentity(identity);
2690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 }
2692
2693 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002694 * Sets the voice mail number of a given subId.
2695 */
2696 @Override
2697 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002698 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2699 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700
2701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2704 new Pair<String, String>(alphaTag, number), new Integer(subId));
2705 return success;
2706 } finally {
2707 Binder.restoreCallingIdentity(identity);
2708 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002709 }
2710
Ta-wei Yen87c49842016-05-13 21:19:52 -07002711 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002712 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2713 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002714 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2715 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002716 if (!TextUtils.equals(callingPackage, systemDialer)) {
2717 throw new SecurityException("caller must be system dialer");
2718 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719
2720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2723 if (phoneAccountHandle == null) {
2724 return null;
2725 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002726 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 } finally {
2728 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002729 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002730 }
2731
2732 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002733 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2734 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002735 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002737 mApp, subId, callingPackage, callingFeatureId,
2738 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002739 return null;
2740 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002742 final long identity = Binder.clearCallingIdentity();
2743 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002744 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002745 } finally {
2746 Binder.restoreCallingIdentity(identity);
2747 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002748 }
2749
2750 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002751 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2752 VisualVoicemailSmsFilterSettings settings) {
2753 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754
2755 final long identity = Binder.clearCallingIdentity();
2756 try {
2757 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002758 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759 } finally {
2760 Binder.restoreCallingIdentity(identity);
2761 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002762 }
2763
2764 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002765 public void disableVisualVoicemailSmsFilter(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 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
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 Yenb6929602016-05-24 15:48:27 -07002778 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2779 String callingPackage, int subId) {
2780 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002785 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 } finally {
2787 Binder.restoreCallingIdentity(identity);
2788 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002789 }
2790
2791 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002792 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002793 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002794
2795 final long identity = Binder.clearCallingIdentity();
2796 try {
2797 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002798 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799 } finally {
2800 Binder.restoreCallingIdentity(identity);
2801 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002802 }
2803
2804 @Override
2805 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2806 String number, int port, String text, PendingIntent sentIntent) {
2807 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002808 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002809 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002810 SmsController smsController = PhoneFactory.getSmsController();
2811 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2812 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002813 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002814
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002815 /**
fionaxu0152e512016-11-14 13:36:14 -08002816 * Sets the voice activation state of a given subId.
2817 */
2818 @Override
2819 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2821 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822
2823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 final Phone phone = getPhone(subId);
2826 if (phone != null) {
2827 phone.setVoiceActivationState(activationState);
2828 } else {
2829 loge("setVoiceActivationState fails with invalid subId: " + subId);
2830 }
2831 } finally {
2832 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002833 }
2834 }
2835
2836 /**
2837 * Sets the data activation state of a given subId.
2838 */
2839 @Override
2840 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2842 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002843
2844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 final Phone phone = getPhone(subId);
2847 if (phone != null) {
2848 phone.setDataActivationState(activationState);
2849 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002850 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 }
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002854 }
2855 }
2856
2857 /**
2858 * Returns the voice activation state of a given subId.
2859 */
2860 @Override
2861 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002862 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863
fionaxu0152e512016-11-14 13:36:14 -08002864 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 if (phone != null) {
2868 return phone.getVoiceActivationState();
2869 } else {
2870 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2871 }
2872 } finally {
2873 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002874 }
2875 }
2876
2877 /**
2878 * Returns the data activation state of a given subId.
2879 */
2880 @Override
2881 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002882 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002883
fionaxu0152e512016-11-14 13:36:14 -08002884 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 if (phone != null) {
2888 return phone.getDataActivationState();
2889 } else {
2890 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2891 }
2892 } finally {
2893 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002894 }
2895 }
2896
2897 /**
Wink Saville36469e72014-06-11 15:17:00 -07002898 * Returns the unread count of voicemails for a subId
2899 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002900 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002901 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2902 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002904 mApp, subId, callingPackage, callingFeatureId,
2905 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002906 return 0;
2907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908 final long identity = Binder.clearCallingIdentity();
2909 try {
2910 final Phone phone = getPhone(subId);
2911 if (phone != null) {
2912 return phone.getVoiceMessageCount();
2913 } else {
2914 return 0;
2915 }
2916 } finally {
2917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002919 }
2920
2921 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002922 * returns true, if the device is in a state where both voice and data
2923 * are supported simultaneously. This can change based on location or network condition.
2924 */
2925 @Override
2926 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 final Phone phone = getPhone(subId);
2930 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2931 } finally {
2932 Binder.restoreCallingIdentity(identity);
2933 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002934 }
2935
2936 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002937 * Send the dialer code if called from the current default dialer or the caller has
2938 * carrier privilege.
2939 * @param inputCode The dialer code to send
2940 */
2941 @Override
2942 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002943 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002944 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002945 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2946 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002947 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002948 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002949 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002954 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002955 } finally {
2956 Binder.restoreCallingIdentity(identity);
2957 }
fionaxu235cc5e2017-03-06 22:25:57 -08002958 }
2959
Pengquan Menga1bb6272018-09-06 09:59:22 -07002960 @Override
2961 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002962 if (!isActiveSubscription(subId)) {
2963 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2964 }
2965
Pengquan Menga1bb6272018-09-06 09:59:22 -07002966 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2967 }
2968
Brad Ebinger35c841c2018-10-01 10:40:55 -07002969 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002970 public boolean isInEmergencySmsMode() {
2971 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 for (Phone phone : PhoneFactory.getPhones()) {
2975 if (phone.isInEmergencySmsMode()) {
2976 return true;
2977 }
2978 }
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 return false;
2983 }
2984
2985 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002986 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2987 throws RemoteException {
2988 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002989 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2990 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2991 "IMS not available on device.");
2992 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002993 final long token = Binder.clearCallingIdentity();
2994 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002995 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002996 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002997 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002998 } catch (ImsException e) {
2999 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003000 } finally {
3001 Binder.restoreCallingIdentity(token);
3002 }
3003 }
3004
3005 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003006 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
3007 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003008 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3009 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3010 }
Meng Wangafbc5852019-09-19 17:37:13 -07003011 final long token = Binder.clearCallingIdentity();
3012 try {
3013 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3014 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3015 .removeRegistrationCallbackForSubscription(c, subId);
3016 } catch (ImsException e) {
3017 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3018 + "is inactive, ignoring unregister.");
3019 // If the subscription is no longer active, just return, since the callback
3020 // will already have been removed internally.
3021 } finally {
3022 Binder.restoreCallingIdentity(token);
3023 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003024 }
3025
Brad Ebingera34a6c22019-10-22 17:36:18 -07003026 /**
3027 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3028 */
3029 @Override
3030 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3031 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3032 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3033 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3034 "IMS not available on device.");
3035 }
3036 final long token = Binder.clearCallingIdentity();
3037 try {
3038 Phone phone = getPhone(subId);
3039 if (phone == null) {
3040 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3041 + subId + "'");
3042 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3043 }
3044 phone.getImsRegistrationState(regState -> {
3045 try {
3046 consumer.accept((regState == null)
3047 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3048 } catch (RemoteException e) {
3049 // Ignore if the remote process is no longer available to call back.
3050 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3051 }
3052 });
3053 } finally {
3054 Binder.restoreCallingIdentity(token);
3055 }
3056 }
3057
3058 /**
3059 * Get the transport type for the IMS service registration state.
3060 */
3061 @Override
3062 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3063 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3064 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3065 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3066 "IMS not available on device.");
3067 }
3068 final long token = Binder.clearCallingIdentity();
3069 try {
3070 Phone phone = getPhone(subId);
3071 if (phone == null) {
3072 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3073 + subId + "'");
3074 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3075 }
3076 phone.getImsRegistrationTech(regTech -> {
3077 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3078 int regTechConverted = (regTech == null)
3079 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3080 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3081 regTechConverted);
3082 try {
3083 consumer.accept(regTechConverted);
3084 } catch (RemoteException e) {
3085 // Ignore if the remote process is no longer available to call back.
3086 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3087 }
3088 });
3089 } finally {
3090 Binder.restoreCallingIdentity(token);
3091 }
3092 }
3093
Brad Ebinger35c841c2018-10-01 10:40:55 -07003094 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003095 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3096 throws RemoteException {
3097 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003098 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3099 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3100 "IMS not available on device.");
3101 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3103 final long token = Binder.clearCallingIdentity();
3104 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003105 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003106 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003107 } catch (ImsException e) {
3108 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003109 } finally {
3110 Binder.restoreCallingIdentity(token);
3111 }
3112 }
3113
3114 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003115 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3116 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003117 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3118 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3119 }
Meng Wangafbc5852019-09-19 17:37:13 -07003120
3121 final long token = Binder.clearCallingIdentity();
3122 try {
3123 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3124 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003125 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003126 } catch (ImsException e) {
3127 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3128 + "is inactive, ignoring unregister.");
3129 // If the subscription is no longer active, just return, since the callback
3130 // will already have been removed internally.
3131 } finally {
3132 Binder.restoreCallingIdentity(token);
3133 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003134 }
3135
3136 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003137 public boolean isCapable(int subId, int capability, int regTech) {
3138 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003139 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3140 final long token = Binder.clearCallingIdentity();
3141 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003142 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003143 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003144 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3146 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003147 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003148 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3149 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003150 } finally {
3151 Binder.restoreCallingIdentity(token);
3152 }
3153 }
3154
3155 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003156 public boolean isAvailable(int subId, int capability, int regTech) {
3157 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003158 final long token = Binder.clearCallingIdentity();
3159 try {
3160 Phone phone = getPhone(subId);
3161 if (phone == null) return false;
3162 return phone.isImsCapabilityAvailable(capability, regTech);
3163 } finally {
3164 Binder.restoreCallingIdentity(token);
3165 }
3166 }
3167
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003168 /**
3169 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3170 * subscription.
3171 * @param subId The subscription to use to check the configuration.
3172 * @param callback The callback that will be used to send the result.
3173 * @param capability The MmTelFeature capability that will be used to send the result.
3174 * @param transportType The transport type of the MmTelFeature capability.
3175 */
3176 @Override
3177 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3178 int transportType) {
3179 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3180 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3181 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3182 "IMS not available on device.");
3183 }
3184 final long token = Binder.clearCallingIdentity();
3185 try {
3186 int slotId = getSlotIndex(subId);
3187 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3188 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3189 + subId + "'");
3190 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3191 }
3192 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3193 transportType, aBoolean -> {
3194 try {
3195 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3196 } catch (RemoteException e) {
3197 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3198 + "running. Ignore");
3199 }
3200 });
3201 } finally {
3202 Binder.restoreCallingIdentity(token);
3203 }
3204 }
3205
Brad Ebinger35c841c2018-10-01 10:40:55 -07003206 @Override
3207 public boolean isAdvancedCallingSettingEnabled(int subId) {
3208 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3209 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3210 final long token = Binder.clearCallingIdentity();
3211 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003212 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003213 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003214 } catch (ImsException e) {
3215 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003216 } finally {
3217 Binder.restoreCallingIdentity(token);
3218 }
3219 }
3220
3221 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003222 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003224 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003225 final long identity = Binder.clearCallingIdentity();
3226 try {
3227 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003228 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003229 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003230 } 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 Ebinger9878b0b2018-11-08 17:43:22 -08003238 public boolean isVtSettingEnabled(int subId) {
3239 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003243 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3244 } catch (ImsException e) {
3245 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003246 } finally {
3247 Binder.restoreCallingIdentity(identity);
3248 }
3249 }
3250
3251 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003252 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003254 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 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 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003259 } catch (ImsException e) {
3260 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003261 } finally {
3262 Binder.restoreCallingIdentity(identity);
3263 }
3264 }
3265
3266 @Override
3267 public boolean isVoWiFiSettingEnabled(int subId) {
3268 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3269 final long identity = Binder.clearCallingIdentity();
3270 try {
3271 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003272 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003274 } catch (ImsException e) {
3275 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003276 } finally {
3277 Binder.restoreCallingIdentity(identity);
3278 }
3279 }
3280
3281 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003282 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003284 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003285 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 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003289 } catch (ImsException e) {
3290 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003291 } finally {
3292 Binder.restoreCallingIdentity(identity);
3293 }
3294 }
3295
3296 @Override
3297 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3298 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003302 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003303 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003304 } catch (ImsException e) {
3305 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003306 } finally {
3307 Binder.restoreCallingIdentity(identity);
3308 }
3309 }
3310
3311 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003312 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003314 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003315 final long identity = Binder.clearCallingIdentity();
3316 try {
3317 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003318 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003319 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003320 } catch (ImsException e) {
3321 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
3325 }
3326
3327 @Override
3328 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3330 "setVoWiFiNonPersistent");
3331 final long identity = Binder.clearCallingIdentity();
3332 try {
3333 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003334 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003335 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003336 } catch (ImsException e) {
3337 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003338 } finally {
3339 Binder.restoreCallingIdentity(identity);
3340 }
3341 }
3342
3343 @Override
3344 public int getVoWiFiModeSetting(int subId) {
3345 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3346 final long identity = Binder.clearCallingIdentity();
3347 try {
3348 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003349 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003350 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003351 } catch (ImsException e) {
3352 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003353 } finally {
3354 Binder.restoreCallingIdentity(identity);
3355 }
3356 }
3357
3358 @Override
3359 public void setVoWiFiModeSetting(int subId, int mode) {
3360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3361 "setVoWiFiModeSetting");
3362 final long identity = Binder.clearCallingIdentity();
3363 try {
3364 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003365 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003367 } catch (ImsException e) {
3368 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003369 } finally {
3370 Binder.restoreCallingIdentity(identity);
3371 }
3372 }
3373
3374 @Override
3375 public int getVoWiFiRoamingModeSetting(int subId) {
3376 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3377 final long identity = Binder.clearCallingIdentity();
3378 try {
3379 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003380 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003382 } catch (ImsException e) {
3383 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003384 } finally {
3385 Binder.restoreCallingIdentity(identity);
3386 }
3387 }
3388
3389 @Override
3390 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3392 "setVoWiFiRoamingModeSetting");
3393 final long identity = Binder.clearCallingIdentity();
3394 try {
3395 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003396 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003397 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003398 } catch (ImsException e) {
3399 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
3403 }
3404
3405 @Override
3406 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3408 "setRttCapabilityEnabled");
3409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003412 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3413 } catch (ImsException e) {
3414 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003415 } finally {
3416 Binder.restoreCallingIdentity(identity);
3417 }
3418 }
3419
3420 @Override
3421 public boolean isTtyOverVolteEnabled(int subId) {
3422 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3423 final long identity = Binder.clearCallingIdentity();
3424 try {
3425 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003426 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003427 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003428 } catch (ImsException e) {
3429 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003430 } finally {
3431 Binder.restoreCallingIdentity(identity);
3432 }
3433 }
3434
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003435 @Override
3436 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3437 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003441 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003442 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003443 } catch (ImsException e) {
3444 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003445 } finally {
3446 Binder.restoreCallingIdentity(identity);
3447 }
3448 }
3449
3450 @Override
3451 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3452 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3453 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003454 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3455 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3456 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003457 try {
3458 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003459 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003460 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003461 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003462 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3463 + "is inactive, ignoring unregister.");
3464 // If the subscription is no longer active, just return, since the callback will already
3465 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003466 } finally {
3467 Binder.restoreCallingIdentity(identity);
3468 }
3469 }
3470
3471 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003472 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3473 boolean isProvisioned) {
3474 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3475 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3476 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3477 }
3478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3479 "setProvisioningStatusForCapability");
3480 final long identity = Binder.clearCallingIdentity();
3481 try {
3482 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3483 Phone phone = getPhone(subId);
3484 if (phone == null) {
3485 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3486 + subId);
3487 return;
3488 }
3489 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3490 return;
3491 }
3492
3493 // this capability requires provisioning, route to the correct API.
3494 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3495 switch (capability) {
3496 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3497 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3498 ims.setVolteProvisioned(isProvisioned);
3499 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3500 ims.setWfcProvisioned(isProvisioned);
3501 }
3502 break;
3503 }
3504 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3505 // There is currently no difference in VT provisioning type.
3506 ims.setVtProvisioned(isProvisioned);
3507 break;
3508 }
3509 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3510 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3511 // change the capability of the feature instead if needed.
3512 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3513 == isProvisioned) {
3514 // No change in provisioning.
3515 return;
3516 }
3517 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3518 try {
3519 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003520 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003521 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3522 + ", Exception" + e.getMessage());
3523 }
3524 break;
3525 }
3526 default: {
3527 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3528 + capability + "', which does not require provisioning.");
3529 }
3530 }
3531
3532 } finally {
3533 Binder.restoreCallingIdentity(identity);
3534 }
3535 }
3536
3537 @Override
3538 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3539 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3540 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3541 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3542 }
3543 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3547 Phone phone = getPhone(subId);
3548 if (phone == null) {
3549 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3550 + subId);
3551 // We will fail with "true" as the provisioning status because this is the default
3552 // if we do not require provisioning.
3553 return true;
3554 }
3555
3556 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3557 return true;
3558 }
3559
3560 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3561 switch (capability) {
3562 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3563 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3564 return ims.isVolteProvisionedOnDevice();
3565 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3566 return ims.isWfcProvisionedOnDevice();
3567 }
3568 // This should never happen, since we are checking tech above to make sure it
3569 // is either LTE or IWLAN.
3570 throw new IllegalArgumentException("Invalid radio technology for voice "
3571 + "capability.");
3572 }
3573 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3574 // There is currently no difference in VT provisioning type.
3575 return ims.isVtProvisionedOnDevice();
3576 }
3577 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3578 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3579 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3580 }
3581 default: {
3582 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3583 + capability + "', which does not require provisioning.");
3584 }
3585 }
3586
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
3589 }
3590 }
3591
3592 @Override
3593 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3594 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3595 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3596 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3597 }
3598 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3599 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3600 return (provisionedBits & capability) > 0;
3601 }
3602
3603 @Override
3604 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3605 boolean isProvisioned) {
3606 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3607 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3608 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3609 }
3610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3611 "setProvisioningStatusForCapability");
3612 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3613 // If the current provisioning status for capability already matches isProvisioned,
3614 // do nothing.
3615 if (((provisionedBits & capability) > 0) == isProvisioned) {
3616 return;
3617 }
3618 if (isProvisioned) {
3619 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3620 } else {
3621 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3622 }
3623 }
3624
3625 /**
3626 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3627 * technology. The bitfield should mirror the bitfield defined by
3628 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3629 */
3630 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3631 String key = getMmTelProvisioningKey(subId, tech);
3632 // Default is no capabilities are provisioned.
3633 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3634 }
3635
3636 /**
3637 * Sets the MmTel capability provisioning bitfield (defined by
3638 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3639 * technology specified.
3640 *
3641 * Note: This is a synchronous command and should not be called on UI thread.
3642 */
3643 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3644 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3645 String key = getMmTelProvisioningKey(subId, tech);
3646 editor.putInt(key, newField);
3647 editor.commit();
3648 }
3649
3650 private static String getMmTelProvisioningKey(int subId, int tech) {
3651 // resulting key is provision_ims_mmtel_{subId}_{tech}
3652 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3653 }
3654
3655 /**
3656 * Query CarrierConfig to see if the specified capability requires provisioning for the
3657 * carrier associated with the subscription id.
3658 */
3659 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3660 int capability) {
3661 CarrierConfigManager configManager = new CarrierConfigManager(context);
3662 PersistableBundle c = configManager.getConfigForSubId(subId);
3663 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003664 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003665 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3666 false);
3667 boolean requireVoiceVtProvisioning = c.getBoolean(
3668 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3669
3670 // First check to make sure that the capability requires provisioning.
3671 switch (capability) {
3672 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3673 // intentional fallthrough
3674 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3675 if (requireVoiceVtProvisioning) {
3676 // Voice and Video requires provisioning
3677 return true;
3678 }
3679 break;
3680 }
3681 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3682 if (requireUtProvisioning) {
3683 // UT requires provisioning
3684 return true;
3685 }
3686 break;
3687 }
3688 }
3689 return false;
3690 }
3691
3692 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003693 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003694 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3695 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3696 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003697 enforceReadPrivilegedPermission("getImsProvisioningInt");
3698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003701 int slotId = getSlotIndex(subId);
3702 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3703 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3704 + subId + "' for key:" + key);
3705 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3706 }
3707 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003708 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003709 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3710 + subId + "' for key:" + key);
3711 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
3715 }
3716
3717 @Override
3718 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003719 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3720 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3721 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003722 enforceReadPrivilegedPermission("getImsProvisioningString");
3723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003726 int slotId = getSlotIndex(subId);
3727 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3728 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3729 + subId + "' for key:" + key);
3730 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3731 }
3732 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003733 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003734 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3735 + subId + "' for key:" + key);
3736 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
3740 }
3741
3742 @Override
3743 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003744 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3745 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3746 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3748 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003749 final long identity = Binder.clearCallingIdentity();
3750 try {
3751 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003752 int slotId = getSlotIndex(subId);
3753 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3754 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3755 + subId + "' for key:" + key);
3756 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3757 }
3758 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003759 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003760 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3761 + "' for key:" + key);
3762 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003763 } finally {
3764 Binder.restoreCallingIdentity(identity);
3765 }
3766 }
3767
3768 @Override
3769 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003770 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3771 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3772 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3774 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003775 final long identity = Binder.clearCallingIdentity();
3776 try {
3777 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003778 int slotId = getSlotIndex(subId);
3779 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3780 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3781 + subId + "' for key:" + key);
3782 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3783 }
3784 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003785 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003786 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3787 + "' for key:" + key);
3788 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003789 } finally {
3790 Binder.restoreCallingIdentity(identity);
3791 }
3792 }
3793
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003794 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003795 int slotId = SubscriptionManager.getSlotIndex(subId);
3796 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003797 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3798 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003799 }
3800 return slotId;
3801 }
3802
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003803 private int getSlotIndex(int subId) {
3804 int slotId = SubscriptionManager.getSlotIndex(subId);
3805 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3806 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3807 }
3808 return slotId;
3809 }
3810
Wink Saville36469e72014-06-11 15:17:00 -07003811 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003812 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003813 */
3814 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003815 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3816 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003817 final int targetSdk = getTargetSdk(callingPackage);
3818 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003819 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003820 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003821 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003822 mApp, subId, callingPackage, callingFeatureId,
3823 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003824 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3825 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 final long identity = Binder.clearCallingIdentity();
3828 try {
3829 final Phone phone = getPhone(subId);
3830 if (phone != null) {
3831 return phone.getServiceState().getDataNetworkType();
3832 } else {
3833 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3834 }
3835 } finally {
3836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003838 }
3839
3840 /**
3841 * Returns the data network type
3842 */
3843 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003844 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3845 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3846 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003847 }
3848
3849 /**
3850 * Returns the data network type for a subId
3851 */
3852 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003853 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3854 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003856 mApp, subId, callingPackage, callingFeatureId,
3857 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003858 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3859 }
3860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 final Phone phone = getPhone(subId);
3864 if (phone != null) {
3865 return phone.getServiceState().getDataNetworkType();
3866 } else {
3867 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3868 }
3869 } finally {
3870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003872 }
3873
3874 /**
Wink Saville36469e72014-06-11 15:17:00 -07003875 * Returns the Voice network type for a subId
3876 */
3877 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003878 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3879 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003880 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003881 mApp, subId, callingPackage, callingFeatureId,
3882 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003883 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3884 }
3885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886 final long identity = Binder.clearCallingIdentity();
3887 try {
3888 final Phone phone = getPhone(subId);
3889 if (phone != null) {
3890 return phone.getServiceState().getVoiceNetworkType();
3891 } else {
3892 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3893 }
3894 } finally {
3895 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003897 }
3898
3899 /**
3900 * @return true if a ICC card is present
3901 */
3902 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003903 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003904 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3905 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003906 }
3907
3908 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003909 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003910 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003911 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003912 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 final Phone phone = PhoneFactory.getPhone(slotIndex);
3916 if (phone != null) {
3917 return phone.getIccCard().hasIccCard();
3918 } else {
3919 return false;
3920 }
3921 } finally {
3922 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003924 }
3925
3926 /**
3927 * Return if the current radio is LTE on CDMA. This
3928 * is a tri-state return value as for a period of time
3929 * the mode may be unknown.
3930 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003931 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003932 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003933 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003934 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003935 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003936 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3937 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3938 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003939 }
3940
Sanket Padawe356d7632015-06-22 14:03:32 -07003941 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003942 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3943 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003945 mApp, subId, callingPackage, callingFeatureId,
3946 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003947 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3948 }
3949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003950 final long identity = Binder.clearCallingIdentity();
3951 try {
3952 final Phone phone = getPhone(subId);
3953 if (phone == null) {
3954 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3955 } else {
3956 return phone.getLteOnCdmaMode();
3957 }
3958 } finally {
3959 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003960 }
Wink Saville36469e72014-06-11 15:17:00 -07003961 }
3962
Wink Saville36469e72014-06-11 15:17:00 -07003963 /**
3964 * {@hide}
3965 * Returns Default subId, 0 in the case of single standby.
3966 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003967 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003968 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003969 }
3970
Shishir Agrawala9f32182016-04-12 12:00:16 -07003971 private int getSlotForDefaultSubscription() {
3972 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3973 }
3974
Wink Savilleb564aae2014-10-23 10:18:09 -07003975 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003976 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003977 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003978
Pengquan Menge92a50d2018-09-21 15:54:48 -07003979 private boolean isActiveSubscription(int subId) {
3980 return mSubscriptionController.isActiveSubId(subId);
3981 }
3982
Ihab Awadf2177b72013-11-25 13:33:23 -08003983 /**
3984 * @see android.telephony.TelephonyManager.WifiCallingChoices
3985 */
3986 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987 final long identity = Binder.clearCallingIdentity();
3988 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003989 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003990 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3991 getWhenToMakeWifiCallsDefaultPreference());
3992 } finally {
3993 Binder.restoreCallingIdentity(identity);
3994 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003995 }
3996
3997 /**
3998 * @see android.telephony.TelephonyManager.WifiCallingChoices
3999 */
4000 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004001 final long identity = Binder.clearCallingIdentity();
4002 try {
4003 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004004 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4006 } finally {
4007 Binder.restoreCallingIdentity(identity);
4008 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004009 }
4010
Sailesh Nepald1e68152013-12-12 19:08:02 -08004011 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004012 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004013 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004014 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004015
Jordan Liu4c733742019-02-28 12:03:40 -08004016 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4017 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4018 if (phoneId == -1) {
4019 throw new IllegalArgumentException("Given slot index: " + slotIndex
4020 + " does not correspond to an active phone");
4021 }
4022 return PhoneFactory.getPhone(phoneId);
4023 }
4024
Shishir Agrawal566b7612013-10-28 14:41:00 -07004025 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004026 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4027 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4029 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004031 if (DBG) {
4032 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4033 }
4034 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4035 p2);
4036 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004037
Jordan Liu4c733742019-02-28 12:03:40 -08004038
4039 @Override
4040 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4041 int slotIndex, String callingPackage, String aid, int p2) {
4042 enforceModifyPermission();
4043 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4044 if (DBG) {
4045 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4046 }
4047 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4048 callingPackage, aid, p2);
4049 }
4050
4051 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4052 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 if (TextUtils.equals(ISDR_AID, aid)) {
4056 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004057 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4058 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004059 if (bestComponent == null
4060 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4061 loge("The calling package is not allowed to access ISD-R.");
4062 throw new SecurityException(
4063 "The calling package is not allowed to access ISD-R.");
4064 }
Derek Tan740e1672017-06-27 14:56:27 -07004065 }
Derek Tan740e1672017-06-27 14:56:27 -07004066
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004067 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004068 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4069 null /* workSource */);
4070 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004071 return response;
4072 } finally {
4073 Binder.restoreCallingIdentity(identity);
4074 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004075 }
4076
4077 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004078 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4080 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004081 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4082 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4083 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004084
Jordan Liu4c733742019-02-28 12:03:40 -08004085 @Override
4086 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4087 enforceModifyPermission();
4088 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4089 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4090 channel);
4091 }
4092
4093 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094 final long identity = Binder.clearCallingIdentity();
4095 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096 if (channel < 0) {
4097 return false;
4098 }
Jordan Liu4c733742019-02-28 12:03:40 -08004099 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4100 null /* workSource */);
4101 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004102 return success;
4103 } finally {
4104 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004105 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004106 }
4107
4108 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004109 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004110 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4112 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004113 if (DBG) {
4114 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4115 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4116 + p3 + " data=" + data);
4117 }
4118 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4119 command, p1, p2, p3, data);
4120 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004121
Jordan Liu4c733742019-02-28 12:03:40 -08004122 @Override
4123 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4124 int command, int p1, int p2, int p3, String data) {
4125 enforceModifyPermission();
4126 if (DBG) {
4127 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4128 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4129 + p3 + " data=" + data);
4130 }
4131 return iccTransmitApduLogicalChannelWithPermission(
4132 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4133 data);
4134 }
4135
4136 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4137 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004138 final long identity = Binder.clearCallingIdentity();
4139 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004140 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004141 return "";
4142 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004143
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004144 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004145 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4146 null /* workSource */);
4147 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149 // Append the returned status code to the end of the response payload.
4150 String s = Integer.toHexString(
4151 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4152 if (response.payload != null) {
4153 s = IccUtils.bytesToHexString(response.payload) + s;
4154 }
4155 return s;
4156 } finally {
4157 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004158 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004159 }
Jake Hambye994d462014-02-03 13:10:13 -08004160
Evan Charltonc66da362014-05-16 14:06:40 -07004161 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004162 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4163 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4165 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004167 if (DBG) {
4168 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4169 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4170 }
4171 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4172 cla, command, p1, p2, p3, data);
4173 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004174
Jordan Liu4c733742019-02-28 12:03:40 -08004175 @Override
4176 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4177 int command, int p1, int p2, int p3, String data) {
4178 enforceModifyPermission();
4179 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4180 if (DBG) {
4181 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4182 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4183 + " data=" + data);
4184 }
4185
4186 return iccTransmitApduBasicChannelWithPermission(
4187 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4188 p2, p3, data);
4189 }
4190
4191 // open APDU basic channel assuming the caller has sufficient permissions
4192 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4193 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004194 final long identity = Binder.clearCallingIdentity();
4195 try {
4196 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4197 && TextUtils.equals(ISDR_AID, data)) {
4198 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004199 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4200 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004201 if (bestComponent == null
4202 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4203 loge("The calling package is not allowed to select ISD-R.");
4204 throw new SecurityException(
4205 "The calling package is not allowed to select ISD-R.");
4206 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004207 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004209 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004210 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4211 null /* workSource */);
4212 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214 // Append the returned status code to the end of the response payload.
4215 String s = Integer.toHexString(
4216 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4217 if (response.payload != null) {
4218 s = IccUtils.bytesToHexString(response.payload) + s;
4219 }
4220 return s;
4221 } finally {
4222 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004223 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004224 }
4225
4226 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004227 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004228 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4230 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004232 final long identity = Binder.clearCallingIdentity();
4233 try {
4234 if (DBG) {
4235 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4236 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4237 }
4238
4239 IccIoResult response =
4240 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4241 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4242 subId);
4243
4244 if (DBG) {
4245 log("Exchange SIM_IO [R]" + response);
4246 }
4247
4248 byte[] result = null;
4249 int length = 2;
4250 if (response.payload != null) {
4251 length = 2 + response.payload.length;
4252 result = new byte[length];
4253 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4254 } else {
4255 result = new byte[length];
4256 }
4257
4258 result[length - 1] = (byte) response.sw2;
4259 result[length - 2] = (byte) response.sw1;
4260 return result;
4261 } finally {
4262 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004263 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004264 }
4265
Nathan Haroldb3014052017-01-25 15:57:32 -08004266 /**
4267 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4268 * on a particular subscription
4269 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004270 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4271 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004273 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004274 return null;
4275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276
4277 final long identity = Binder.clearCallingIdentity();
4278 try {
4279 if (appType != TelephonyManager.APPTYPE_USIM
4280 && appType != TelephonyManager.APPTYPE_SIM) {
4281 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4282 return null;
4283 }
4284 Object response = sendRequest(
4285 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4286 if (response instanceof String[]) {
4287 return (String[]) response;
4288 }
yincheng zhao2737e882019-09-06 17:06:54 -07004289 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004291 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004292 } finally {
4293 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004294 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004295 }
4296
yincheng zhao2737e882019-09-06 17:06:54 -07004297 /**
4298 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4299 * subscription.
4300 *
4301 * @param subId the id of the subscription.
4302 * @param appType the uicc app type, must be USIM or SIM.
4303 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4304 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004305 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004306 * @return number of fplmns that is successfully written to the SIM.
4307 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004308 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4309 String callingFeatureId) {
4310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4311 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004312 if (DBG) logv("no permissions for setForbiddenplmns");
4313 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4314 }
4315 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4316 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4317 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4318 }
4319 if (fplmns == null) {
4320 throw new IllegalArgumentException("Fplmn List provided is null");
4321 }
4322 for (String fplmn : fplmns) {
4323 if (!CellIdentity.isValidPlmn(fplmn)) {
4324 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4325 }
4326 }
4327 final long identity = Binder.clearCallingIdentity();
4328 try {
4329 Object response = sendRequest(
4330 CMD_SET_FORBIDDEN_PLMNS,
4331 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4332 subId);
4333 return (int) response;
4334 } finally {
4335 Binder.restoreCallingIdentity(identity);
4336 }
4337 }
4338
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004339 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004340 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4342 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004344 final long identity = Binder.clearCallingIdentity();
4345 try {
4346 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4347 if (response.payload == null) {
4348 return "";
4349 }
Evan Charltonc66da362014-05-16 14:06:40 -07004350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004351 // Append the returned status code to the end of the response payload.
4352 String s = Integer.toHexString(
4353 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4354 s = IccUtils.bytesToHexString(response.payload) + s;
4355 return s;
4356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
Evan Charltonc66da362014-05-16 14:06:40 -07004359 }
4360
Jake Hambye994d462014-02-03 13:10:13 -08004361 /**
4362 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4363 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4364 *
4365 * @param itemID the ID of the item to read
4366 * @return the NV item as a String, or null on error.
4367 */
4368 @Override
4369 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004370 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4372 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373
4374 final long identity = Binder.clearCallingIdentity();
4375 try {
4376 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004377 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004378 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4379 return value;
4380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
Jake Hambye994d462014-02-03 13:10:13 -08004383 }
4384
4385 /**
4386 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4387 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4388 *
4389 * @param itemID the ID of the item to read
4390 * @param itemValue the value to write, as a String
4391 * @return true on success; false on any failure
4392 */
4393 @Override
4394 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004395 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4397 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004398
4399 final long identity = Binder.clearCallingIdentity();
4400 try {
4401 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4402 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004403 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4405 return success;
4406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
Jake Hambye994d462014-02-03 13:10:13 -08004409 }
4410
4411 /**
4412 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4413 * Used for device configuration by some CDMA operators.
4414 *
4415 * @param preferredRoamingList byte array containing the new PRL
4416 * @return true on success; false on any failure
4417 */
4418 @Override
4419 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4421 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422
4423 final long identity = Binder.clearCallingIdentity();
4424 try {
4425 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4426 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4427 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4428 return success;
4429 } finally {
4430 Binder.restoreCallingIdentity(identity);
4431 }
Jake Hambye994d462014-02-03 13:10:13 -08004432 }
4433
4434 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004435 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004436 * Used for device configuration by some CDMA operators.
4437 *
chen xu6dac5ab2018-10-26 17:39:23 -07004438 * @param slotIndex - device slot.
4439 *
Jake Hambye994d462014-02-03 13:10:13 -08004440 * @return true on success; false on any failure
4441 */
4442 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004443 public boolean resetModemConfig(int slotIndex) {
4444 Phone phone = PhoneFactory.getPhone(slotIndex);
4445 if (phone != null) {
4446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4447 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004448
chen xu6dac5ab2018-10-26 17:39:23 -07004449 final long identity = Binder.clearCallingIdentity();
4450 try {
4451 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4452 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4453 return success;
4454 } finally {
4455 Binder.restoreCallingIdentity(identity);
4456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457 }
chen xu6dac5ab2018-10-26 17:39:23 -07004458 return false;
4459 }
4460
4461 /**
4462 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4463 *
4464 * @param slotIndex - device slot.
4465 *
4466 * @return true on success; false on any failure
4467 */
4468 @Override
4469 public boolean rebootModem(int slotIndex) {
4470 Phone phone = PhoneFactory.getPhone(slotIndex);
4471 if (phone != null) {
4472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4473 mApp, phone.getSubId(), "rebootModem");
4474
4475 final long identity = Binder.clearCallingIdentity();
4476 try {
4477 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4478 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4479 return success;
4480 } finally {
4481 Binder.restoreCallingIdentity(identity);
4482 }
4483 }
4484 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004485 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004486
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004487 public String[] getPcscfAddress(String apnType, String callingPackage,
4488 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004489 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004490 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4491 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004492 return new String[0];
4493 }
4494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 final long identity = Binder.clearCallingIdentity();
4496 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004497 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
Wink Saville36469e72014-06-11 15:17:00 -07004501 }
4502
Brad Ebinger51f743a2017-01-23 13:50:20 -08004503 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004504 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4505 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004506 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004507 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004508 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004509
4510 final long identity = Binder.clearCallingIdentity();
4511 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004512 ImsResolver resolver = PhoneFactory.getImsResolver();
4513 if (resolver == null) {
4514 // may happen if the device does not support IMS.
4515 return;
4516 }
4517 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004521 }
4522
4523 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004524 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4525 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004526 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004527 public void disableIms(int slotId) {
4528 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529
4530 final long identity = Binder.clearCallingIdentity();
4531 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004532 ImsResolver resolver = PhoneFactory.getImsResolver();
4533 if (resolver == null) {
4534 // may happen if the device does not support IMS.
4535 return;
4536 }
4537 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004538 } finally {
4539 Binder.restoreCallingIdentity(identity);
4540 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004541 }
4542
4543 /**
4544 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4545 * feature or {@link null} if the service is not available. If the feature is available, the
4546 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4547 */
4548 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004549 IImsServiceFeatureCallback callback) {
4550 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004551
4552 final long identity = Binder.clearCallingIdentity();
4553 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004554 ImsResolver resolver = PhoneFactory.getImsResolver();
4555 if (resolver == null) {
4556 // may happen if the device does not support IMS.
4557 return null;
4558 }
4559 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004560 } finally {
4561 Binder.restoreCallingIdentity(identity);
4562 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004563 }
4564
4565 /**
4566 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4567 * feature during emergency calling or {@link null} if the service is not available. If the
4568 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4569 * listener for feature updates.
4570 */
4571 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4572 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004573
4574 final long identity = Binder.clearCallingIdentity();
4575 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004576 ImsResolver resolver = PhoneFactory.getImsResolver();
4577 if (resolver == null) {
4578 // may happen if the device does not support IMS.
4579 return null;
4580 }
4581 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004582 } finally {
4583 Binder.restoreCallingIdentity(identity);
4584 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004585 }
4586
Brad Ebinger5f64b052017-12-14 14:26:15 -08004587 /**
4588 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004589 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004590 */
4591 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4592 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004593
4594 final long identity = Binder.clearCallingIdentity();
4595 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004596 ImsResolver resolver = PhoneFactory.getImsResolver();
4597 if (resolver == null) {
4598 // may happen if the device does not support IMS.
4599 return null;
4600 }
4601 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004602 } finally {
4603 Binder.restoreCallingIdentity(identity);
4604 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004605 }
4606
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004607 /**
4608 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004609 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004610 */
4611 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4612 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004613
4614 final long identity = Binder.clearCallingIdentity();
4615 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004616 ImsResolver resolver = PhoneFactory.getImsResolver();
4617 if (resolver == null) {
4618 // may happen if the device does not support IMS.
4619 return null;
4620 }
4621 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004622 } finally {
4623 Binder.restoreCallingIdentity(identity);
4624 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004625 }
4626
Brad Ebinger884c07b2018-02-15 16:17:40 -08004627 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004628 * Sets the ImsService Package Name that Telephony will bind to.
4629 *
4630 * @param slotId the slot ID that the ImsService should bind for.
4631 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4632 * ImsService is the device default ImsService.
4633 * @param packageName The package name of the application that contains the ImsService to bind
4634 * to.
4635 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4636 * @hide
4637 */
4638 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004639 int[] subIds = SubscriptionManager.getSubId(slotId);
4640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4641 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4642 "setImsService");
4643
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004644 final long identity = Binder.clearCallingIdentity();
4645 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004646 ImsResolver resolver = PhoneFactory.getImsResolver();
4647 if (resolver == null) {
4648 // may happen if the device does not support IMS.
4649 return false;
4650 }
4651 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4652 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 } finally {
4654 Binder.restoreCallingIdentity(identity);
4655 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004656 }
4657
4658 /**
4659 * Return the ImsService configuration.
4660 *
4661 * @param slotId The slot that the ImsService is associated with.
4662 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4663 * the device default.
4664 * @return the package name of the ImsService configuration.
4665 */
4666 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004667 int[] subIds = SubscriptionManager.getSubId(slotId);
4668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4669 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4670 "getImsService");
4671
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004672 final long identity = Binder.clearCallingIdentity();
4673 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004674 ImsResolver resolver = PhoneFactory.getImsResolver();
4675 if (resolver == null) {
4676 // may happen if the device does not support IMS.
4677 return "";
4678 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004679 // TODO: change API to query RCS separately.
4680 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4681 ImsFeature.FEATURE_MMTEL);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004682 } finally {
4683 Binder.restoreCallingIdentity(identity);
4684 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004685 }
4686
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004687 /**
4688 * Get the MmTelFeature state associated with the requested subscription id.
4689 * @param subId The subscription that the MmTelFeature is associated with.
4690 * @param callback A callback with an integer containing the
4691 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4692 */
4693 @Override
4694 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4695 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4696 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4697 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4698 "IMS not available on device.");
4699 }
4700 final long token = Binder.clearCallingIdentity();
4701 try {
4702 int slotId = getSlotIndex(subId);
4703 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4704 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4705 + subId + "'");
4706 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4707 }
4708 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4709 try {
4710 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4711 } catch (RemoteException e) {
4712 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4713 + "Ignore");
4714 }
4715 });
4716 } finally {
4717 Binder.restoreCallingIdentity(token);
4718 }
4719 }
4720
Wink Saville36469e72014-06-11 15:17:00 -07004721 public void setImsRegistrationState(boolean registered) {
4722 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723
4724 final long identity = Binder.clearCallingIdentity();
4725 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004726 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 } finally {
4728 Binder.restoreCallingIdentity(identity);
4729 }
Wink Saville36469e72014-06-11 15:17:00 -07004730 }
4731
4732 /**
Stuart Scott54788802015-03-30 13:18:01 -07004733 * Set the network selection mode to automatic.
4734 *
4735 */
4736 @Override
4737 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4739 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004740
Pengquan Menge92a50d2018-09-21 15:54:48 -07004741 if (!isActiveSubscription(subId)) {
4742 return;
4743 }
4744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004745 final long identity = Binder.clearCallingIdentity();
4746 try {
4747 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4748 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4749 } finally {
4750 Binder.restoreCallingIdentity(identity);
4751 }
Stuart Scott54788802015-03-30 13:18:01 -07004752 }
4753
Pengquan Mengea84e042018-09-20 14:57:26 -07004754 /**
4755 * Ask the radio to connect to the input network and change selection mode to manual.
4756 *
4757 * @param subId the id of the subscription.
4758 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4759 * the operator to attach to.
4760 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4761 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4762 * normal network selection next time.
4763 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004764 */
4765 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004766 public boolean setNetworkSelectionModeManual(
4767 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4769 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004770
4771 if (!isActiveSubscription(subId)) {
4772 return false;
4773 }
4774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004775 final long identity = Binder.clearCallingIdentity();
4776 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004777 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004778 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004779 if (DBG) {
4780 log("setNetworkSelectionModeManual: subId: " + subId
4781 + " operator: " + operatorInfo);
4782 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4784 } finally {
4785 Binder.restoreCallingIdentity(identity);
4786 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004787 }
4788
4789 /**
4790 * Scans for available networks.
4791 */
4792 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004793 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4794 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4796 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004797 LocationAccessPolicy.LocationPermissionResult locationResult =
4798 LocationAccessPolicy.checkLocationPermission(mApp,
4799 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4800 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004801 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004802 .setCallingPid(Binder.getCallingPid())
4803 .setCallingUid(Binder.getCallingUid())
4804 .setMethod("getCellNetworkScanResults")
4805 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4806 .build());
4807 switch (locationResult) {
4808 case DENIED_HARD:
4809 throw new SecurityException("Not allowed to access scan results -- location");
4810 case DENIED_SOFT:
4811 return null;
4812 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813
Pengquan Menga1bb6272018-09-06 09:59:22 -07004814 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815 try {
4816 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004817 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819 } finally {
4820 Binder.restoreCallingIdentity(identity);
4821 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004822 }
4823
4824 /**
yinxub1bed742017-04-17 11:45:04 -07004825 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004826 *
yinxub1bed742017-04-17 11:45:04 -07004827 * @param subId id of the subscription
4828 * @param request contains the radio access networks with bands/channels to scan
4829 * @param messenger callback messenger for scan results or errors
4830 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004831 * @return the id of the requested scan which can be used to stop the scan.
4832 */
4833 @Override
4834 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004835 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4837 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004838 LocationAccessPolicy.LocationPermissionResult locationResult =
4839 LocationAccessPolicy.checkLocationPermission(mApp,
4840 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4841 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004842 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004843 .setCallingPid(Binder.getCallingPid())
4844 .setCallingUid(Binder.getCallingUid())
4845 .setMethod("requestNetworkScan")
4846 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4847 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004848 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004849 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004850 if (e != null) {
4851 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4852 throw e;
4853 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004854 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004855 return TelephonyScanManager.INVALID_SCAN_ID;
4856 }
4857 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004858 }
Hall Liu912dfd32019-04-25 14:02:26 -07004859 int callingUid = Binder.getCallingUid();
4860 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004861 final long identity = Binder.clearCallingIdentity();
4862 try {
4863 return mNetworkScanRequestTracker.startNetworkScan(
4864 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004865 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004866 } finally {
4867 Binder.restoreCallingIdentity(identity);
4868 }
yinxu504e1392017-04-12 16:03:22 -07004869 }
4870
Hall Liub2ac8ef2019-02-28 15:56:23 -08004871 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004872 NetworkScanRequest request, int subId) {
4873 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4874 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4875 boolean hasNetworkScanPermission =
4876 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4877 == PERMISSION_GRANTED;
4878
4879 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4880 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4881 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004882 }
4883
4884 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4885 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004886 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4887 return new SecurityException("Specific channels must not be"
4888 + " scanned without location access.");
4889 }
4890 }
4891 }
4892
Hall Liub2ac8ef2019-02-28 15:56:23 -08004893 return null;
4894 }
4895
yinxu504e1392017-04-12 16:03:22 -07004896 /**
4897 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004898 *
4899 * @param subId id of the subscription
4900 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004901 */
4902 @Override
4903 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4905 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906
Hall Liu912dfd32019-04-25 14:02:26 -07004907 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908 final long identity = Binder.clearCallingIdentity();
4909 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004910 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004911 } finally {
4912 Binder.restoreCallingIdentity(identity);
4913 }
yinxu504e1392017-04-12 16:03:22 -07004914 }
4915
4916 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004917 * Get the calculated preferred network type.
4918 * Used for debugging incorrect network type.
4919 *
4920 * @return the preferred network type, defined in RILConstants.java.
4921 */
4922 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004923 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004924 final Phone defaultPhone = getDefaultPhone();
4925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004926 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004927 return RILConstants.PREFERRED_NETWORK_MODE;
4928 }
4929
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004930 final long identity = Binder.clearCallingIdentity();
4931 try {
4932 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004933 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934 } finally {
4935 Binder.restoreCallingIdentity(identity);
4936 }
Junda Liu84d15a22014-07-02 11:21:04 -07004937 }
4938
4939 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004940 * Get the preferred network type.
4941 * Used for device configuration by some CDMA operators.
4942 *
4943 * @return the preferred network type, defined in RILConstants.java.
4944 */
4945 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004946 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004947 TelephonyPermissions
4948 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4949 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950
4951 final long identity = Binder.clearCallingIdentity();
4952 try {
4953 if (DBG) log("getPreferredNetworkType");
4954 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4955 int networkType = (result != null ? result[0] : -1);
4956 if (DBG) log("getPreferredNetworkType: " + networkType);
4957 return networkType;
4958 } finally {
4959 Binder.restoreCallingIdentity(identity);
4960 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004961 }
4962
4963 /**
4964 * Set the preferred network type.
4965 * Used for device configuration by some CDMA operators.
4966 *
4967 * @param networkType the preferred network type, defined in RILConstants.java.
4968 * @return true on success; false on any failure.
4969 */
4970 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004971 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4973 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974
4975 final long identity = Binder.clearCallingIdentity();
4976 try {
4977 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4978 Boolean success = (Boolean) sendRequest(
4979 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4980 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4981 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004982 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4984 }
4985 return success;
4986 } finally {
4987 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004988 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004989 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004990
4991 /**
Miaoa84611c2019-03-15 09:21:10 +08004992 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004993 *
Miaoa84611c2019-03-15 09:21:10 +08004994 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004995 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004996 * @hide
4997 */
4998 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004999 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005000 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005002 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003 try {
Miaoa84611c2019-03-15 09:21:10 +08005004 if (phone != null) {
5005 return phone.hasMatchedTetherApnSetting();
5006 } else {
5007 return false;
5008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009 } finally {
5010 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005011 }
Junda Liu475951f2014-11-07 16:45:03 -08005012 }
5013
5014 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005015 * Set mobile data enabled
5016 * Used by the user through settings etc to turn on/off mobile data
5017 *
5018 * @param enable {@code true} turn turn data on, else {@code false}
5019 */
5020 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005021 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5023 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024
5025 final long identity = Binder.clearCallingIdentity();
5026 try {
5027 int phoneId = mSubscriptionController.getPhoneId(subId);
5028 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5029 Phone phone = PhoneFactory.getPhone(phoneId);
5030 if (phone != null) {
5031 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005032 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005033 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005034 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005035 }
5036 } finally {
5037 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005038 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005039 }
5040
5041 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005042 * Get the user enabled state of Mobile Data.
5043 *
5044 * TODO: remove and use isUserDataEnabled.
5045 * This can't be removed now because some vendor codes
5046 * calls through ITelephony directly while they should
5047 * use TelephonyManager.
5048 *
5049 * @return true on enabled
5050 */
5051 @Override
5052 public boolean getDataEnabled(int subId) {
5053 return isUserDataEnabled(subId);
5054 }
5055
5056 /**
5057 * Get whether mobile data is enabled per user setting.
5058 *
5059 * There are other factors deciding whether mobile data is actually enabled, but they are
5060 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005061 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005062 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005063 *
5064 * @return {@code true} if data is enabled else {@code false}
5065 */
5066 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005067 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005068 try {
5069 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5070 null);
5071 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5073 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005075
5076 final long identity = Binder.clearCallingIdentity();
5077 try {
5078 int phoneId = mSubscriptionController.getPhoneId(subId);
5079 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5080 Phone phone = PhoneFactory.getPhone(phoneId);
5081 if (phone != null) {
5082 boolean retVal = phone.isUserDataEnabled();
5083 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5084 return retVal;
5085 } else {
5086 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5087 return false;
5088 }
5089 } finally {
5090 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005091 }
5092 }
5093
5094 /**
5095 * Get whether mobile data is enabled.
5096 *
5097 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5098 * whether mobile data is actually enabled.
5099 *
5100 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5101 *
5102 * @return {@code true} if data is enabled else {@code false}
5103 */
5104 @Override
5105 public boolean isDataEnabled(int subId) {
5106 try {
5107 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5108 null);
5109 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5111 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005112 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113
5114 final long identity = Binder.clearCallingIdentity();
5115 try {
5116 int phoneId = mSubscriptionController.getPhoneId(subId);
5117 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5118 Phone phone = PhoneFactory.getPhone(phoneId);
5119 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005120 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5122 return retVal;
5123 } else {
5124 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5125 return false;
5126 }
5127 } finally {
5128 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005129 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005130 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005131
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005132 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5133 Phone phone) {
5134 //load access rules from carrier configs, and check those as well: b/139133814
5135 SubscriptionController subController = SubscriptionController.getInstance();
5136 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5137 || subController == null) return privilegeFromSim;
5138
5139 int uid = Binder.getCallingUid();
5140 PackageManager pkgMgr = phone.getContext().getPackageManager();
5141 String[] packages = pkgMgr.getPackagesForUid(uid);
5142
5143 final long identity = Binder.clearCallingIdentity();
5144 try {
5145 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5146 SubscriptionManager subManager = (SubscriptionManager)
5147 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5148 for (String pkg : packages) {
5149 if (subManager.canManageSubscription(subInfo, pkg)) {
5150 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5151 }
5152 }
5153 return privilegeFromSim;
5154 } finally {
5155 Binder.restoreCallingIdentity(identity);
5156 }
5157 }
5158
5159 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5160 String pkgName) {
5161 //load access rules from carrier configs, and check those as well: b/139133814
5162 SubscriptionController subController = SubscriptionController.getInstance();
5163 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5164 || subController == null) return privilegeFromSim;
5165
5166 final long identity = Binder.clearCallingIdentity();
5167 try {
5168 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5169 SubscriptionManager subManager = (SubscriptionManager)
5170 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5171 return subManager.canManageSubscription(subInfo, pkgName)
5172 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5173 } finally {
5174 Binder.restoreCallingIdentity(identity);
5175 }
5176 }
5177
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005178 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005179 public int getCarrierPrivilegeStatus(int subId) {
5180 final Phone phone = getPhone(subId);
5181 if (phone == null) {
5182 loge("getCarrierPrivilegeStatus: Invalid subId");
5183 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5184 }
5185 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005186 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005187 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005188 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5189 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005190
5191 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5192 card.getCarrierPrivilegeStatusForCurrentTransaction(
5193 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005194 }
Junda Liu29340342014-07-10 15:23:27 -07005195
5196 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005197 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005198 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005199 final Phone phone = getPhone(subId);
5200 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005201 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005202 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5203 }
5204 UiccProfile profile =
5205 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5206 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005207 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005208 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5209 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005210 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005211 profile.getCarrierPrivilegeStatusForUid(
5212 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005213 }
5214
5215 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005216 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5217 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005218 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005219 }
5220
5221 int phoneId = SubscriptionManager.getPhoneId(subId);
5222 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005223 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005224 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005225 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5226 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005227 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5228 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5229 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005230 }
5231
5232 @Override
5233 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005234 if (TextUtils.isEmpty(pkgName))
5235 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005236 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5237 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5238 UiccCard card = UiccController.getInstance().getUiccCard(i);
5239 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005240 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005241 continue;
5242 }
5243
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005244 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5245 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5246 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005247 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5248 break;
5249 }
5250 }
5251
5252 return result;
Junda Liu29340342014-07-10 15:23:27 -07005253 }
Derek Tan89e89d42014-07-08 17:00:10 -07005254
5255 @Override
Junda Liue64de782015-04-16 17:19:16 -07005256 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5257 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5258 loge("phoneId " + phoneId + " is not valid.");
5259 return null;
5260 }
5261 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005262 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005263 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005264 return null ;
5265 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005266 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005267 }
5268
Amith Yamasani6e118872016-02-19 12:53:51 -08005269 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005270 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005271 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005272 List<String> privilegedPackages = new ArrayList<>();
5273 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005274 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5275 // has UICC in that slot.
5276 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005277 if (card.hasCarrierPrivilegeRules()) {
5278 if (packages == null) {
5279 // Only check packages in user 0 for now
5280 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005281 PackageManager.MATCH_DISABLED_COMPONENTS
5282 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005283 | PackageManager.GET_SIGNING_CERTIFICATES,
5284 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005285 }
5286 for (int p = packages.size() - 1; p >= 0; p--) {
5287 PackageInfo pkgInfo = packages.get(p);
5288 if (pkgInfo != null && pkgInfo.packageName != null
5289 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005290 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005291 privilegedPackages.add(pkgInfo.packageName);
5292 }
5293 }
5294 }
5295 }
5296 return privilegedPackages;
5297 }
5298
chen xuf7e9fe82019-05-09 19:31:02 -07005299 @Override
5300 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005301 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5302
5303 final long identity = Binder.clearCallingIdentity();
5304
chen xuf7e9fe82019-05-09 19:31:02 -07005305 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005306 try {
5307 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5308 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5309 }
5310 } finally {
5311 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005312 }
5313 return privilegedPackages;
5314 }
5315
Wink Savilleb564aae2014-10-23 10:18:09 -07005316 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005317 final Phone phone = getPhone(subId);
5318 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005319 if (card == null) {
5320 loge("getIccId: No UICC");
5321 return null;
5322 }
5323 String iccId = card.getIccId();
5324 if (TextUtils.isEmpty(iccId)) {
5325 loge("getIccId: ICC ID is null or empty.");
5326 return null;
5327 }
5328 return iccId;
5329 }
5330
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005331 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005332 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5333 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005334 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005335 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005337 final long identity = Binder.clearCallingIdentity();
5338 try {
5339 final String iccId = getIccId(subId);
5340 final Phone phone = getPhone(subId);
5341 if (phone == null) {
5342 return false;
5343 }
5344 final String subscriberId = phone.getSubscriberId();
5345
5346 if (DBG_MERGE) {
5347 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5348 + subscriberId + " to " + number);
5349 }
5350
5351 if (TextUtils.isEmpty(iccId)) {
5352 return false;
5353 }
5354
5355 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5356
5357 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5358 if (alphaTag == null) {
5359 editor.remove(alphaTagPrefKey);
5360 } else {
5361 editor.putString(alphaTagPrefKey, alphaTag);
5362 }
5363
5364 // Record both the line number and IMSI for this ICCID, since we need to
5365 // track all merged IMSIs based on line number
5366 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5367 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5368 if (number == null) {
5369 editor.remove(numberPrefKey);
5370 editor.remove(subscriberPrefKey);
5371 } else {
5372 editor.putString(numberPrefKey, number);
5373 editor.putString(subscriberPrefKey, subscriberId);
5374 }
5375
5376 editor.commit();
5377 return true;
5378 } finally {
5379 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005380 }
Derek Tan7226c842014-07-02 17:42:23 -07005381 }
5382
5383 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005384 public String getLine1NumberForDisplay(int subId, String callingPackage,
5385 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005386 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005388 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005389 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005390 return null;
5391 }
Derek Tan97ebb422014-09-05 16:55:38 -07005392
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 final long identity = Binder.clearCallingIdentity();
5394 try {
5395 String iccId = getIccId(subId);
5396 if (iccId != null) {
5397 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5398 if (DBG_MERGE) {
5399 log("getLine1NumberForDisplay returning "
5400 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5401 }
5402 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005403 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5405 return null;
5406 } finally {
5407 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005408 }
Derek Tan7226c842014-07-02 17:42:23 -07005409 }
5410
5411 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005412 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5413 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005415 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005416 return null;
5417 }
Derek Tan97ebb422014-09-05 16:55:38 -07005418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 final long identity = Binder.clearCallingIdentity();
5420 try {
5421 String iccId = getIccId(subId);
5422 if (iccId != null) {
5423 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5424 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5425 }
5426 return null;
5427 } finally {
5428 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005429 }
Derek Tan7226c842014-07-02 17:42:23 -07005430 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005431
5432 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005433 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5434 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005435 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5436 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005438 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005439 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005440 return null;
5441 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005442
Jordan Liub49b04b2019-05-06 14:45:15 -07005443 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5444 // the process, where TelephonyManager was instantiated.
5445 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005446 final long identity = Binder.clearCallingIdentity();
5447 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005448 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 final TelephonyManager tele = TelephonyManager.from(context);
5450 final SubscriptionManager sub = SubscriptionManager.from(context);
5451
5452 // Figure out what subscribers are currently active
5453 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454
Jordan Liub49b04b2019-05-06 14:45:15 -07005455 // Only consider subs which match the current subId
5456 // This logic can be simplified. See b/131189269 for progress.
5457 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005458 activeSubscriberIds.add(tele.getSubscriberId(subId));
5459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460
5461 // First pass, find a number override for an active subscriber
5462 String mergeNumber = null;
5463 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5464 for (String key : prefs.keySet()) {
5465 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5466 final String subscriberId = (String) prefs.get(key);
5467 if (activeSubscriberIds.contains(subscriberId)) {
5468 final String iccId = key.substring(
5469 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5470 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5471 mergeNumber = (String) prefs.get(numberKey);
5472 if (DBG_MERGE) {
5473 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5474 + " for active subscriber " + subscriberId);
5475 }
5476 if (!TextUtils.isEmpty(mergeNumber)) {
5477 break;
5478 }
5479 }
5480 }
5481 }
5482
5483 // Shortcut when no active merged subscribers
5484 if (TextUtils.isEmpty(mergeNumber)) {
5485 return null;
5486 }
5487
5488 // Second pass, find all subscribers under that line override
5489 final ArraySet<String> result = new ArraySet<>();
5490 for (String key : prefs.keySet()) {
5491 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5492 final String number = (String) prefs.get(key);
5493 if (mergeNumber.equals(number)) {
5494 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5495 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5496 final String subscriberId = (String) prefs.get(subscriberKey);
5497 if (!TextUtils.isEmpty(subscriberId)) {
5498 result.add(subscriberId);
5499 }
5500 }
5501 }
5502 }
5503
5504 final String[] resultArray = result.toArray(new String[result.size()]);
5505 Arrays.sort(resultArray);
5506 if (DBG_MERGE) {
5507 Slog.d(LOG_TAG,
5508 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5509 }
5510 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005511 } finally {
5512 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005513 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005514 }
5515
5516 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005517 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5518 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5519
5520 final long identity = Binder.clearCallingIdentity();
5521 try {
5522 final TelephonyManager telephonyManager = mApp.getSystemService(
5523 TelephonyManager.class);
5524 String subscriberId = telephonyManager.getSubscriberId(subId);
5525 if (subscriberId == null) {
5526 if (DBG) {
5527 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5528 + subId);
5529 }
5530 return null;
5531 }
5532
5533 final SubscriptionInfo info = SubscriptionController.getInstance()
5534 .getSubscriptionInfo(subId);
5535 final ParcelUuid groupUuid = info.getGroupUuid();
5536 // If it doesn't belong to any group, return just subscriberId of itself.
5537 if (groupUuid == null) {
5538 return new String[]{subscriberId};
5539 }
5540
5541 // Get all subscriberIds from the group.
5542 final List<String> mergedSubscriberIds = new ArrayList<>();
5543 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005544 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5545 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005546 for (SubscriptionInfo subInfo : groupInfos) {
5547 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5548 if (subscriberId != null) {
5549 mergedSubscriberIds.add(subscriberId);
5550 }
5551 }
5552
5553 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5554 } finally {
5555 Binder.restoreCallingIdentity(identity);
5556
5557 }
5558 }
5559
5560 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005561 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005562 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005563 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564
5565 final long identity = Binder.clearCallingIdentity();
5566 try {
5567 final Phone phone = getPhone(subId);
5568 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5569 } finally {
5570 Binder.restoreCallingIdentity(identity);
5571 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005572 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005573
5574 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005575 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005576 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5577 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005578 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5579 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580
5581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 final Phone phone = getPhone(subId);
5584 if (phone == null) {
5585 return false;
5586 }
5587 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5588 cdmaNonRoamingList);
5589 } finally {
5590 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005591 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005592 }
5593
5594 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005595 @Deprecated
5596 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5597 enforceModifyPermission();
5598
5599 int returnValue = 0;
5600 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005601 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005602 if(result.exception == null) {
5603 if (result.result != null) {
5604 byte[] responseData = (byte[])(result.result);
5605 if(responseData.length > oemResp.length) {
5606 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5607 responseData.length + "bytes. Buffer Size is " +
5608 oemResp.length + "bytes.");
5609 }
5610 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5611 returnValue = responseData.length;
5612 }
5613 } else {
5614 CommandException ex = (CommandException) result.exception;
5615 returnValue = ex.getCommandError().ordinal();
5616 if(returnValue > 0) returnValue *= -1;
5617 }
5618 } catch (RuntimeException e) {
5619 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5620 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5621 if(returnValue > 0) returnValue *= -1;
5622 }
5623
5624 return returnValue;
5625 }
5626
5627 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005628 public void setRadioCapability(RadioAccessFamily[] rafs) {
5629 try {
5630 ProxyController.getInstance().setRadioCapability(rafs);
5631 } catch (RuntimeException e) {
5632 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5633 }
5634 }
5635
5636 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005637 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005638 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005639 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005640 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005641 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643 final long identity = Binder.clearCallingIdentity();
5644 try {
chen xub97461a2018-10-26 14:17:57 -07005645 TelephonyPermissions
5646 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5647 mApp, phone.getSubId(), "getRadioAccessFamily");
5648 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649 } finally {
5650 Binder.restoreCallingIdentity(identity);
5651 }
chen xub97461a2018-10-26 14:17:57 -07005652 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005653 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005654
5655 @Override
5656 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005657 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005658 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659
5660 final long identity = Binder.clearCallingIdentity();
5661 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005662 ImsManager.getInstance(defaultPhone.getContext(),
5663 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 } finally {
5665 Binder.restoreCallingIdentity(identity);
5666 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005667 }
5668
5669 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005670 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005671 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005672 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5673 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005674 return false;
5675 }
Svet Ganovb320e182015-04-16 12:30:10 -07005676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 final long identity = Binder.clearCallingIdentity();
5678 try {
5679 // Check the user preference and the system-level IMS setting. Even if the user has
5680 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5681 // In the long run, we may instead need to check if there exists a connection service
5682 // which can support video calling.
5683 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005684 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005685 return imsManager.isVtEnabledByPlatform()
5686 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5687 && imsManager.isVtEnabledByUser();
5688 } finally {
5689 Binder.restoreCallingIdentity(identity);
5690 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005691 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005692
Andrew Leea1239f22015-03-02 17:44:07 -08005693 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005694 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5695 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005697 mApp, subId, callingPackage, callingFeatureId,
5698 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 return false;
5700 }
5701
5702 final long identity = Binder.clearCallingIdentity();
5703 try {
5704 CarrierConfigManager configManager =
5705 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005706 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
Andrew Leea1239f22015-03-02 17:44:07 -08005711 }
5712
5713 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005714 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005716 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 return false;
5718 }
5719
5720 final long identity = Binder.clearCallingIdentity();
5721 try {
5722 CarrierConfigManager configManager =
5723 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005724 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5726 } finally {
5727 Binder.restoreCallingIdentity(identity);
5728 }
Andrew Leea1239f22015-03-02 17:44:07 -08005729 }
5730
Andrew Lee9431b832015-03-09 18:46:45 -07005731 @Override
5732 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005733 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005734 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005735 }
5736
5737 @Override
5738 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 final long identity = Binder.clearCallingIdentity();
5740 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005741 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 } finally {
5743 Binder.restoreCallingIdentity(identity);
5744 }
Andrew Lee9431b832015-03-09 18:46:45 -07005745 }
5746
Hall Liuf6668912018-10-31 17:05:23 -07005747 /**
5748 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5749 * support for the feature and device firmware support.
5750 *
5751 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5752 */
5753 @Override
5754 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005755 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005756 final Phone phone = getPhone(subscriptionId);
5757 if (phone == null) {
5758 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5759 return false;
5760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005762 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5764 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005765 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 return isCarrierSupported && isDeviceSupported;
5767 } finally {
5768 Binder.restoreCallingIdentity(identity);
5769 }
Hall Liu98187582018-01-22 19:15:32 -08005770 }
5771
Hall Liuf6668912018-10-31 17:05:23 -07005772 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005773 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5774 * RTT setting, will return true if the device and carrier both support RTT.
5775 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005776 */
5777 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 final long identity = Binder.clearCallingIdentity();
5779 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00005780 boolean isRttSupported = isRttSupported(subscriptionId);
5781 boolean isUserRttSettingOn = Settings.Secure.getInt(
5782 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5783 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5784 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5785 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 } finally {
5787 Binder.restoreCallingIdentity(identity);
5788 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005789 }
5790
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005791 @Deprecated
5792 @Override
5793 public String getDeviceId(String callingPackage) {
5794 return getDeviceIdWithFeature(callingPackage, null);
5795 }
5796
Sanket Padawe7310cc72015-01-14 09:53:20 -08005797 /**
5798 * Returns the unique device ID of phone, for example, the IMEI for
5799 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5800 *
5801 * <p>Requires Permission:
5802 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5803 */
5804 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005805 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005806 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005807 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005808 return null;
5809 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005810 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005811 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005812 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005813 return null;
5814 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815
5816 final long identity = Binder.clearCallingIdentity();
5817 try {
5818 return phone.getDeviceId();
5819 } finally {
5820 Binder.restoreCallingIdentity(identity);
5821 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005822 }
5823
Ping Sunc67b7c22016-03-02 19:16:45 +08005824 /**
5825 * {@hide}
5826 * Returns the IMS Registration Status on a particular subid
5827 *
5828 * @param subId
5829 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005830 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005831 Phone phone = getPhone(subId);
5832 if (phone != null) {
5833 return phone.isImsRegistered();
5834 } else {
5835 return false;
5836 }
5837 }
5838
Santos Cordon7a1885b2015-02-03 11:15:19 -08005839 @Override
5840 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005841 final long identity = Binder.clearCallingIdentity();
5842 try {
5843 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5844 } finally {
5845 Binder.restoreCallingIdentity(identity);
5846 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005847 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005848
Tyler Gunnf70ed162019-04-03 15:28:53 -07005849 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005850 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005851 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005852 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005853 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005854 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5855 }
5856 final long identity = Binder.clearCallingIdentity();
5857 try {
5858 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5859 } finally {
5860 Binder.restoreCallingIdentity(identity);
5861 }
5862 }
5863
5864 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005865 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5866 final long identity = Binder.clearCallingIdentity();
5867 try {
5868 Phone phone = getPhone(subscriptionId);
5869 if (phone == null) {
5870 return null;
5871 }
5872 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5873 } finally {
5874 Binder.restoreCallingIdentity(identity);
5875 }
5876 }
5877
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005878 /**
5879 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005880 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005881 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 Phone phone = getPhone(subId);
5885 if (phone != null) {
5886 return phone.isWifiCallingEnabled();
5887 } else {
5888 return false;
5889 }
5890 } finally {
5891 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005892 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005893 }
5894
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005895 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005896 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005897 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005898 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005899 final long identity = Binder.clearCallingIdentity();
5900 try {
5901 Phone phone = getPhone(subId);
5902 if (phone != null) {
5903 return phone.isVideoEnabled();
5904 } else {
5905 return false;
5906 }
5907 } finally {
5908 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005909 }
5910 }
5911
5912 /**
5913 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5914 * defined in {@link ImsRegistrationImplBase}.
5915 */
5916 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917 final long identity = Binder.clearCallingIdentity();
5918 try {
5919 Phone phone = getPhone(subId);
5920 if (phone != null) {
5921 return phone.getImsRegistrationTech();
5922 } else {
5923 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5924 }
5925 } finally {
5926 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005927 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005928 }
5929
Stuart Scott8eef64f2015-04-08 15:13:54 -07005930 @Override
5931 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08005932 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005933 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5934 return;
5935 }
5936
Svet Ganovcc087f82015-05-12 20:35:54 -07005937 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005938
Svet Ganovcc087f82015-05-12 20:35:54 -07005939 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005940 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5941 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005942 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005943 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005944 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005945 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5946 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005947 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005948 // There has been issues when Sms raw table somehow stores orphan
5949 // fragments. They lead to garbled message when new fragments come
5950 // in and combined with those stale ones. In case this happens again,
5951 // user can reset all network settings which will clean up this table.
5952 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005953 // Clean up IMS settings as well here.
5954 int slotId = getSlotIndex(subId);
5955 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5956 ImsManager.getInstance(mApp, slotId).factoryReset();
5957 }
Naina Nallurid63128d2019-09-17 14:10:30 -07005958
5959 // Erase modem config if erase modem on network setting is enabled.
5960 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5961 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5962 if (configValue != null && Boolean.parseBoolean(configValue)) {
5963 sendEraseModemConfig(getDefaultPhone());
5964 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005965 } finally {
5966 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005967 }
5968 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005969
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005970 private void cleanUpSmsRawTable(Context context) {
5971 ContentResolver resolver = context.getContentResolver();
5972 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5973 resolver.delete(uri, null, null);
5974 }
5975
Narayan Kamath1c496c22015-04-16 14:40:19 +01005976 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005977 public String getSimLocaleForSubscriber(int subId) {
5978 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5979 final Phone phone = getPhone(subId);
5980 if (phone == null) {
5981 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005982 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005983 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 final long identity = Binder.clearCallingIdentity();
5985 try {
chen xu5d3637b2019-01-21 23:31:38 -08005986 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005987 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08005988 if (info == null) {
5989 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5990 return null;
5991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 // Try and fetch the locale from the carrier properties or from the SIM language
5993 // preferences (EF-PL and EF-LI)...
5994 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005996 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5997 if (localeFromDefaultSim != null) {
5998 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5999 if (DBG) log("Using locale from subId: " + subId + " locale: "
6000 + localeFromDefaultSim);
6001 return localeFromDefaultSim.toLanguageTag();
6002 } else {
6003 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 }
6005 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 // The SIM language preferences only store a language (e.g. fr = French), not an
6008 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6009 // the SIM and carrier preferences does not include a country we add the country
6010 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006011 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006013 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 return mccLocale.toLanguageTag();
6015 }
6016
6017 if (DBG) log("No locale found - returning null");
6018 return null;
6019 } finally {
6020 Binder.restoreCallingIdentity(identity);
6021 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006022 }
6023
6024 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006025 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6026 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006027 }
6028
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029 /**
6030 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6031 */
6032 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006033 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6034 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006035 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006036
Chenjie Yu1ba97252018-01-11 18:16:20 -08006037 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006038 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006039
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006040 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006041 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6042 * representing the state of the modem.
6043 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006044 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6045 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006046 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006047 */
6048 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006049 public void requestModemActivityInfo(ResultReceiver result) {
6050 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006051 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052
6053 final long identity = Binder.clearCallingIdentity();
6054 try {
6055 ModemActivityInfo ret = null;
6056 synchronized (mLastModemActivityInfo) {
6057 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6058 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006059 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006060 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006062 int[] txTimeMs = info.getTransmitTimeMillis();
6063 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006065 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066 }
6067 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006068 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6069 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 mLastModemActivityInfo.setIdleTimeMillis(
6071 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006072 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6073 mLastModemActivityInfo.setReceiveTimeMillis(
6074 info.getReceiveTimeMillis() + mLastModemActivityInfo
6075 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006076 }
Chen Xud78231e2019-09-10 18:49:52 -07006077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6079 mLastModemActivityInfo.getSleepTimeMillis(),
6080 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006081 mLastModemActivityInfo.getTransmitTimeMillis(),
6082 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084 Bundle bundle = new Bundle();
6085 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6086 result.send(0, bundle);
6087 } finally {
6088 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006089 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006090 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006091
Siddharth Rayb8114062018-06-17 15:02:38 -07006092 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6093 // less than total activity duration.
6094 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6095 if (info == null) {
6096 return false;
6097 }
6098 int activityDurationMs =
6099 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6100 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006101 int[] txTimeMs = info.getTransmitTimeMillis();
6102 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6103 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006104 }
6105 return (info.isValid()
6106 && (info.getSleepTimeMillis() <= activityDurationMs)
6107 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006108 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006109 && (totalTxTimeMs <= activityDurationMs));
6110 }
6111
Jack Yu85bd38a2015-11-09 11:34:32 -08006112 /**
6113 * {@hide}
6114 * Returns the service state information on specified subscription.
6115 */
6116 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006117 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6118 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006120 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006121 return null;
6122 }
6123
Hall Liuf19c44f2018-11-27 14:38:17 -08006124 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6125 LocationAccessPolicy.checkLocationPermission(mApp,
6126 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6127 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006128 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006129 .setCallingPid(Binder.getCallingPid())
6130 .setCallingUid(Binder.getCallingUid())
6131 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006132 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006133 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6134 .build());
6135
6136 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6137 LocationAccessPolicy.checkLocationPermission(mApp,
6138 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6139 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006140 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006141 .setCallingPid(Binder.getCallingPid())
6142 .setCallingUid(Binder.getCallingUid())
6143 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006144 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006145 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6146 .build());
6147 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6148 boolean hasFinePermission =
6149 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6150 boolean hasCoarsePermission =
6151 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006153 final long identity = Binder.clearCallingIdentity();
6154 try {
6155 final Phone phone = getPhone(subId);
6156 if (phone == null) {
6157 return null;
6158 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006159
Hall Liuf19c44f2018-11-27 14:38:17 -08006160 ServiceState ss = phone.getServiceState();
6161
6162 // Scrub out the location info in ServiceState depending on what level of access
6163 // the caller has.
6164 if (hasFinePermission) return ss;
6165 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6166 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006170 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006171
6172 /**
6173 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6174 *
6175 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6176 * voicemail ringtone.
6177 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6178 * PhoneAccount.
6179 */
6180 @Override
6181 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182 final long identity = Binder.clearCallingIdentity();
6183 try {
6184 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6185 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006186 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006187 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006189 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6190 } finally {
6191 Binder.restoreCallingIdentity(identity);
6192 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006193 }
6194
6195 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006196 * Sets the per-account voicemail ringtone.
6197 *
6198 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6199 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6200 *
6201 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6202 * voicemail ringtone.
6203 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6204 * PhoneAccount.
6205 */
6206 @Override
6207 public void setVoicemailRingtoneUri(String callingPackage,
6208 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006209 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006210 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006211 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6212 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6214 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6215 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006216 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006217
6218 final long identity = Binder.clearCallingIdentity();
6219 try {
6220 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6221 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006222 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006223 }
6224 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6225 } finally {
6226 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006227 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006228 }
6229
6230 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006231 * Returns whether vibration is set for voicemail notification in Phone settings.
6232 *
6233 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6234 * voicemail vibration setting.
6235 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6236 */
6237 @Override
6238 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 final long identity = Binder.clearCallingIdentity();
6240 try {
6241 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6242 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006243 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006244 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006246 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6247 } finally {
6248 Binder.restoreCallingIdentity(identity);
6249 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006250 }
6251
Youhan Wange64578a2016-05-02 15:32:42 -07006252 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006253 * Sets the per-account voicemail vibration.
6254 *
6255 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6256 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6257 *
6258 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6259 * voicemail vibration setting.
6260 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6261 * specific PhoneAccount.
6262 */
6263 @Override
6264 public void setVoicemailVibrationEnabled(String callingPackage,
6265 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006266 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006267 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006268 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6269 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6271 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6272 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006273 }
6274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275 final long identity = Binder.clearCallingIdentity();
6276 try {
6277 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6278 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006279 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 }
6281 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6282 } finally {
6283 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006284 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006285 }
6286
6287 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006288 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6289 *
6290 * @throws SecurityException if the caller does not have the required permission
6291 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006292 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006293 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006294 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006295 }
6296
6297 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006298 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6299 * permission.
6300 *
6301 * @throws SecurityException if the caller does not have the required permission
6302 */
6303 private void enforceSendSmsPermission() {
6304 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6305 }
6306
6307 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006308 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006309 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006310 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006311 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006312 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006313 final long identity = Binder.clearCallingIdentity();
6314 try {
6315 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006316 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317 if (componentName == null) {
6318 throw new SecurityException(
6319 "Caller not current active visual voicemail package[null]");
6320 }
6321 String vvmPackage = componentName.getPackageName();
6322 if (!callingPackage.equals(vvmPackage)) {
6323 throw new SecurityException("Caller not current active visual voicemail package["
6324 + vvmPackage + "]");
6325 }
6326 } finally {
6327 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006328 }
6329 }
6330
6331 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006332 * Return the application ID for the app type.
6333 *
6334 * @param subId the subscription ID that this request applies to.
6335 * @param appType the uicc app type.
6336 * @return Application ID for specificied app type, or null if no uicc.
6337 */
6338 @Override
6339 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006340 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006341 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342
6343 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006344 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 if (phone == null) {
6346 return null;
6347 }
6348 String aid = null;
6349 try {
6350 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6351 .getApplicationByType(appType).getAid();
6352 } catch (Exception e) {
6353 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6354 }
6355 return aid;
6356 } finally {
6357 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006358 }
Youhan Wange64578a2016-05-02 15:32:42 -07006359 }
6360
Youhan Wang4001d252016-05-11 10:29:41 -07006361 /**
6362 * Return the Electronic Serial Number.
6363 *
6364 * @param subId the subscription ID that this request applies to.
6365 * @return ESN or null if error.
6366 */
6367 @Override
6368 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006369 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006370 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371
6372 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006373 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374 if (phone == null) {
6375 return null;
6376 }
6377 String esn = null;
6378 try {
6379 esn = phone.getEsn();
6380 } catch (Exception e) {
6381 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6382 }
6383 return esn;
6384 } finally {
6385 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006386 }
Youhan Wang4001d252016-05-11 10:29:41 -07006387 }
6388
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006389 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006390 * Return the Preferred Roaming List Version.
6391 *
6392 * @param subId the subscription ID that this request applies to.
6393 * @return PRLVersion or null if error.
6394 */
6395 @Override
6396 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006397 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006398 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399
6400 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006401 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 if (phone == null) {
6403 return null;
6404 }
6405 String cdmaPrlVersion = null;
6406 try {
6407 cdmaPrlVersion = phone.getCdmaPrlVersion();
6408 } catch (Exception e) {
6409 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6410 }
6411 return cdmaPrlVersion;
6412 } finally {
6413 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006414 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006415 }
6416
6417 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006418 * Get snapshot of Telephony histograms
6419 * @return List of Telephony histograms
6420 * @hide
6421 */
6422 @Override
6423 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6425 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006426
6427 final long identity = Binder.clearCallingIdentity();
6428 try {
6429 return RIL.getTelephonyRILTimingHistograms();
6430 } finally {
6431 Binder.restoreCallingIdentity(identity);
6432 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006433 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006434
6435 /**
6436 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006437 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6438 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006439 * Require system privileges. In the future we may add this to carrier APIs.
6440 *
Michele Berionne482f8202018-11-27 18:57:59 -08006441 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006442 */
6443 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006444 @TelephonyManager.SetCarrierRestrictionResult
6445 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006446 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006447 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006448
Michele Berionne482f8202018-11-27 18:57:59 -08006449 if (carrierRestrictionRules == null) {
6450 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006451 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006453 final long identity = Binder.clearCallingIdentity();
6454 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006455 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006456 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006457 } finally {
6458 Binder.restoreCallingIdentity(identity);
6459 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006460 }
6461
6462 /**
6463 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006464 * Get the allowed carrier list and the excluded carrier list, including the priority between
6465 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006466 * Require system privileges. In the future we may add this to carrier APIs.
6467 *
Michele Berionne482f8202018-11-27 18:57:59 -08006468 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006469 */
6470 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006471 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006472 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006473 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006474
6475 final long identity = Binder.clearCallingIdentity();
6476 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006477 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6478 if (response instanceof CarrierRestrictionRules) {
6479 return (CarrierRestrictionRules) response;
6480 }
6481 // Response is an Exception of some kind,
6482 // which is signalled to the user as a NULL retval
6483 return null;
6484 } catch (Exception e) {
6485 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6486 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487 } finally {
6488 Binder.restoreCallingIdentity(identity);
6489 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006490 }
6491
fionaxu59545b42016-05-25 15:53:37 -07006492 /**
6493 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6494 * @param subId the subscription ID that this action applies to.
6495 * @param enabled control enable or disable metered apns.
6496 * {@hide}
6497 */
6498 @Override
6499 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6500 enforceModifyPermission();
6501 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006502
6503 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006504 if (phone == null) {
6505 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6506 return;
6507 }
6508 try {
6509 phone.carrierActionSetMeteredApnsEnabled(enabled);
6510 } catch (Exception e) {
6511 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006512 } finally {
6513 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006514 }
6515 }
6516
6517 /**
6518 * Action set from carrier signalling broadcast receivers to enable/disable radio
6519 * @param subId the subscription ID that this action applies to.
6520 * @param enabled control enable or disable radio.
6521 * {@hide}
6522 */
6523 @Override
6524 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6525 enforceModifyPermission();
6526 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006527
6528 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006529 if (phone == null) {
6530 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6531 return;
6532 }
6533 try {
6534 phone.carrierActionSetRadioEnabled(enabled);
6535 } catch (Exception e) {
6536 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006537 } finally {
6538 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006539 }
6540 }
6541
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006542 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006543 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6544 * network status based on which carrier apps could apply actions accordingly,
6545 * enable/disable default url handler for example.
6546 *
6547 * @param subId the subscription ID that this action applies to.
6548 * @param report control start/stop reporting the default network status.
6549 * {@hide}
6550 */
6551 @Override
6552 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6553 enforceModifyPermission();
6554 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555
6556 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006557 if (phone == null) {
6558 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6559 return;
6560 }
6561 try {
6562 phone.carrierActionReportDefaultNetworkStatus(report);
6563 } catch (Exception e) {
6564 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565 } finally {
6566 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006567 }
6568 }
6569
6570 /**
fionaxud9622282017-07-17 17:51:30 -07006571 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6572 * @param subId the subscription ID that this action applies to.
6573 * {@hide}
6574 */
6575 @Override
6576 public void carrierActionResetAll(int subId) {
6577 enforceModifyPermission();
6578 final Phone phone = getPhone(subId);
6579 if (phone == null) {
6580 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6581 return;
6582 }
6583 try {
6584 phone.carrierActionResetAll();
6585 } catch (Exception e) {
6586 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6587 }
6588 }
6589
6590 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006591 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6592 * bug report is being generated.
6593 */
6594 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006595 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006596 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6597 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006598 writer.println("Permission Denial: can't dump Phone from pid="
6599 + Binder.getCallingPid()
6600 + ", uid=" + Binder.getCallingUid()
6601 + "without permission "
6602 + android.Manifest.permission.DUMP);
6603 return;
6604 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006605 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006606 }
Jack Yueb89b242016-06-22 13:27:47 -07006607
Brad Ebingerdac2f002018-04-03 15:17:52 -07006608 @Override
6609 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6610 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6611 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006612 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6613 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006614 }
6615
Jack Yueb89b242016-06-22 13:27:47 -07006616 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006617 * Get aggregated video call data usage since boot.
6618 *
6619 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6620 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006621 * {@hide}
6622 */
6623 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006624 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006625 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6626 null);
6627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628 final long identity = Binder.clearCallingIdentity();
6629 try {
6630 // NetworkStatsService keeps tracking the active network interface and identity. It
6631 // records the delta with the corresponding network identity.
6632 // We just return the total video call data usage snapshot since boot.
6633 Phone phone = getPhone(subId);
6634 if (phone != null) {
6635 return phone.getVtDataUsage(perUidStats);
6636 }
6637 return null;
6638 } finally {
6639 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006640 }
Jack Yueb89b242016-06-22 13:27:47 -07006641 }
Jack Yu75ab2952016-07-08 14:29:33 -07006642
6643 /**
6644 * Policy control of data connection. Usually used when data limit is passed.
6645 * @param enabled True if enabling the data, otherwise disabling.
6646 * @param subId Subscription index
6647 * {@hide}
6648 */
6649 @Override
6650 public void setPolicyDataEnabled(boolean enabled, int subId) {
6651 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006652
6653 final long identity = Binder.clearCallingIdentity();
6654 try {
6655 Phone phone = getPhone(subId);
6656 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006657 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006658 }
6659 } finally {
6660 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006661 }
6662 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006663
6664 /**
6665 * Get Client request stats
6666 * @return List of Client Request Stats
6667 * @hide
6668 */
6669 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006670 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6671 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006672 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006673 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006674 return null;
6675 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006676 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006677
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006678 final long identity = Binder.clearCallingIdentity();
6679 try {
6680 if (phone != null) {
6681 return phone.getClientRequestStats();
6682 }
6683
6684 return null;
6685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006688 }
6689
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006690 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006691 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006692 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006693 }
Jack Yueb4124c2017-02-16 15:32:43 -08006694
6695 /**
Grace Chen70990072017-03-24 17:21:30 -07006696 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006697 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006698 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006699 * @param state State of SIM (power down, power up, pass through)
6700 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6701 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6702 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006703 *
6704 **/
6705 @Override
Grace Chen70990072017-03-24 17:21:30 -07006706 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006707 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006708 Phone phone = PhoneFactory.getPhone(slotIndex);
6709
vagdeviaf9a5b92018-08-15 16:01:53 -07006710 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6711
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 final long identity = Binder.clearCallingIdentity();
6713 try {
6714 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006715 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 }
6717 } finally {
6718 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006719 }
6720 }
Shuo Qiandd210312017-04-12 22:11:33 +00006721
Tyler Gunn65d45c22017-06-05 11:22:26 -07006722 private boolean isUssdApiAllowed(int subId) {
6723 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006724 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006725 if (configManager == null) {
6726 return false;
6727 }
6728 PersistableBundle pb = configManager.getConfigForSubId(subId);
6729 if (pb == null) {
6730 return false;
6731 }
6732 return pb.getBoolean(
6733 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6734 }
6735
Shuo Qiandd210312017-04-12 22:11:33 +00006736 /**
6737 * Check if phone is in emergency callback mode
6738 * @return true if phone is in emergency callback mode
6739 * @param subId sub id
6740 */
goneil9c5f4872017-12-05 14:07:56 -08006741 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006742 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006743 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006744 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745
6746 final long identity = Binder.clearCallingIdentity();
6747 try {
6748 if (phone != null) {
6749 return phone.isInEcm();
6750 } else {
6751 return false;
6752 }
6753 } finally {
6754 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006755 }
6756 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006757
6758 /**
6759 * Get the current signal strength information for the given subscription.
6760 * Because this information is not updated when the device is in a low power state
6761 * it should not be relied-upon to be current.
6762 * @param subId Subscription index
6763 * @return the most recent cached signal strength info from the modem
6764 */
6765 @Override
6766 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 final long identity = Binder.clearCallingIdentity();
6768 try {
6769 Phone p = getPhone(subId);
6770 if (p == null) {
6771 return null;
6772 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006774 return p.getSignalStrength();
6775 } finally {
6776 Binder.restoreCallingIdentity(identity);
6777 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006778 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006779
Pengquan Meng77b7f132018-08-22 14:49:57 -07006780 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006781 * Get the current modem radio state for the given slot.
6782 * @param slotIndex slot index.
6783 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006784 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006785 * @return the current radio power state from the modem
6786 */
6787 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006788 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006789 Phone phone = PhoneFactory.getPhone(slotIndex);
6790 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006791 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6792 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006793 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6794 }
6795
6796 final long identity = Binder.clearCallingIdentity();
6797 try {
6798 return phone.getRadioPowerState();
6799 } finally {
6800 Binder.restoreCallingIdentity(identity);
6801 }
6802 }
6803 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6804 }
6805
6806 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006807 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6808 *
6809 * <p>Requires one of the following permissions:
6810 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6811 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6812 * privileges.
6813 *
6814 * @param subId subscription id
6815 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6816 * {@code false}.
6817 */
6818 @Override
6819 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006820 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6821 null /* message */);
6822
Pengquan Menga1bb6272018-09-06 09:59:22 -07006823 boolean isEnabled = false;
6824 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006825 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006826 Phone phone = getPhone(subId);
6827 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006828 } catch (Exception e) {
6829 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6830 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006831 } finally {
6832 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006833 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006834 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006835 }
6836
6837
6838 /**
6839 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6840 *
6841 * <p> Requires permission:
6842 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6843 * privileges.
6844 *
6845 * @param subId subscription id
6846 * @param isEnabled {@code true} means enable, {@code false} means disable.
6847 */
6848 @Override
6849 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6851 mApp, subId, "setDataRoamingEnabled");
6852
Pengquan Menga1bb6272018-09-06 09:59:22 -07006853 final long identity = Binder.clearCallingIdentity();
6854 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006855 Phone phone = getPhone(subId);
6856 if (phone != null) {
6857 phone.setDataRoamingEnabled(isEnabled);
6858 }
6859 } finally {
6860 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006861 }
6862 }
6863
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006864 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006865 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006866 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6867 mApp, subId, "isManualNetworkSelectionAllowed");
6868
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006869 boolean isAllowed = true;
6870 final long identity = Binder.clearCallingIdentity();
6871 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006872 Phone phone = getPhone(subId);
6873 if (phone != null) {
6874 isAllowed = phone.isCspPlmnEnabled();
6875 }
6876 } finally {
6877 Binder.restoreCallingIdentity(identity);
6878 }
6879 return isAllowed;
6880 }
6881
6882 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006883 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006884 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006885 try {
6886 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006887 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006888 } catch (SecurityException e) {
6889 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6890 // has carrier privileges on an active UICC
6891 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6892 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006893 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006894 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006895 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006896
6897 final long identity = Binder.clearCallingIdentity();
6898 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006899 UiccController uiccController = UiccController.getInstance();
6900 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006901 if (hasReadPermission) {
6902 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006903 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006904
6905 // Remove private info if the caller doesn't have access
6906 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6907 for (UiccCardInfo cardInfo : cardInfos) {
6908 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6909 // is available
6910 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6911 if (card == null || card.getUiccProfile() == null) {
6912 // assume no access if the card or profile is unavailable
6913 filteredInfos.add(cardInfo.getUnprivileged());
6914 continue;
6915 }
6916 UiccProfile profile = card.getUiccProfile();
6917 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6918 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6919 filteredInfos.add(cardInfo);
6920 } else {
6921 filteredInfos.add(cardInfo.getUnprivileged());
6922 }
6923 }
6924 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006925 } finally {
6926 Binder.restoreCallingIdentity(identity);
6927 }
6928 }
6929
6930 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006931 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006932 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006934 final long identity = Binder.clearCallingIdentity();
6935 try {
6936 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6937 if (slots == null) {
6938 Rlog.i(LOG_TAG, "slots is null.");
6939 return null;
6940 }
6941
6942 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6943 for (int i = 0; i < slots.length; i++) {
6944 UiccSlot slot = slots[i];
6945 if (slot == null) {
6946 continue;
6947 }
6948
Jordan Liu7be7e652019-05-06 18:55:02 +00006949 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950 UiccCard card = slot.getUiccCard();
6951 if (card != null) {
6952 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006953 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006954 cardId = slot.getEid();
6955 if (TextUtils.isEmpty(cardId)) {
6956 cardId = slot.getIccId();
6957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006958 }
6959
Jordan Liu857451f2019-05-09 16:35:35 -07006960 if (cardId != null) {
6961 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6962 // if cardId is an EID, it's all digits so this is fine
6963 cardId = IccUtils.stripTrailingFs(cardId);
6964 }
6965
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006966 int cardState = 0;
6967 switch (slot.getCardState()) {
6968 case CARDSTATE_ABSENT:
6969 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6970 break;
6971 case CARDSTATE_PRESENT:
6972 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6973 break;
6974 case CARDSTATE_ERROR:
6975 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6976 break;
6977 case CARDSTATE_RESTRICTED:
6978 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6979 break;
6980 default:
6981 break;
6982
6983 }
6984
6985 infos[i] = new UiccSlotInfo(
6986 slot.isActive(),
6987 slot.isEuicc(),
6988 cardId,
6989 cardState,
6990 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006991 slot.isExtendedApduSupported(),
6992 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006993 }
6994 return infos;
6995 } finally {
6996 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006997 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006998 }
6999
7000 @Override
7001 public boolean switchSlots(int[] physicalSlots) {
7002 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003
7004 final long identity = Binder.clearCallingIdentity();
7005 try {
7006 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7007 } finally {
7008 Binder.restoreCallingIdentity(identity);
7009 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007010 }
Jack Yu4c988042018-02-27 15:30:01 -08007011
7012 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007013 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007014 final long identity = Binder.clearCallingIdentity();
7015 try {
7016 return UiccController.getInstance().getCardIdForDefaultEuicc();
7017 } finally {
7018 Binder.restoreCallingIdentity(identity);
7019 }
7020 }
7021
7022 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007023 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7024 enforceModifyPermission();
7025 final Phone phone = getPhone(subId);
7026 if (phone == null) {
7027 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7028 return;
7029 }
7030
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 final long identity = Binder.clearCallingIdentity();
7032 try {
7033 phone.setRadioIndicationUpdateMode(filters, mode);
7034 } finally {
7035 Binder.restoreCallingIdentity(identity);
7036 }
Jack Yu4c988042018-02-27 15:30:01 -08007037 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007038
7039 /**
goneil47ffb6e2018-04-06 15:40:58 -07007040 * A test API to reload the UICC profile.
7041 *
7042 * <p>Requires that the calling app has permission
7043 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7044 * @hide
7045 */
7046 @Override
7047 public void refreshUiccProfile(int subId) {
7048 enforceModifyPermission();
7049
7050 final long identity = Binder.clearCallingIdentity();
7051 try {
7052 Phone phone = getPhone(subId);
7053 if (phone == null) {
7054 return;
7055 }
7056 UiccCard uiccCard = phone.getUiccCard();
7057 if (uiccCard == null) {
7058 return;
7059 }
7060 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7061 if (uiccProfile == null) {
7062 return;
7063 }
7064 uiccProfile.refresh();
7065 } finally {
7066 Binder.restoreCallingIdentity(identity);
7067 }
7068 }
7069
7070 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007071 * Returns false if the mobile data is disabled by default, otherwise return true.
7072 */
7073 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007074 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007075 }
7076
7077 /**
7078 * Returns true if the data roaming is enabled by default, i.e the system property
7079 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7080 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7081 */
7082 private boolean getDefaultDataRoamingEnabled(int subId) {
7083 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007084 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007085 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007086 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7087 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7088 return isDataRoamingEnabled;
7089 }
7090
7091 /**
7092 * Returns the default network type for the given {@code subId}, if the default network type is
7093 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7094 */
7095 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007096 List<Integer> list = TelephonyProperties.default_network();
7097 int phoneId = mSubscriptionController.getPhoneId(subId);
7098 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7099 return list.get(phoneId);
7100 }
7101 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007102 }
fionaxua13278b2018-03-21 00:08:13 -07007103
7104 @Override
7105 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007106 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007107 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108
7109 final long identity = Binder.clearCallingIdentity();
7110 try {
7111 final Phone phone = getPhone(subId);
7112 if (phone == null) {
7113 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7114 return;
7115 }
chen xueaba88a2019-03-15 13:15:10 -07007116 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7117 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118 } finally {
7119 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007120 }
fionaxua13278b2018-03-21 00:08:13 -07007121 }
7122
7123 @Override
7124 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007125 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126
7127 final long identity = Binder.clearCallingIdentity();
7128 try {
7129 final Phone phone = getPhone(subId);
7130 if (phone == null) {
7131 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7132 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7133 }
7134 return phone.getCarrierIdListVersion();
7135 } finally {
7136 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007137 }
fionaxua13278b2018-03-21 00:08:13 -07007138 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007139
7140 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007141 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7142 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007144 mApp, subId, callingPackage, callingFeatureId,
7145 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007146 return -1;
7147 }
7148
7149 final long identity = Binder.clearCallingIdentity();
7150 try {
7151 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7152 } finally {
7153 Binder.restoreCallingIdentity(identity);
7154 }
7155 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007156
7157 @Override
7158 public int getCdmaRoamingMode(int subId) {
7159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7160 mApp, subId, "getCdmaRoamingMode");
7161
7162 final long identity = Binder.clearCallingIdentity();
7163 try {
7164 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7165 } finally {
7166 Binder.restoreCallingIdentity(identity);
7167 }
7168 }
7169
7170 @Override
7171 public boolean setCdmaRoamingMode(int subId, int mode) {
7172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7173 mApp, subId, "setCdmaRoamingMode");
7174
7175 final long identity = Binder.clearCallingIdentity();
7176 try {
7177 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7178 } finally {
7179 Binder.restoreCallingIdentity(identity);
7180 }
7181 }
7182
7183 @Override
7184 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7186 mApp, subId, "setCdmaSubscriptionMode");
7187
7188 final long identity = Binder.clearCallingIdentity();
7189 try {
7190 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7191 } finally {
7192 Binder.restoreCallingIdentity(identity);
7193 }
7194 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007195
sqianc5eccab2018-10-19 18:46:41 -07007196 @Override
sqian8c685422019-02-22 15:55:18 -08007197 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007198 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007199 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007200 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7201 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007202 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7203 }
7204 final long identity = Binder.clearCallingIdentity();
7205 try {
sqian854d44b2018-12-12 16:48:18 -08007206 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7207 for (Phone phone: PhoneFactory.getPhones()) {
7208 if (phone.getEmergencyNumberTracker() != null
7209 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7210 emergencyNumberListInternal.put(
7211 phone.getSubId(),
7212 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7213 }
sqian11b7a0e2018-12-05 18:48:28 -08007214 }
sqian854d44b2018-12-12 16:48:18 -08007215 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007216 } finally {
7217 Binder.restoreCallingIdentity(identity);
7218 }
sqianc5eccab2018-10-19 18:46:41 -07007219 }
7220
7221 @Override
sqian8c685422019-02-22 15:55:18 -08007222 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007223 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007224 if (!exactMatch) {
7225 TelephonyPermissions
7226 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007227 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007228 }
7229 final long identity = Binder.clearCallingIdentity();
7230 try {
sqian854d44b2018-12-12 16:48:18 -08007231 for (Phone phone: PhoneFactory.getPhones()) {
7232 if (phone.getEmergencyNumberTracker() != null
7233 && phone.getEmergencyNumberTracker() != null) {
7234 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7235 number, exactMatch)) {
7236 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007237 }
7238 }
sqian11b7a0e2018-12-05 18:48:28 -08007239 }
7240 return false;
7241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243 }
7244 }
7245
sqianf4ca7ed2019-01-15 18:32:07 -08007246 /**
7247 * Update emergency number list for test mode.
7248 */
7249 @Override
7250 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7251 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7252 "updateEmergencyNumberListTestMode");
7253
7254 final long identity = Binder.clearCallingIdentity();
7255 try {
7256 for (Phone phone: PhoneFactory.getPhones()) {
7257 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7258 if (tracker != null) {
7259 tracker.executeEmergencyNumberTestModeCommand(action, num);
7260 }
7261 }
7262 } finally {
7263 Binder.restoreCallingIdentity(identity);
7264 }
7265 }
7266
7267 /**
7268 * Get the full emergency number list for test mode.
7269 */
7270 @Override
7271 public List<String> getEmergencyNumberListTestMode() {
7272 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7273 "getEmergencyNumberListTestMode");
7274
7275 final long identity = Binder.clearCallingIdentity();
7276 try {
7277 Set<String> emergencyNumbers = new HashSet<>();
7278 for (Phone phone: PhoneFactory.getPhones()) {
7279 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7280 if (tracker != null) {
7281 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7282 emergencyNumbers.add(num.getNumber());
7283 }
7284 }
7285 }
7286 return new ArrayList<>(emergencyNumbers);
7287 } finally {
7288 Binder.restoreCallingIdentity(identity);
7289 }
7290 }
7291
chen xud6b45bd2018-10-30 22:27:10 -07007292 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007293 public int getEmergencyNumberDbVersion(int subId) {
7294 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7295
7296 final long identity = Binder.clearCallingIdentity();
7297 try {
7298 final Phone phone = getPhone(subId);
7299 if (phone == null) {
7300 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7301 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7302 }
7303 return phone.getEmergencyNumberDbVersion();
7304 } finally {
7305 Binder.restoreCallingIdentity(identity);
7306 }
7307 }
7308
7309 @Override
7310 public void notifyOtaEmergencyNumberDbInstalled() {
7311 enforceModifyPermission();
7312
7313 final long identity = Binder.clearCallingIdentity();
7314 try {
7315 for (Phone phone: PhoneFactory.getPhones()) {
7316 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7317 if (tracker != null) {
7318 tracker.updateOtaEmergencyNumberDatabase();
7319 }
7320 }
7321 } finally {
7322 Binder.restoreCallingIdentity(identity);
7323 }
7324 }
7325
7326 @Override
7327 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7328 enforceActiveEmergencySessionPermission();
7329
7330 final long identity = Binder.clearCallingIdentity();
7331 try {
7332 for (Phone phone: PhoneFactory.getPhones()) {
7333 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7334 if (tracker != null) {
7335 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7336 }
7337 }
7338 } finally {
7339 Binder.restoreCallingIdentity(identity);
7340 }
7341 }
7342
7343 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007344 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7345 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7346 Phone phone = getPhone(subId);
7347 if (phone == null) {
7348 return null;
7349 }
7350 final long identity = Binder.clearCallingIdentity();
7351 try {
7352 UiccProfile profile = UiccController.getInstance()
7353 .getUiccProfileForPhone(phone.getPhoneId());
7354 if (profile != null) {
7355 return profile.getCertsFromCarrierPrivilegeAccessRules();
7356 }
7357 } finally {
7358 Binder.restoreCallingIdentity(identity);
7359 }
7360 return null;
7361 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007362
7363 /**
7364 * Enable or disable a modem stack.
7365 */
7366 @Override
7367 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7368 enforceModifyPermission();
7369
7370 final long identity = Binder.clearCallingIdentity();
7371 try {
7372 Phone phone = PhoneFactory.getPhone(slotIndex);
7373 if (phone == null) {
7374 return false;
7375 } else {
7376 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7377 }
7378 } finally {
7379 Binder.restoreCallingIdentity(identity);
7380 }
7381 }
Michelecea4cf22018-12-21 15:00:11 -08007382
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007383 /**
7384 * Whether a modem stack is enabled or not.
7385 */
7386 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007387 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7388 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007389 Phone phone = PhoneFactory.getPhone(slotIndex);
7390 if (phone == null) return false;
7391
7392 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007393 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7394 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007395 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7396 }
7397
7398 final long identity = Binder.clearCallingIdentity();
7399 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007400 try {
7401 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7402 } catch (NoSuchElementException ex) {
7403 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7404 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007405 } finally {
7406 Binder.restoreCallingIdentity(identity);
7407 }
7408 }
7409
Michelecea4cf22018-12-21 15:00:11 -08007410 @Override
Michele0ea7d782019-03-19 14:58:42 -07007411 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007412 enforceModifyPermission();
7413
7414 final long identity = Binder.clearCallingIdentity();
7415 try {
7416 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007417 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007418 .commit();
7419 } finally {
7420 Binder.restoreCallingIdentity(identity);
7421 }
7422 }
7423
7424 @Override
Michele0ea7d782019-03-19 14:58:42 -07007425 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007426 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007427 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007428 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7429 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007430 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007431 }
Michelecea4cf22018-12-21 15:00:11 -08007432
7433 final long identity = Binder.clearCallingIdentity();
7434 try {
Michele0ea7d782019-03-19 14:58:42 -07007435 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007436 } finally {
7437 Binder.restoreCallingIdentity(identity);
7438 }
7439 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007440
Michele0ea7d782019-03-19 14:58:42 -07007441 @TelephonyManager.IsMultiSimSupportedResult
7442 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007443 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7444 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7445 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007446 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7447 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007448 }
7449 // Check if the hardware supports multisim functionality. If usage of multisim is not
7450 // supported by the modem, indicate that it is restricted.
7451 PhoneCapability staticCapability =
7452 mPhoneConfigurationManager.getStaticPhoneCapability();
7453 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007454 loge("isMultiSimSupportedInternal: no static configuration available");
7455 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007456 }
Sarah Chin7caee492020-02-18 20:49:02 +00007457 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007458 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7459 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007460 }
7461 // Check if support of multiple SIMs is restricted by carrier
7462 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007463 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007464 }
7465
Michele0ea7d782019-03-19 14:58:42 -07007466 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007467 }
7468
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007469 /**
7470 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007471 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7472 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7473 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007474 * @param numOfSims number of active sims we want to switch to
7475 */
7476 @Override
7477 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007478 if (numOfSims == 1) {
7479 enforceModifyPermission();
7480 } else {
7481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7482 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7483 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007484 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007485
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007486 try {
Michele30b57b22019-03-01 12:01:14 -08007487 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007488 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007489 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7490 return;
7491 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007492 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7493 } finally {
7494 Binder.restoreCallingIdentity(identity);
7495 }
7496 }
7497
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007498 @Override
7499 public boolean isApplicationOnUicc(int subId, int appType) {
7500 enforceReadPrivilegedPermission("isApplicationOnUicc");
7501 Phone phone = getPhone(subId);
7502 if (phone == null) {
7503 return false;
7504 }
7505 final long identity = Binder.clearCallingIdentity();
7506 try {
7507 UiccCard uiccCard = phone.getUiccCard();
7508 if (uiccCard == null) {
7509 return false;
7510 }
7511 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7512 if (uiccProfile == null) {
7513 return false;
7514 }
7515 if (TelephonyManager.APPTYPE_SIM <= appType
7516 && appType <= TelephonyManager.APPTYPE_ISIM) {
7517 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7518 }
7519 return false;
7520 } finally {
7521 Binder.restoreCallingIdentity(identity);
7522 }
7523 }
7524
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007525 /**
chen xub4baa772019-04-03 10:23:41 -07007526 * Get whether making changes to modem configurations will trigger reboot.
7527 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007528 */
7529 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007530 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7531 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007532 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007533 mApp, subId, callingPackage, callingFeatureId,
7534 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007535 return false;
7536 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007537 final long identity = Binder.clearCallingIdentity();
7538 try {
7539 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7540 } finally {
7541 Binder.restoreCallingIdentity(identity);
7542 }
7543 }
7544
Nathan Harold29f5f052019-02-15 13:41:57 -08007545 private void updateModemStateMetrics() {
7546 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7547 // TODO: check the state for each modem if the api is ready.
7548 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7549 }
7550
Pengquan Meng3889a572019-01-23 11:16:29 -08007551 @Override
7552 public int[] getSlotsMapping() {
7553 enforceReadPrivilegedPermission("getSlotsMapping");
7554
7555 final long identity = Binder.clearCallingIdentity();
7556 try {
7557 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7558 // All logical slots should have a mapping to a physical slot.
7559 int[] logicalSlotsMapping = new int[phoneCount];
7560 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7561 for (int i = 0; i < slotInfos.length; i++) {
7562 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7563 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7564 }
7565 }
7566 return logicalSlotsMapping;
7567 } finally {
7568 Binder.restoreCallingIdentity(identity);
7569 }
7570 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007571
7572 /**
7573 * Get the IRadio HAL Version
7574 */
7575 @Override
7576 public int getRadioHalVersion() {
7577 Phone phone = getDefaultPhone();
7578 if (phone == null) return -1;
7579 HalVersion hv = phone.getHalVersion();
7580 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7581 return hv.major * 100 + hv.minor;
7582 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007583
7584 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007585 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7586 * corresponding network requests on a subId.
7587 *
7588 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007589 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007590 * 2) APN is un-metered for this subscription, or
7591 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7592 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7593 *
7594 * @return whether data is allowed for a apn type.
7595 *
7596 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007597 */
7598 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007599 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007600 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7601 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007602
7603 // Now that all security checks passes, perform the operation as ourselves.
7604 final long identity = Binder.clearCallingIdentity();
7605 try {
7606 Phone phone = getPhone(subId);
7607 if (phone == null) return false;
7608
Jack Yu41407ee2019-05-13 16:54:09 -07007609 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007610 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7611 } finally {
7612 Binder.restoreCallingIdentity(identity);
7613 }
7614 }
7615
7616 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007617 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007618 enforceReadPrivilegedPermission("isApnMetered");
7619
7620 // Now that all security checks passes, perform the operation as ourselves.
7621 final long identity = Binder.clearCallingIdentity();
7622 try {
7623 Phone phone = getPhone(subId);
7624 if (phone == null) return true; // By default return true.
7625
Jack Yu41407ee2019-05-13 16:54:09 -07007626 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007627 } finally {
7628 Binder.restoreCallingIdentity(identity);
7629 }
7630 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007631
7632 @Override
7633 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
7705 /**
7706 * Updates whether conference event pacakge handling is enabled.
7707 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7708 * otherwise.
7709 */
7710 @Override
7711 public void setCepEnabled(boolean isCepEnabled) {
7712 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7713
7714 final long identity = Binder.clearCallingIdentity();
7715 try {
7716 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7717 for (Phone phone : PhoneFactory.getPhones()) {
7718 Phone defaultPhone = phone.getImsPhone();
7719 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7720 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7721 ImsPhoneCallTracker imsPhoneCallTracker =
7722 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7723 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7724 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7725 + imsPhone.getMsisdn());
7726 }
7727 }
7728 } finally {
7729 Binder.restoreCallingIdentity(identity);
7730 }
7731 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007732}