blob: 0be8b84c96ff1eb069872fce189635e106c8fb95 [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;
Pengquan Meng85728fb2018-03-12 16:31:21 -070055import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
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 Xuc7b18ec2019-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 zhaod698b842019-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 Ebinger774ba362019-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 Ebinger77b832e2019-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;
Taesu Leef8fbed92019-10-07 18:47:02 +0900159import 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 zhaod698b842019-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 Nalluri8ff344d2019-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
Pengquan Meng85728fb2018-03-12 16:31:21 -0700275 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
276 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
277 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
278
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700279 /** The singleton instance. */
280 private static PhoneInterfaceManager sInstance;
281
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800283 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700284 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private AppOpsManager mAppOps;
286 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800287 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800288 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700289 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
Derek Tan97ebb422014-09-05 16:55:38 -0700291 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
292 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800293 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800294 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700295
Michelecea4cf22018-12-21 15:00:11 -0800296 // String to store multi SIM allowed
297 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
298
Derek Tan740e1672017-06-27 14:56:27 -0700299 // The AID of ISD-R.
300 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
301
yinxub1bed742017-04-17 11:45:04 -0700302 private NetworkScanRequestTracker mNetworkScanRequestTracker;
303
David Kelly5e06a7f2018-03-12 14:10:59 +0000304 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
305 private static final int MANUFACTURER_CODE_LENGTH = 8;
306
Derek Tan89e89d42014-07-08 17:00:10 -0700307 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700308 * Experiment flag to enable erase modem config on reset network, default value is false
309 */
310 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
311 "reset_network_erase_modem_config_enabled";
312
313 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700314 * A request object to use for transmitting data to an ICC.
315 */
316 private static final class IccAPDUArgument {
317 public int channel, cla, command, p1, p2, p3;
318 public String data;
319
320 public IccAPDUArgument(int channel, int cla, int command,
321 int p1, int p2, int p3, String data) {
322 this.channel = channel;
323 this.cla = cla;
324 this.command = command;
325 this.p1 = p1;
326 this.p2 = p2;
327 this.p3 = p3;
328 this.data = data;
329 }
330 }
331
332 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700333 * A request object to use for transmitting data to an ICC.
334 */
335 private static final class ManualNetworkSelectionArgument {
336 public OperatorInfo operatorInfo;
337 public boolean persistSelection;
338
339 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
340 this.operatorInfo = operatorInfo;
341 this.persistSelection = persistSelection;
342 }
343 }
344
345 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
347 * request after sending. The main thread will notify the request when it is complete.
348 */
349 private static final class MainThreadRequest {
350 /** The argument to use for the request */
351 public Object argument;
352 /** The result of the request that is run on the main thread */
353 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800354 // The subscriber id that this request applies to. Defaults to
355 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
356 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
Nathan Harold92bed182018-10-12 18:16:49 -0700358 // In cases where subId is unavailable, the caller needs to specify the phone.
359 public Phone phone;
360
vagdeviaf9a5b92018-08-15 16:01:53 -0700361 public WorkSource workSource;
362
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 public MainThreadRequest(Object argument) {
364 this.argument = argument;
365 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800366
Nathan Harold92bed182018-10-12 18:16:49 -0700367 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
368 this.argument = argument;
369 if (phone != null) {
370 this.phone = phone;
371 }
372 this.workSource = workSource;
373 }
374
vagdeviaf9a5b92018-08-15 16:01:53 -0700375 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800376 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800377 if (subId != null) {
378 this.subId = subId;
379 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700380 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 }
383
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800384 private static final class IncomingThirdPartyCallArgs {
385 public final ComponentName component;
386 public final String callId;
387 public final String callerDisplayName;
388
389 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
390 String callerDisplayName) {
391 this.component = component;
392 this.callId = callId;
393 this.callerDisplayName = callerDisplayName;
394 }
395 }
396
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 /**
398 * A handler that processes messages on the main thread in the phone process. Since many
399 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
400 * inbound binder threads to the main thread in the phone process. The Binder thread
401 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
402 * on, which will be notified when the operation completes and will contain the result of the
403 * request.
404 *
405 * <p>If a MainThreadRequest object is provided in the msg.obj field,
406 * note that request.result must be set to something non-null for the calling thread to
407 * unblock.
408 */
409 private final class MainThreadHandler extends Handler {
410 @Override
411 public void handleMessage(Message msg) {
412 MainThreadRequest request;
413 Message onCompleted;
414 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800415 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800417 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418
419 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700420 case CMD_HANDLE_USSD_REQUEST: {
421 request = (MainThreadRequest) msg.obj;
422 final Phone phone = getPhoneFromRequest(request);
423 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
424 String ussdRequest = ussdObject.first;
425 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700426
Pengquan Menga1bb6272018-09-06 09:59:22 -0700427 if (!isUssdApiAllowed(request.subId)) {
428 // Carrier does not support use of this API, return failure.
429 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
430 UssdResponse response = new UssdResponse(ussdRequest, null);
431 Bundle returnData = new Bundle();
432 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
433 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700434
Pengquan Menga1bb6272018-09-06 09:59:22 -0700435 request.result = true;
436 notifyRequester(request);
437 return;
438 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700439
Pengquan Menga1bb6272018-09-06 09:59:22 -0700440 try {
441 request.result = phone != null
442 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
443 } catch (CallStateException cse) {
444 request.result = false;
445 }
446 // Wake up the requesting thread
447 notifyRequester(request);
448 break;
pkanwar32d516d2016-10-14 19:37:38 -0700449 }
450
Yorke Lee716f67e2015-06-17 15:39:16 -0700451 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700453 final Phone phone = getPhoneFromRequest(request);
454 request.result = phone != null ?
455 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
456 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700458 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700461
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800465 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 if (uiccCard == null) {
467 loge("iccTransmitApduLogicalChannel: No UICC");
468 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700469 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700470 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
472 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700473 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700474 iccArgument.channel, iccArgument.cla, iccArgument.command,
475 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700477 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 break;
479
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 ar = (AsyncResult) msg.obj;
482 request = (MainThreadRequest) ar.userObj;
483 if (ar.exception == null && ar.result != null) {
484 request.result = ar.result;
485 } else {
486 request.result = new IccIoResult(0x6F, 0, (byte[])null);
487 if (ar.result == null) {
488 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800489 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800491 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700492 } else {
493 loge("iccTransmitApduLogicalChannel: Unknown exception");
494 }
495 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 break;
498
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
500 request = (MainThreadRequest) msg.obj;
501 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800502 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 if (uiccCard == null) {
504 loge("iccTransmitApduBasicChannel: No UICC");
505 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700506 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 } else {
508 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
509 request);
510 uiccCard.iccTransmitApduBasicChannel(
511 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
512 iccArgument.p3, iccArgument.data, onCompleted);
513 }
514 break;
515
516 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
517 ar = (AsyncResult) msg.obj;
518 request = (MainThreadRequest) ar.userObj;
519 if (ar.exception == null && ar.result != null) {
520 request.result = ar.result;
521 } else {
522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
523 if (ar.result == null) {
524 loge("iccTransmitApduBasicChannel: Empty response");
525 } else if (ar.exception instanceof CommandException) {
526 loge("iccTransmitApduBasicChannel: CommandException: " +
527 ar.exception);
528 } else {
529 loge("iccTransmitApduBasicChannel: Unknown exception");
530 }
531 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 break;
534
535 case CMD_EXCHANGE_SIM_IO:
536 request = (MainThreadRequest) msg.obj;
537 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800538 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 if (uiccCard == null) {
540 loge("iccExchangeSimIO: No UICC");
541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 } else {
544 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
545 request);
546 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
547 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
548 iccArgument.data, onCompleted);
549 }
550 break;
551
552 case EVENT_EXCHANGE_SIM_IO_DONE:
553 ar = (AsyncResult) msg.obj;
554 request = (MainThreadRequest) ar.userObj;
555 if (ar.exception == null && ar.result != null) {
556 request.result = ar.result;
557 } else {
558 request.result = new IccIoResult(0x6f, 0, (byte[])null);
559 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 break;
562
Derek Tan4d5e5c12014-02-04 11:54:58 -0800563 case CMD_SEND_ENVELOPE:
564 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 if (uiccCard == null) {
567 loge("sendEnvelopeWithStatus: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
572 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
573 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800574 break;
575
576 case EVENT_SEND_ENVELOPE_DONE:
577 ar = (AsyncResult) msg.obj;
578 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700579 if (ar.exception == null && ar.result != null) {
580 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800581 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700582 request.result = new IccIoResult(0x6F, 0, (byte[])null);
583 if (ar.result == null) {
584 loge("sendEnvelopeWithStatus: Empty response");
585 } else if (ar.exception instanceof CommandException) {
586 loge("sendEnvelopeWithStatus: CommandException: " +
587 ar.exception);
588 } else {
589 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
590 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800591 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800593 break;
594
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 case CMD_OPEN_CHANNEL:
596 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800597 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800598 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 if (uiccCard == null) {
600 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800601 request.result = new IccOpenLogicalChannelResponse(-1,
602 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700603 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 } else {
605 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800606 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
607 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700608 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 break;
610
611 case EVENT_OPEN_CHANNEL_DONE:
612 ar = (AsyncResult) msg.obj;
613 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 int[] result = (int[]) ar.result;
617 int channelId = result[0];
618 byte[] selectResponse = null;
619 if (result.length > 1) {
620 selectResponse = new byte[result.length - 1];
621 for (int i = 1; i < result.length; ++i) {
622 selectResponse[i - 1] = (byte) result[i];
623 }
624 }
625 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 if (ar.result == null) {
629 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 if (ar.exception != null) {
632 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
633 }
634
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700635 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700636 if (ar.exception instanceof CommandException) {
637 CommandException.Error error =
638 ((CommandException) (ar.exception)).getCommandError();
639 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700640 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700641 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700642 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 }
644 }
645 openChannelResp = new IccOpenLogicalChannelResponse(
646 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700648 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700649 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
652 case CMD_CLOSE_CHANNEL:
653 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800654 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 if (uiccCard == null) {
656 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900657 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 } else {
660 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
661 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
662 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 break;
664
665 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800666 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
667 break;
668
669 case CMD_NV_READ_ITEM:
670 request = (MainThreadRequest) msg.obj;
671 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800672 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
673 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800674 break;
675
676 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800682 request.result = "";
683 if (ar.result == null) {
684 loge("nvReadItem: Empty response");
685 } else if (ar.exception instanceof CommandException) {
686 loge("nvReadItem: CommandException: " +
687 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800689 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 }
691 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700692 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 break;
694
Jake Hambye994d462014-02-03 13:10:13 -0800695 case CMD_NV_WRITE_ITEM:
696 request = (MainThreadRequest) msg.obj;
697 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
698 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800699 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700700 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
703 case EVENT_NV_WRITE_ITEM_DONE:
704 handleNullReturnEvent(msg, "nvWriteItem");
705 break;
706
707 case CMD_NV_WRITE_CDMA_PRL:
708 request = (MainThreadRequest) msg.obj;
709 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800710 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800711 break;
712
713 case EVENT_NV_WRITE_CDMA_PRL_DONE:
714 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
715 break;
716
chen xu6dac5ab2018-10-26 17:39:23 -0700717 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800718 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700719 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800720 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800721 break;
722
chen xu6dac5ab2018-10-26 17:39:23 -0700723 case EVENT_RESET_MODEM_CONFIG_DONE:
724 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800725 break;
726
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 case CMD_GET_PREFERRED_NETWORK_TYPE:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700730 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 break;
732
733 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
734 ar = (AsyncResult) msg.obj;
735 request = (MainThreadRequest) ar.userObj;
736 if (ar.exception == null && ar.result != null) {
737 request.result = ar.result; // Integer
738 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800739 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800740 if (ar.result == null) {
741 loge("getPreferredNetworkType: Empty response");
742 } else if (ar.exception instanceof CommandException) {
743 loge("getPreferredNetworkType: CommandException: " +
744 ar.exception);
745 } else {
746 loge("getPreferredNetworkType: Unknown exception");
747 }
748 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800750 break;
751
752 case CMD_SET_PREFERRED_NETWORK_TYPE:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
755 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700756 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800757 break;
758
759 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
760 handleNullReturnEvent(msg, "setPreferredNetworkType");
761 break;
762
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000763 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
764 request = (MainThreadRequest)msg.obj;
765 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800766 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000767 break;
768
769 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
770 ar = (AsyncResult)msg.obj;
771 request = (MainThreadRequest)ar.userObj;
772 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000774 break;
775
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800776 case CMD_SET_VOICEMAIL_NUMBER:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
779 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800780 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
781 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800782 break;
783
784 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
785 handleNullReturnEvent(msg, "setVoicemailNumber");
786 break;
787
Stuart Scott54788802015-03-30 13:18:01 -0700788 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
789 request = (MainThreadRequest) msg.obj;
790 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
791 request);
792 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
793 break;
794
795 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
796 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
797 break;
798
Shishir Agrawal302c8692015-06-19 13:49:39 -0700799 case CMD_PERFORM_NETWORK_SCAN:
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
802 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
803 break;
804
805 case EVENT_PERFORM_NETWORK_SCAN_DONE:
806 ar = (AsyncResult) msg.obj;
807 request = (MainThreadRequest) ar.userObj;
808 CellNetworkScanResult cellScanResult;
809 if (ar.exception == null && ar.result != null) {
810 cellScanResult = new CellNetworkScanResult(
811 CellNetworkScanResult.STATUS_SUCCESS,
812 (List<OperatorInfo>) ar.result);
813 } else {
814 if (ar.result == null) {
815 loge("getCellNetworkScanResults: Empty response");
816 }
817 if (ar.exception != null) {
818 loge("getCellNetworkScanResults: Exception: " + ar.exception);
819 }
820 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
821 if (ar.exception instanceof CommandException) {
822 CommandException.Error error =
823 ((CommandException) (ar.exception)).getCommandError();
824 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
825 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
826 } else if (error == CommandException.Error.GENERIC_FAILURE) {
827 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
828 }
829 }
830 cellScanResult = new CellNetworkScanResult(errorCode, null);
831 }
832 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700833 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700834 break;
835
836 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
837 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700838 ManualNetworkSelectionArgument selArg =
839 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
841 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700842 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
843 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700844 break;
845
846 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
849 if (ar.exception == null) {
850 request.result = true;
851 } else {
852 request.result = false;
853 loge("setNetworkSelectionModeManual " + ar.exception);
854 }
855 notifyRequester(request);
856 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700857 break;
858
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700859 case CMD_GET_MODEM_ACTIVITY_INFO:
860 request = (MainThreadRequest) msg.obj;
861 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700862 if (defaultPhone != null) {
863 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
864 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700865 break;
866
867 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
868 ar = (AsyncResult) msg.obj;
869 request = (MainThreadRequest) ar.userObj;
870 if (ar.exception == null && ar.result != null) {
871 request.result = ar.result;
872 } else {
873 if (ar.result == null) {
874 loge("queryModemActivityInfo: Empty response");
875 } else if (ar.exception instanceof CommandException) {
876 loge("queryModemActivityInfo: CommandException: " +
877 ar.exception);
878 } else {
879 loge("queryModemActivityInfo: Unknown exception");
880 }
881 }
Amit Mahajand4766222016-01-28 15:28:28 -0800882 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
883 if (request.result == null) {
884 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
885 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700886 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700887 break;
888
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 case CMD_SET_ALLOWED_CARRIERS:
890 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800891 CarrierRestrictionRules argument =
892 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700893 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800894 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700895 break;
896
897 case EVENT_SET_ALLOWED_CARRIERS_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null && ar.result != null) {
901 request.result = ar.result;
902 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800903 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
904 if (ar.exception instanceof CommandException) {
905 loge("setAllowedCarriers: CommandException: " + ar.exception);
906 CommandException.Error error =
907 ((CommandException) (ar.exception)).getCommandError();
908 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
909 request.result =
910 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
911 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700912 } else {
913 loge("setAllowedCarriers: Unknown exception");
914 }
915 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700916 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700917 break;
918
919 case CMD_GET_ALLOWED_CARRIERS:
920 request = (MainThreadRequest) msg.obj;
921 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800922 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700923 break;
924
925 case EVENT_GET_ALLOWED_CARRIERS_DONE:
926 ar = (AsyncResult) msg.obj;
927 request = (MainThreadRequest) ar.userObj;
928 if (ar.exception == null && ar.result != null) {
929 request.result = ar.result;
930 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800931 request.result = new IllegalStateException(
932 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700933 if (ar.result == null) {
934 loge("getAllowedCarriers: Empty response");
935 } else if (ar.exception instanceof CommandException) {
936 loge("getAllowedCarriers: CommandException: " +
937 ar.exception);
938 } else {
939 loge("getAllowedCarriers: Unknown exception");
940 }
941 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700942 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700943 break;
944
Nathan Haroldb3014052017-01-25 15:57:32 -0800945 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
946 ar = (AsyncResult) msg.obj;
947 request = (MainThreadRequest) ar.userObj;
948 if (ar.exception == null && ar.result != null) {
949 request.result = ar.result;
950 } else {
951 request.result = new IllegalArgumentException(
952 "Failed to retrieve Forbidden Plmns");
953 if (ar.result == null) {
954 loge("getForbiddenPlmns: Empty response");
955 } else {
956 loge("getForbiddenPlmns: Unknown exception");
957 }
958 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700959 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800960 break;
961
962 case CMD_GET_FORBIDDEN_PLMNS:
963 request = (MainThreadRequest) msg.obj;
964 uiccCard = getUiccCardFromRequest(request);
965 if (uiccCard == null) {
966 loge("getForbiddenPlmns() UiccCard is null");
967 request.result = new IllegalArgumentException(
968 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700969 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800970 break;
971 }
972 Integer appType = (Integer) request.argument;
973 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
974 if (uiccApp == null) {
975 loge("getForbiddenPlmns() no app with specified type -- "
976 + appType);
977 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700978 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800979 break;
980 } else {
981 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
982 + " specified type -- " + appType);
983 }
984 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
985 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
986 onCompleted);
987 break;
988
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000989 case CMD_SWITCH_SLOTS:
990 request = (MainThreadRequest) msg.obj;
991 int[] physicalSlots = (int[]) request.argument;
992 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
993 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
994 break;
995
996 case EVENT_SWITCH_SLOTS_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001000 notifyRequester(request);
1001 break;
1002 case CMD_GET_NETWORK_SELECTION_MODE:
1003 request = (MainThreadRequest) msg.obj;
1004 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1005 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1006 break;
1007
1008 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
1011 if (ar.exception != null) {
1012 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1013 } else {
1014 int mode = ((int[]) ar.result)[0];
1015 if (mode == 0) {
1016 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1017 } else {
1018 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1019 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001020 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001021 notifyRequester(request);
1022 break;
1023 case CMD_GET_CDMA_ROAMING_MODE:
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1026 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1027 break;
1028 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 if (ar.exception != null) {
1032 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1033 } else {
1034 request.result = ((int[]) ar.result)[0];
1035 }
1036 notifyRequester(request);
1037 break;
1038 case CMD_SET_CDMA_ROAMING_MODE:
1039 request = (MainThreadRequest) msg.obj;
1040 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1041 int mode = (int) request.argument;
1042 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1043 break;
1044 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
1047 request.result = ar.exception == null;
1048 notifyRequester(request);
1049 break;
1050 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1053 int subscriptionMode = (int) request.argument;
1054 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1055 break;
1056 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1057 ar = (AsyncResult) msg.obj;
1058 request = (MainThreadRequest) ar.userObj;
1059 request.result = ar.exception == null;
1060 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001061 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 case CMD_GET_ALL_CELL_INFO:
1063 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001065 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001067 case EVENT_GET_ALL_CELL_INFO_DONE:
1068 ar = (AsyncResult) msg.obj;
1069 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001070 // If a timeout occurs, the response will be null
1071 request.result = (ar.exception == null && ar.result != null)
1072 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001073 synchronized (request) {
1074 request.notifyAll();
1075 }
1076 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001077 case CMD_REQUEST_CELL_INFO_UPDATE:
1078 request = (MainThreadRequest) msg.obj;
1079 request.phone.requestCellInfoUpdate(request.workSource,
1080 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1081 break;
1082 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1083 ar = (AsyncResult) msg.obj;
1084 request = (MainThreadRequest) ar.userObj;
1085 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1086 try {
1087 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001088 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001089 cb.onError(
1090 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1091 ar.exception.getClass().getName(),
1092 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001094 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001095 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001096 } else {
1097 // use the result as returned
1098 cb.onCellInfo((List<CellInfo>) ar.result);
1099 }
1100 } catch (RemoteException re) {
1101 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1102 }
1103 break;
1104 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001105 request = (MainThreadRequest) msg.obj;
1106 WorkSource ws = (WorkSource) request.argument;
1107 Phone phone = getPhoneFromRequest(request);
1108 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1109 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001110 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001111 ar = (AsyncResult) msg.obj;
1112 request = (MainThreadRequest) ar.userObj;
1113 if (ar.exception == null) {
1114 request.result = ar.result;
1115 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001116 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001117 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1118 ? new CdmaCellLocation() : new GsmCellLocation();
1119 }
1120
1121 synchronized (request) {
1122 request.notifyAll();
1123 }
1124 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001125 case CMD_MODEM_REBOOT:
1126 request = (MainThreadRequest) msg.obj;
1127 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001128 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001129 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001130 case EVENT_CMD_MODEM_REBOOT_DONE:
1131 handleNullReturnEvent(msg, "rebootModem");
1132 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001133 case CMD_REQUEST_ENABLE_MODEM:
1134 request = (MainThreadRequest) msg.obj;
1135 boolean enable = (boolean) request.argument;
1136 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001137 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001138 PhoneConfigurationManager.getInstance()
1139 .enablePhone(request.phone, enable, onCompleted);
1140 break;
1141 case EVENT_ENABLE_MODEM_DONE:
1142 ar = (AsyncResult) msg.obj;
1143 request = (MainThreadRequest) ar.userObj;
1144 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001145 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001146 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001147 if ((boolean) request.result) {
1148 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1149 updateModemStateMetrics();
1150 } else {
1151 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1152 + ar.exception);
1153 }
1154 notifyRequester(request);
1155 break;
1156 case CMD_GET_MODEM_STATUS:
1157 request = (MainThreadRequest) msg.obj;
1158 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1159 PhoneConfigurationManager.getInstance()
1160 .getPhoneStatusFromModem(request.phone, onCompleted);
1161 break;
1162 case EVENT_GET_MODEM_STATUS_DONE:
1163 ar = (AsyncResult) msg.obj;
1164 request = (MainThreadRequest) ar.userObj;
1165 int id = request.phone.getPhoneId();
1166 if (ar.exception == null && ar.result != null) {
1167 request.result = ar.result;
1168 //update the cache as modem status has changed
1169 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1170 (boolean) request.result);
1171 } else {
1172 // Return true if modem status cannot be retrieved. For most cases,
1173 // modem status is on. And for older version modems, GET_MODEM_STATUS
1174 // and disable modem are not supported. Modem is always on.
1175 // TODO: this should be fixed in R to support a third
1176 // status UNKNOWN b/131631629
1177 request.result = true;
1178 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1179 + ar.exception);
1180 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001181 notifyRequester(request);
1182 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001183 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1184 ar = (AsyncResult) msg.obj;
1185 request = (MainThreadRequest) ar.userObj;
1186 if (ar.exception == null && ar.result != null) {
1187 request.result = ar.result;
1188 } else {
1189 request.result = -1;
1190 loge("Failed to set Forbidden Plmns");
1191 if (ar.result == null) {
1192 loge("setForbidenPlmns: Empty response");
1193 } else if (ar.exception != null) {
1194 loge("setForbiddenPlmns: Exception: " + ar.exception);
1195 request.result = -1;
1196 } else {
1197 loge("setForbiddenPlmns: Unknown exception");
1198 }
1199 }
1200 notifyRequester(request);
1201 break;
1202 case CMD_SET_FORBIDDEN_PLMNS:
1203 request = (MainThreadRequest) msg.obj;
1204 uiccCard = getUiccCardFromRequest(request);
1205 if (uiccCard == null) {
1206 loge("setForbiddenPlmns: UiccCard is null");
1207 request.result = -1;
1208 notifyRequester(request);
1209 break;
1210 }
1211 Pair<Integer, List<String>> setFplmnsArgs =
1212 (Pair<Integer, List<String>>) request.argument;
1213 appType = setFplmnsArgs.first;
1214 List<String> fplmns = setFplmnsArgs.second;
1215 uiccApp = uiccCard.getApplicationByType(appType);
1216 if (uiccApp == null) {
1217 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1218 request.result = -1;
1219 loge("Failed to get UICC App");
1220 notifyRequester(request);
1221 } else {
1222 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1223 ((SIMRecords) uiccApp.getIccRecords())
1224 .setForbiddenPlmns(onCompleted, fplmns);
1225 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001226 case CMD_ERASE_MODEM_CONFIG:
1227 request = (MainThreadRequest) msg.obj;
1228 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1229 defaultPhone.eraseModemConfig(onCompleted);
1230 break;
1231 case EVENT_ERASE_MODEM_CONFIG_DONE:
1232 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001233 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 default:
1235 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1236 break;
1237 }
1238 }
Jake Hambye994d462014-02-03 13:10:13 -08001239
Pengquan Menga1bb6272018-09-06 09:59:22 -07001240 private void notifyRequester(MainThreadRequest request) {
1241 synchronized (request) {
1242 request.notifyAll();
1243 }
1244 }
1245
Jake Hambye994d462014-02-03 13:10:13 -08001246 private void handleNullReturnEvent(Message msg, String command) {
1247 AsyncResult ar = (AsyncResult) msg.obj;
1248 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1249 if (ar.exception == null) {
1250 request.result = true;
1251 } else {
1252 request.result = false;
1253 if (ar.exception instanceof CommandException) {
1254 loge(command + ": CommandException: " + ar.exception);
1255 } else {
1256 loge(command + ": Unknown exception");
1257 }
1258 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001259 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 }
1262
1263 /**
1264 * Posts the specified command to be executed on the main thread,
1265 * waits for the request to complete, and returns the result.
1266 * @see #sendRequestAsync
1267 */
1268 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001269 return sendRequest(
1270 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001271 }
1272
1273 /**
1274 * Posts the specified command to be executed on the main thread,
1275 * waits for the request to complete, and returns the result.
1276 * @see #sendRequestAsync
1277 */
1278 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1279 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001280 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001281 }
1282
1283 /**
1284 * Posts the specified command to be executed on the main thread,
1285 * waits for the request to complete, and returns the result.
1286 * @see #sendRequestAsync
1287 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001288 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001289 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001290 }
1291
1292 /**
1293 * Posts the specified command to be executed on the main thread,
1294 * waits for the request to complete, and returns the result.
1295 * @see #sendRequestAsync
1296 */
Nathan Harold92bed182018-10-12 18:16:49 -07001297 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1298 return sendRequest(command, argument, subId, null, workSource);
1299 }
1300
1301 /**
1302 * Posts the specified command to be executed on the main thread,
1303 * waits for the request to complete, and returns the result.
1304 * @see #sendRequestAsync
1305 */
1306 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1307 return sendRequest(
1308 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1309 }
1310
1311 /**
1312 * Posts the specified command to be executed on the main thread,
1313 * waits for the request to complete, and returns the result.
1314 * @see #sendRequestAsync
1315 */
1316 private Object sendRequest(
1317 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1319 throw new RuntimeException("This method will deadlock if called from the main thread.");
1320 }
1321
Nathan Harold92bed182018-10-12 18:16:49 -07001322 MainThreadRequest request = null;
1323 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1324 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1325 } else if (phone != null) {
1326 request = new MainThreadRequest(argument, phone, workSource);
1327 } else {
1328 request = new MainThreadRequest(argument, subId, workSource);
1329 }
1330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 Message msg = mMainThreadHandler.obtainMessage(command, request);
1332 msg.sendToTarget();
1333
1334 // Wait for the request to complete
1335 synchronized (request) {
1336 while (request.result == null) {
1337 try {
1338 request.wait();
1339 } catch (InterruptedException e) {
1340 // Do nothing, go back and wait until the request is complete
1341 }
1342 }
1343 }
1344 return request.result;
1345 }
1346
1347 /**
1348 * Asynchronous ("fire and forget") version of sendRequest():
1349 * Posts the specified command to be executed on the main thread, and
1350 * returns immediately.
1351 * @see #sendRequest
1352 */
1353 private void sendRequestAsync(int command) {
1354 mMainThreadHandler.sendEmptyMessage(command);
1355 }
1356
1357 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001358 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001360 */
1361 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001362 sendRequestAsync(command, argument, null, null);
1363 }
1364
1365 /**
1366 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1367 * @see {@link #sendRequest(int,Object)}
1368 */
1369 private void sendRequestAsync(
1370 int command, Object argument, Phone phone, WorkSource workSource) {
1371 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001372 Message msg = mMainThreadHandler.obtainMessage(command, request);
1373 msg.sendToTarget();
1374 }
1375
1376 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 * Initialize the singleton PhoneInterfaceManager instance.
1378 * This is only done once, at startup, from PhoneApp.onCreate().
1379 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001380 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 synchronized (PhoneInterfaceManager.class) {
1382 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001383 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 } else {
1385 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1386 }
1387 return sInstance;
1388 }
1389 }
1390
1391 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001392 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001395 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1397 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001398 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001399 mTelephonySharedPreferences =
1400 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001401 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001402 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001403
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 publish();
1405 }
1406
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001407 private Phone getDefaultPhone() {
1408 Phone thePhone = getPhone(getDefaultSubscription());
1409 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1410 }
1411
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 private void publish() {
1413 if (DBG) log("publish: " + this);
1414
1415 ServiceManager.addService("phone", this);
1416 }
1417
Stuart Scott584921c2015-01-15 17:10:34 -08001418 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001419 if (request.phone != null) {
1420 return request.phone;
1421 } else {
1422 return getPhoneFromSubId(request.subId);
1423 }
1424 }
1425
1426 private Phone getPhoneFromSubId(int subId) {
1427 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1428 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001429 }
1430
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001431 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1432 Phone phone = getPhoneFromRequest(request);
1433 return phone == null ? null :
1434 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1435 }
1436
Wink Saville36469e72014-06-11 15:17:00 -07001437 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001438 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001439 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001442 private void sendEraseModemConfig(Phone phone) {
1443 if (phone != null) {
1444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1445 mApp, phone.getSubId(), "eraseModemConfig");
1446 final long identity = Binder.clearCallingIdentity();
1447 try {
1448 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1449 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1450 } finally {
1451 Binder.restoreCallingIdentity(identity);
1452 }
1453 }
1454 }
1455
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001457 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001458 }
1459
Wink Savilleb564aae2014-10-23 10:18:09 -07001460 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 if (DBG) log("dial: " + number);
1462 // No permission check needed here: This is just a wrapper around the
1463 // ACTION_DIAL intent, which is available to any app since it puts up
1464 // the UI before it does anything.
1465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001466 final long identity = Binder.clearCallingIdentity();
1467 try {
1468 String url = createTelUrl(number);
1469 if (url == null) {
1470 return;
1471 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001473 // PENDING: should we just silently fail if phone is offhook or ringing?
1474 PhoneConstants.State state = mCM.getState(subId);
1475 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1476 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1477 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1478 mApp.startActivity(intent);
1479 }
1480 } finally {
1481 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 }
1483 }
1484
1485 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001486 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001487 }
1488
Wink Savilleb564aae2014-10-23 10:18:09 -07001489 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 if (DBG) log("call: " + number);
1491
1492 // This is just a wrapper around the ACTION_CALL intent, but we still
1493 // need to do a permission check since we're calling startActivity()
1494 // from the context of the phone app.
1495 enforceCallPermission();
1496
Jordan Liu1617b712019-07-10 15:06:26 -07001497 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 != AppOpsManager.MODE_ALLOWED) {
1499 return;
1500 }
1501
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001502 final long identity = Binder.clearCallingIdentity();
1503 try {
1504 String url = createTelUrl(number);
1505 if (url == null) {
1506 return;
1507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001509 boolean isValid = false;
1510 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1511 if (slist != null) {
1512 for (SubscriptionInfo subInfoRecord : slist) {
1513 if (subInfoRecord.getSubscriptionId() == subId) {
1514 isValid = true;
1515 break;
1516 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001517 }
Wink Saville08874612014-08-31 19:19:58 -07001518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001519 if (!isValid) {
1520 return;
1521 }
Wink Saville08874612014-08-31 19:19:58 -07001522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001523 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1524 intent.putExtra(SUBSCRIPTION_KEY, subId);
1525 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1526 mApp.startActivity(intent);
1527 } finally {
1528 Binder.restoreCallingIdentity(identity);
1529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 }
1531
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001533 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001534 }
1535
Wink Savilleb564aae2014-10-23 10:18:09 -07001536 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001537 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001538 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1539 }
1540
1541 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001542 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001543 }
1544
Wink Savilleb564aae2014-10-23 10:18:09 -07001545 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001546 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001547 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1548 }
1549
1550 /** {@hide} */
1551 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001552 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001553 }
1554
Wink Savilleb564aae2014-10-23 10:18:09 -07001555 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001557
1558 final long identity = Binder.clearCallingIdentity();
1559 try {
1560 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1561 checkSimPin.start();
1562 return checkSimPin.unlockSim(null, pin);
1563 } finally {
1564 Binder.restoreCallingIdentity(identity);
1565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 }
1567
Wink Saville9de0f752013-10-22 19:04:03 -07001568 /** {@hide} */
1569 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001570 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001571 }
1572
Wink Savilleb564aae2014-10-23 10:18:09 -07001573 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001575
1576 final long identity = Binder.clearCallingIdentity();
1577 try {
1578 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1579 checkSimPuk.start();
1580 return checkSimPuk.unlockSim(puk, pin);
1581 } finally {
1582 Binder.restoreCallingIdentity(identity);
1583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001584 }
1585
1586 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001587 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001588 * a synchronous one.
1589 */
1590 private static class UnlockSim extends Thread {
1591
1592 private final IccCard mSimCard;
1593
1594 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001595 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1596 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597
1598 // For replies from SimCard interface
1599 private Handler mHandler;
1600
1601 // For async handler to identify request type
1602 private static final int SUPPLY_PIN_COMPLETE = 100;
1603
1604 public UnlockSim(IccCard simCard) {
1605 mSimCard = simCard;
1606 }
1607
1608 @Override
1609 public void run() {
1610 Looper.prepare();
1611 synchronized (UnlockSim.this) {
1612 mHandler = new Handler() {
1613 @Override
1614 public void handleMessage(Message msg) {
1615 AsyncResult ar = (AsyncResult) msg.obj;
1616 switch (msg.what) {
1617 case SUPPLY_PIN_COMPLETE:
1618 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1619 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001620 mRetryCount = msg.arg1;
1621 if (ar.exception != null) {
1622 if (ar.exception instanceof CommandException &&
1623 ((CommandException)(ar.exception)).getCommandError()
1624 == CommandException.Error.PASSWORD_INCORRECT) {
1625 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1626 } else {
1627 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1628 }
1629 } else {
1630 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001632 mDone = true;
1633 UnlockSim.this.notifyAll();
1634 }
1635 break;
1636 }
1637 }
1638 };
1639 UnlockSim.this.notifyAll();
1640 }
1641 Looper.loop();
1642 }
1643
1644 /*
1645 * Use PIN or PUK to unlock SIM card
1646 *
1647 * If PUK is null, unlock SIM card with PIN
1648 *
1649 * If PUK is not null, unlock SIM card with PUK and set PIN code
1650 */
Wink Saville9de0f752013-10-22 19:04:03 -07001651 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652
1653 while (mHandler == null) {
1654 try {
1655 wait();
1656 } catch (InterruptedException e) {
1657 Thread.currentThread().interrupt();
1658 }
1659 }
1660 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1661
1662 if (puk == null) {
1663 mSimCard.supplyPin(pin, callback);
1664 } else {
1665 mSimCard.supplyPuk(puk, pin, callback);
1666 }
1667
1668 while (!mDone) {
1669 try {
1670 Log.d(LOG_TAG, "wait for done");
1671 wait();
1672 } catch (InterruptedException e) {
1673 // Restore the interrupted status
1674 Thread.currentThread().interrupt();
1675 }
1676 }
1677 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001678 int[] resultArray = new int[2];
1679 resultArray[0] = mResult;
1680 resultArray[1] = mRetryCount;
1681 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 }
1683 }
1684
1685 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001686 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001687
1688 }
1689
Wink Savilleb564aae2014-10-23 10:18:09 -07001690 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 // No permission check needed here: this call is harmless, and it's
1692 // needed for the ServiceState.requestStateUpdate() call (which is
1693 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001694 final long identity = Binder.clearCallingIdentity();
1695 try {
1696 final Phone phone = getPhone(subId);
1697 if (phone != null) {
1698 phone.updateServiceLocation();
1699 }
1700 } finally {
1701 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 }
1704
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001705 @Override
1706 public boolean isRadioOn(String callingPackage) {
1707 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001708 }
1709
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001710 @Override
1711 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001713 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001714 return false;
1715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001716
1717 final long identity = Binder.clearCallingIdentity();
1718 try {
1719 return isRadioOnForSubscriber(subId);
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
1722 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001723 }
1724
1725 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001726 final long identity = Binder.clearCallingIdentity();
1727 try {
1728 final Phone phone = getPhone(subId);
1729 if (phone != null) {
1730 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1731 } else {
1732 return false;
1733 }
1734 } finally {
1735 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 }
1738
1739 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001740 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 }
Wink Saville36469e72014-06-11 15:17:00 -07001742
Wink Savilleb564aae2014-10-23 10:18:09 -07001743 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001745
1746 final long identity = Binder.clearCallingIdentity();
1747 try {
1748 final Phone phone = getPhone(subId);
1749 if (phone != null) {
1750 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1751 }
1752 } finally {
1753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001754 }
Wink Saville36469e72014-06-11 15:17:00 -07001755 }
1756
1757 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001758 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001759 }
1760
Wink Savilleb564aae2014-10-23 10:18:09 -07001761 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001763
1764 final long identity = Binder.clearCallingIdentity();
1765 try {
1766 final Phone phone = getPhone(subId);
1767 if (phone == null) {
1768 return false;
1769 }
1770 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1771 toggleRadioOnOffForSubscriber(subId);
1772 }
1773 return true;
1774 } finally {
1775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 }
Wink Saville36469e72014-06-11 15:17:00 -07001778
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001779 public boolean needMobileRadioShutdown() {
1780 /*
1781 * If any of the Radios are available, it will need to be
1782 * shutdown. So return true if any Radio is available.
1783 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001784 final long identity = Binder.clearCallingIdentity();
1785 try {
1786 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1787 Phone phone = PhoneFactory.getPhone(i);
1788 if (phone != null && phone.isRadioAvailable()) return true;
1789 }
1790 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1791 return false;
1792 } finally {
1793 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001794 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001795 }
1796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001798 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799 enforceModifyPermission();
1800
1801 final long identity = Binder.clearCallingIdentity();
1802 try {
1803 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1804 logv("Shutting down Phone " + i);
1805 shutdownRadioUsingPhoneId(i);
1806 }
1807 } finally {
1808 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001809 }
1810 }
1811
1812 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001813 Phone phone = PhoneFactory.getPhone(phoneId);
1814 if (phone != null && phone.isRadioAvailable()) {
1815 phone.shutdownRadio();
1816 }
1817 }
1818
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001820 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001821
1822 final long identity = Binder.clearCallingIdentity();
1823 try {
1824 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1825 if (defaultPhone != null) {
1826 defaultPhone.setRadioPower(turnOn);
1827 return true;
1828 } else {
1829 loge("There's no default phone.");
1830 return false;
1831 }
1832 } finally {
1833 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001834 }
Wink Saville36469e72014-06-11 15:17:00 -07001835 }
1836
Wink Savilleb564aae2014-10-23 10:18:09 -07001837 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001839
1840 final long identity = Binder.clearCallingIdentity();
1841 try {
1842 final Phone phone = getPhone(subId);
1843 if (phone != null) {
1844 phone.setRadioPower(turnOn);
1845 return true;
1846 } else {
1847 return false;
1848 }
1849 } finally {
1850 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001851 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001852 }
1853
Wink Saville36469e72014-06-11 15:17:00 -07001854 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001855 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 public boolean enableDataConnectivity() {
1857 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001858
1859 final long identity = Binder.clearCallingIdentity();
1860 try {
1861 int subId = mSubscriptionController.getDefaultDataSubId();
1862 final Phone phone = getPhone(subId);
1863 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001864 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001865 return true;
1866 } else {
1867 return false;
1868 }
1869 } finally {
1870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 }
1873
Wink Saville36469e72014-06-11 15:17:00 -07001874 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 public boolean disableDataConnectivity() {
1877 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001878
1879 final long identity = Binder.clearCallingIdentity();
1880 try {
1881 int subId = mSubscriptionController.getDefaultDataSubId();
1882 final Phone phone = getPhone(subId);
1883 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001884 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001885 return true;
1886 } else {
1887 return false;
1888 }
1889 } finally {
1890 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 }
1893
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001895 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001896 final long identity = Binder.clearCallingIdentity();
1897 try {
1898 final Phone phone = getPhone(subId);
1899 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001900 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001901 } else {
1902 return false;
1903 }
1904 } finally {
1905 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 }
1908
1909 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001910 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001911 }
1912
pkanwarae03a6b2016-11-06 20:37:09 -08001913 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001914 enforceCallPermission();
1915
1916 final long identity = Binder.clearCallingIdentity();
1917 try {
1918 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1919 return;
1920 }
1921 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1922 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1923 } finally {
1924 Binder.restoreCallingIdentity(identity);
1925 }
pkanwar32d516d2016-10-14 19:37:38 -07001926 };
1927
Wink Savilleb564aae2014-10-23 10:18:09 -07001928 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001930
1931 final long identity = Binder.clearCallingIdentity();
1932 try {
1933 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1934 return false;
1935 }
1936 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1937 } finally {
1938 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001939 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 }
1941
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001943 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001944 }
1945
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001946 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001947 final long identity = Binder.clearCallingIdentity();
1948 try {
1949 Phone phone = PhoneFactory.getPhone(slotIndex);
1950 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1951 PhoneConstantConversions.convertCallState(phone.getState());
1952 } finally {
1953 Binder.restoreCallingIdentity(identity);
1954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 }
1956
Sanket Padawe356d7632015-06-22 14:03:32 -07001957 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001958 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001959 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1960 }
1961
1962 @Override
1963 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001964 final long identity = Binder.clearCallingIdentity();
1965 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001966 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001967 if (phone != null) {
1968 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1969 } else {
1970 return PhoneConstantConversions.convertDataState(
1971 PhoneConstants.DataState.DISCONNECTED);
1972 }
1973 } finally {
1974 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001975 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 }
1977
Sanket Padawe356d7632015-06-22 14:03:32 -07001978 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001979 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001980 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1981 }
1982
1983 @Override
1984 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985 final long identity = Binder.clearCallingIdentity();
1986 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001987 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001988 if (phone != null) {
1989 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1990 } else {
1991 return TelephonyManager.DATA_ACTIVITY_NONE;
1992 }
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001995 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 }
1997
1998 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001999 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002000 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002001 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002002
2003 LocationAccessPolicy.LocationPermissionResult locationResult =
2004 LocationAccessPolicy.checkLocationPermission(mApp,
2005 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2006 .setCallingPackage(callingPackage)
2007 .setCallingPid(Binder.getCallingPid())
2008 .setCallingUid(Binder.getCallingUid())
2009 .setMethod("getCellLocation")
2010 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2011 .build());
2012 switch (locationResult) {
2013 case DENIED_HARD:
2014 throw new SecurityException("Not allowed to access cell location");
2015 case DENIED_SOFT:
2016 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
2018
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002019 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 if (DBG_LOC) log("getCellLocation: is active user");
2023 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002024 int subId = mSubscriptionController.getDefaultDataSubId();
2025 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2026 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002027 return data;
2028 } finally {
2029 Binder.restoreCallingIdentity(identity);
2030 }
Svetoslav64fad262015-04-14 14:35:21 -07002031 }
2032
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002034 public String getNetworkCountryIsoForPhone(int phoneId) {
2035 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2036 // registered cell info, so return a NULL country instead.
2037 final long identity = Binder.clearCallingIdentity();
2038 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002039 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2040 // Get default phone in this case.
2041 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2042 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002043 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002044 // Todo: fix this when we can get the actual cellular network info when the device
2045 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002046 if (TelephonyManager.NETWORK_TYPE_IWLAN
2047 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2048 return "";
2049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002050 Phone phone = PhoneFactory.getPhone(phoneId);
2051 if (phone != null) {
2052 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002053 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054 if (sst != null) {
2055 LocaleTracker lt = sst.getLocaleTracker();
2056 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002057 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2058 return lt.getCurrentCountry();
2059 } else if (emergencyNumberTracker != null) {
2060 return emergencyNumberTracker.getEmergencyCountryIso();
2061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002062 }
2063 }
2064 }
2065 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002066 } finally {
2067 Binder.restoreCallingIdentity(identity);
2068 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002069 }
2070
2071 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002073 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002074 }
2075
Sanket Padawe356d7632015-06-22 14:03:32 -07002076 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002077 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078 mApp.enforceCallingOrSelfPermission(
2079 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080
2081 final long identity = Binder.clearCallingIdentity();
2082 try {
2083 final Phone phone = getPhone(subId);
2084 if (phone != null) {
2085 phone.enableLocationUpdates();
2086 }
2087 } finally {
2088 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 }
2091
2092 @Override
2093 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002094 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002095 }
2096
Sanket Padawe356d7632015-06-22 14:03:32 -07002097 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002098 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 mApp.enforceCallingOrSelfPermission(
2100 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002101
2102 final long identity = Binder.clearCallingIdentity();
2103 try {
2104 final Phone phone = getPhone(subId);
2105 if (phone != null) {
2106 phone.disableLocationUpdates();
2107 }
2108 } finally {
2109 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002110 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 }
2112
Nathan Harold31d7ff32018-10-15 20:20:30 -07002113 /**
2114 * Returns the target SDK version number for a given package name.
2115 *
Nathan Haroldec184742019-07-10 17:04:16 -07002116 * This call MUST be invoked before clearing the calling UID.
2117 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002118 * @return target SDK if the package is found or INT_MAX.
2119 */
2120 private int getTargetSdk(String packageName) {
2121 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002122 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002123 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002124 if (ai != null) return ai.targetSdkVersion;
2125 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002126 loge("Failed to get package info for pkg="
2127 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002128 }
2129 return Integer.MAX_VALUE;
2130 }
2131
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 @Override
2133 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002134 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2135 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002136 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2137 throw new SecurityException(
2138 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2139 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002140
Jordan Liu1617b712019-07-10 15:06:26 -07002141 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002142 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2143 return null;
2144 }
Svetoslav64fad262015-04-14 14:35:21 -07002145
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002146 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147
Nathan Haroldf180aac2018-06-01 18:43:55 -07002148 List<CellInfo> info = getAllCellInfo(callingPackage);
2149 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150
Nathan Haroldf180aac2018-06-01 18:43:55 -07002151 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2152 for (CellInfo ci : info) {
2153 if (ci instanceof CellInfoGsm) {
2154 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2155 } else if (ci instanceof CellInfoWcdma) {
2156 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002159 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 }
2161
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002162 private List<CellInfo> getCachedCellInfo() {
2163 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2164 for (Phone phone : PhoneFactory.getPhones()) {
2165 List<CellInfo> info = phone.getAllCellInfo();
2166 if (info != null) cellInfos.addAll(info);
2167 }
2168 return cellInfos;
2169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170
2171 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002172 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002173 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002174 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002175
2176 LocationAccessPolicy.LocationPermissionResult locationResult =
2177 LocationAccessPolicy.checkLocationPermission(mApp,
2178 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2179 .setCallingPackage(callingPackage)
2180 .setCallingPid(Binder.getCallingPid())
2181 .setCallingUid(Binder.getCallingUid())
2182 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002183 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002184 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2185 .build());
2186 switch (locationResult) {
2187 case DENIED_HARD:
2188 throw new SecurityException("Not allowed to access cell info");
2189 case DENIED_SOFT:
2190 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 }
2192
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002193 final int targetSdk = getTargetSdk(callingPackage);
2194 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2195 return getCachedCellInfo();
2196 }
2197
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002198 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002199 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002200 final long identity = Binder.clearCallingIdentity();
2201 try {
2202 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2203 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002204 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002205 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002206 if (info != null) cellInfos.addAll(info);
2207 }
2208 return cellInfos;
2209 } finally {
2210 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 }
2212 }
2213
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002214 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002215 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2216 requestCellInfoUpdateInternal(
2217 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2218 }
2219
2220 @Override
2221 public void requestCellInfoUpdateWithWorkSource(
2222 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2223 enforceModifyPermission();
2224 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2225 }
2226
2227 private void requestCellInfoUpdateInternal(
2228 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002229 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002230 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002231
2232 LocationAccessPolicy.LocationPermissionResult locationResult =
2233 LocationAccessPolicy.checkLocationPermission(mApp,
2234 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2235 .setCallingPackage(callingPackage)
2236 .setCallingPid(Binder.getCallingPid())
2237 .setCallingUid(Binder.getCallingUid())
2238 .setMethod("requestCellInfoUpdate")
2239 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2240 .build());
2241 switch (locationResult) {
2242 case DENIED_HARD:
2243 throw new SecurityException("Not allowed to access cell info");
2244 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002245 try {
2246 cb.onCellInfo(new ArrayList<CellInfo>());
2247 } catch (RemoteException re) {
2248 // Drop without consequences
2249 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002250 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002251 }
2252
Nathan Harolda939a962019-05-09 10:13:47 -07002253
2254 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002255 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2256
2257 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2258 }
2259
2260 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002262 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264
2265 final long identity = Binder.clearCallingIdentity();
2266 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002267 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002268 } finally {
2269 Binder.restoreCallingIdentity(identity);
2270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 }
2272
Shishir Agrawala9f32182016-04-12 12:00:16 -07002273 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002274 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002275 Phone phone = PhoneFactory.getPhone(slotIndex);
2276 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002277 return null;
2278 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002279 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002280 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2281 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002282 return null;
2283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002284
2285 final long identity = Binder.clearCallingIdentity();
2286 try {
2287 return phone.getImei();
2288 } finally {
2289 Binder.restoreCallingIdentity(identity);
2290 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002291 }
2292
2293 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002294 public String getTypeAllocationCodeForSlot(int slotIndex) {
2295 Phone phone = PhoneFactory.getPhone(slotIndex);
2296 String tac = null;
2297 if (phone != null) {
2298 String imei = phone.getImei();
2299 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2300 }
2301 return tac;
2302 }
2303
2304 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002305 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002306 Phone phone = PhoneFactory.getPhone(slotIndex);
2307 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002308 return null;
2309 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002310
Jeff Davidson913390f2018-02-23 17:11:49 -08002311 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002312 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2313 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002314 return null;
2315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002316
2317 final long identity = Binder.clearCallingIdentity();
2318 try {
2319 return phone.getMeid();
2320 } finally {
2321 Binder.restoreCallingIdentity(identity);
2322 }
Jack Yu2af8d712017-03-15 17:14:14 -07002323 }
2324
2325 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002326 public String getManufacturerCodeForSlot(int slotIndex) {
2327 Phone phone = PhoneFactory.getPhone(slotIndex);
2328 String manufacturerCode = null;
2329 if (phone != null) {
2330 String meid = phone.getMeid();
2331 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2332 }
2333 return manufacturerCode;
2334 }
2335
2336 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002337 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002338 Phone phone = PhoneFactory.getPhone(slotIndex);
2339 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002340 return null;
2341 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002342 int subId = phone.getSubId();
2343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2344 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2345 return null;
2346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 return phone.getDeviceSvn();
2351 } finally {
2352 Binder.restoreCallingIdentity(identity);
2353 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002354 }
2355
fionaxu43304da2017-11-27 22:51:16 -08002356 @Override
2357 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002358 final long identity = Binder.clearCallingIdentity();
2359 try {
2360 final Phone phone = getPhone(subId);
2361 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2362 } finally {
2363 Binder.restoreCallingIdentity(identity);
2364 }
fionaxu43304da2017-11-27 22:51:16 -08002365 }
2366
2367 @Override
2368 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002369 final long identity = Binder.clearCallingIdentity();
2370 try {
2371 final Phone phone = getPhone(subId);
2372 return phone == null ? null : phone.getCarrierName();
2373 } finally {
2374 Binder.restoreCallingIdentity(identity);
2375 }
fionaxu43304da2017-11-27 22:51:16 -08002376 }
2377
calvinpanffe225e2018-11-01 19:43:06 +08002378 @Override
chen xu0026ca62019-03-06 15:28:50 -08002379 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 final Phone phone = getPhone(subId);
2383 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002384 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002385 } finally {
2386 Binder.restoreCallingIdentity(identity);
2387 }
2388 }
2389
2390 @Override
chen xu0026ca62019-03-06 15:28:50 -08002391 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002392 final long identity = Binder.clearCallingIdentity();
2393 try {
2394 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002395 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002396 } finally {
2397 Binder.restoreCallingIdentity(identity);
2398 }
2399 }
2400
chen xu651eec72018-11-11 19:03:44 -08002401 @Override
chen xu864e11c2018-12-06 22:10:03 -08002402 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2403 if (!isSubscriptionMccMnc) {
2404 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2405 }
chen xu651eec72018-11-11 19:03:44 -08002406 final Phone phone = PhoneFactory.getPhone(slotIndex);
2407 if (phone == null) {
2408 return TelephonyManager.UNKNOWN_CARRIER_ID;
2409 }
2410 final long identity = Binder.clearCallingIdentity();
2411 try {
2412 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2413 } finally {
2414 Binder.restoreCallingIdentity(identity);
2415 }
2416 }
2417
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 //
2419 // Internal helper methods.
2420 //
2421
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002422 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2424 *
2425 * @throws SecurityException if the caller does not have the required permission
2426 */
2427 private void enforceModifyPermission() {
2428 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2429 }
2430
2431 /**
2432 * Make sure the caller has the CALL_PHONE permission.
2433 *
2434 * @throws SecurityException if the caller does not have the required permission
2435 */
2436 private void enforceCallPermission() {
2437 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2438 }
2439
paulhu423b5f22019-08-23 19:17:33 +08002440 private void enforceSettingsPermission() {
2441 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002442 }
2443
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 private String createTelUrl(String number) {
2445 if (TextUtils.isEmpty(number)) {
2446 return null;
2447 }
2448
Jake Hambye994d462014-02-03 13:10:13 -08002449 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 }
2451
Ihab Awadf9e92732013-12-05 18:02:52 -08002452 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2454 }
2455
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002456 private static void logv(String msg) {
2457 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2458 }
2459
Ihab Awadf9e92732013-12-05 18:02:52 -08002460 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2462 }
2463
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002464 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002466 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002467 }
2468
Sanket Padawe356d7632015-06-22 14:03:32 -07002469 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002470 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002471 final long identity = Binder.clearCallingIdentity();
2472 try {
2473 final Phone phone = PhoneFactory.getPhone(slotIndex);
2474 if (phone == null) {
2475 return PhoneConstants.PHONE_TYPE_NONE;
2476 } else {
2477 return phone.getPhoneType();
2478 }
2479 } finally {
2480 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 }
2483
2484 /**
2485 * Returns the CDMA ERI icon index to display
2486 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002487 @Override
2488 public int getCdmaEriIconIndex(String callingPackage) {
2489 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002490 }
2491
Sanket Padawe356d7632015-06-22 14:03:32 -07002492 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002493 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002494 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002495 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002496 return -1;
2497 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498
2499 final long identity = Binder.clearCallingIdentity();
2500 try {
2501 final Phone phone = getPhone(subId);
2502 if (phone != null) {
2503 return phone.getCdmaEriIconIndex();
2504 } else {
2505 return -1;
2506 }
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002510 }
2511
2512 /**
2513 * Returns the CDMA ERI icon mode,
2514 * 0 - ON
2515 * 1 - FLASHING
2516 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002517 @Override
2518 public int getCdmaEriIconMode(String callingPackage) {
2519 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002520 }
2521
Sanket Padawe356d7632015-06-22 14:03:32 -07002522 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002523 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002525 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002526 return -1;
2527 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002528
2529 final long identity = Binder.clearCallingIdentity();
2530 try {
2531 final Phone phone = getPhone(subId);
2532 if (phone != null) {
2533 return phone.getCdmaEriIconMode();
2534 } else {
2535 return -1;
2536 }
2537 } finally {
2538 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540 }
2541
2542 /**
2543 * Returns the CDMA ERI text,
2544 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002545 @Override
2546 public String getCdmaEriText(String callingPackage) {
2547 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002548 }
2549
Sanket Padawe356d7632015-06-22 14:03:32 -07002550 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002551 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002552 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002553 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002554 return null;
2555 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556
2557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 final Phone phone = getPhone(subId);
2560 if (phone != null) {
2561 return phone.getCdmaEriText();
2562 } else {
2563 return null;
2564 }
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 }
2569
2570 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002571 * Returns the CDMA MDN.
2572 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002573 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002574 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2576 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577
2578 final long identity = Binder.clearCallingIdentity();
2579 try {
2580 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002581 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582 return phone.getLine1Number();
2583 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002584 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002585 return null;
2586 }
2587 } finally {
2588 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002589 }
2590 }
2591
2592 /**
2593 * Returns the CDMA MIN.
2594 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002595 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002596 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2598 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599
2600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 final Phone phone = getPhone(subId);
2603 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2604 return phone.getCdmaMin();
2605 } else {
2606 return null;
2607 }
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002610 }
2611 }
2612
Hall Liud892bec2018-11-30 14:51:45 -08002613 @Override
2614 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2615 INumberVerificationCallback callback, String callingPackage) {
2616 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2617 != PERMISSION_GRANTED) {
2618 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2619 }
2620 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2621
2622 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2623 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2624 throw new SecurityException("Calling package must be configured in the device config");
2625 }
2626
2627 if (range == null) {
2628 throw new NullPointerException("Range must be non-null");
2629 }
2630
2631 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002632 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002633
2634 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2635 }
2636
Junda Liuca05d5d2014-08-14 22:36:34 -07002637 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002638 * Returns true if CDMA provisioning needs to run.
2639 */
2640 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 final long identity = Binder.clearCallingIdentity();
2642 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002643 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644 } finally {
2645 Binder.restoreCallingIdentity(identity);
2646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 }
2648
2649 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002650 * Sets the voice mail number of a given subId.
2651 */
2652 @Override
2653 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002654 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2659 new Pair<String, String>(alphaTag, number), new Integer(subId));
2660 return success;
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
2663 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002664 }
2665
Ta-wei Yen87c49842016-05-13 21:19:52 -07002666 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002667 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2668 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002669 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2670 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002671 if (!TextUtils.equals(callingPackage, systemDialer)) {
2672 throw new SecurityException("caller must be system dialer");
2673 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674
2675 final long identity = Binder.clearCallingIdentity();
2676 try {
2677 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2678 if (phoneAccountHandle == null) {
2679 return null;
2680 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002681 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682 } finally {
2683 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002684 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002685 }
2686
2687 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002688 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002689 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002690 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002691 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002692 return null;
2693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002695 final long identity = Binder.clearCallingIdentity();
2696 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002697 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002698 } finally {
2699 Binder.restoreCallingIdentity(identity);
2700 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002701 }
2702
2703 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002704 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2705 VisualVoicemailSmsFilterSettings settings) {
2706 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707
2708 final long identity = Binder.clearCallingIdentity();
2709 try {
2710 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002711 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712 } finally {
2713 Binder.restoreCallingIdentity(identity);
2714 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002715 }
2716
2717 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002718 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2719 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720
2721 final long identity = Binder.clearCallingIdentity();
2722 try {
2723 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002724 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725 } finally {
2726 Binder.restoreCallingIdentity(identity);
2727 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002728 }
2729
2730 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002731 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2732 String callingPackage, int subId) {
2733 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734
2735 final long identity = Binder.clearCallingIdentity();
2736 try {
2737 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002738 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 } finally {
2740 Binder.restoreCallingIdentity(identity);
2741 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002742 }
2743
2744 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002745 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002746 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747
2748 final long identity = Binder.clearCallingIdentity();
2749 try {
2750 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002751 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002752 } finally {
2753 Binder.restoreCallingIdentity(identity);
2754 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002755 }
2756
2757 @Override
2758 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2759 String number, int port, String text, PendingIntent sentIntent) {
2760 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002761 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002762 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002763 SmsController smsController = PhoneFactory.getSmsController();
2764 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2765 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002766 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002767
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002768 /**
fionaxu0152e512016-11-14 13:36:14 -08002769 * Sets the voice activation state of a given subId.
2770 */
2771 @Override
2772 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2774 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002775
2776 final long identity = Binder.clearCallingIdentity();
2777 try {
2778 final Phone phone = getPhone(subId);
2779 if (phone != null) {
2780 phone.setVoiceActivationState(activationState);
2781 } else {
2782 loge("setVoiceActivationState fails with invalid subId: " + subId);
2783 }
2784 } finally {
2785 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002786 }
2787 }
2788
2789 /**
2790 * Sets the data activation state of a given subId.
2791 */
2792 @Override
2793 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2795 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796
2797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 final Phone phone = getPhone(subId);
2800 if (phone != null) {
2801 phone.setDataActivationState(activationState);
2802 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002803 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 }
2805 } finally {
2806 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002807 }
2808 }
2809
2810 /**
2811 * Returns the voice activation state of a given subId.
2812 */
2813 @Override
2814 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002815 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816
fionaxu0152e512016-11-14 13:36:14 -08002817 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 if (phone != null) {
2821 return phone.getVoiceActivationState();
2822 } else {
2823 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2824 }
2825 } finally {
2826 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002827 }
2828 }
2829
2830 /**
2831 * Returns the data activation state of a given subId.
2832 */
2833 @Override
2834 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002835 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836
fionaxu0152e512016-11-14 13:36:14 -08002837 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 if (phone != null) {
2841 return phone.getDataActivationState();
2842 } else {
2843 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2844 }
2845 } finally {
2846 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002847 }
2848 }
2849
2850 /**
Wink Saville36469e72014-06-11 15:17:00 -07002851 * Returns the unread count of voicemails for a subId
2852 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002853 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002854 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2856 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2857 return 0;
2858 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859 final long identity = Binder.clearCallingIdentity();
2860 try {
2861 final Phone phone = getPhone(subId);
2862 if (phone != null) {
2863 return phone.getVoiceMessageCount();
2864 } else {
2865 return 0;
2866 }
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002869 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002870 }
2871
2872 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002873 * returns true, if the device is in a state where both voice and data
2874 * are supported simultaneously. This can change based on location or network condition.
2875 */
2876 @Override
2877 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 final Phone phone = getPhone(subId);
2881 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2882 } finally {
2883 Binder.restoreCallingIdentity(identity);
2884 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002885 }
2886
2887 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002888 * Send the dialer code if called from the current default dialer or the caller has
2889 * carrier privilege.
2890 * @param inputCode The dialer code to send
2891 */
2892 @Override
2893 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002894 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002895 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002896 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2897 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002898 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002899 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2900 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902
2903 final long identity = Binder.clearCallingIdentity();
2904 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002905 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 } finally {
2907 Binder.restoreCallingIdentity(identity);
2908 }
fionaxu235cc5e2017-03-06 22:25:57 -08002909 }
2910
Pengquan Menga1bb6272018-09-06 09:59:22 -07002911 @Override
2912 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002913 if (!isActiveSubscription(subId)) {
2914 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2915 }
2916
Pengquan Menga1bb6272018-09-06 09:59:22 -07002917 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2918 }
2919
Brad Ebinger35c841c2018-10-01 10:40:55 -07002920 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002921 public boolean isInEmergencySmsMode() {
2922 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2923 final long identity = Binder.clearCallingIdentity();
2924 try {
2925 for (Phone phone : PhoneFactory.getPhones()) {
2926 if (phone.isInEmergencySmsMode()) {
2927 return true;
2928 }
2929 }
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
2932 }
2933 return false;
2934 }
2935
2936 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002937 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2938 throws RemoteException {
2939 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002940 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2941 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2942 "IMS not available on device.");
2943 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002944 final long token = Binder.clearCallingIdentity();
2945 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002947 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002948 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002949 } catch (ImsException e) {
2950 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002951 } finally {
2952 Binder.restoreCallingIdentity(token);
2953 }
2954 }
2955
2956 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002957 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2958 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002959 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2960 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2961 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002962 final long token = Binder.clearCallingIdentity();
2963 try {
2964 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2965 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2966 .removeRegistrationCallbackForSubscription(c, subId);
2967 } catch (ImsException e) {
2968 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2969 + "is inactive, ignoring unregister.");
2970 // If the subscription is no longer active, just return, since the callback
2971 // will already have been removed internally.
2972 } finally {
2973 Binder.restoreCallingIdentity(token);
2974 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002975 }
2976
Brad Ebinger774ba362019-10-22 17:36:18 -07002977 /**
2978 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2979 */
2980 @Override
2981 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2982 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2983 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2984 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2985 "IMS not available on device.");
2986 }
2987 final long token = Binder.clearCallingIdentity();
2988 try {
2989 Phone phone = getPhone(subId);
2990 if (phone == null) {
2991 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2992 + subId + "'");
2993 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
2994 }
2995 phone.getImsRegistrationState(regState -> {
2996 try {
2997 consumer.accept((regState == null)
2998 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
2999 } catch (RemoteException e) {
3000 // Ignore if the remote process is no longer available to call back.
3001 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3002 }
3003 });
3004 } finally {
3005 Binder.restoreCallingIdentity(token);
3006 }
3007 }
3008
3009 /**
3010 * Get the transport type for the IMS service registration state.
3011 */
3012 @Override
3013 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3014 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3015 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3016 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3017 "IMS not available on device.");
3018 }
3019 final long token = Binder.clearCallingIdentity();
3020 try {
3021 Phone phone = getPhone(subId);
3022 if (phone == null) {
3023 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3024 + subId + "'");
3025 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3026 }
3027 phone.getImsRegistrationTech(regTech -> {
3028 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3029 int regTechConverted = (regTech == null)
3030 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3031 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3032 regTechConverted);
3033 try {
3034 consumer.accept(regTechConverted);
3035 } catch (RemoteException e) {
3036 // Ignore if the remote process is no longer available to call back.
3037 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3038 }
3039 });
3040 } finally {
3041 Binder.restoreCallingIdentity(token);
3042 }
3043 }
3044
Brad Ebinger35c841c2018-10-01 10:40:55 -07003045 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003046 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3047 throws RemoteException {
3048 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003049 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3050 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3051 "IMS not available on device.");
3052 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3054 final long token = Binder.clearCallingIdentity();
3055 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003056 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003057 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003058 } catch (ImsException e) {
3059 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003060 } finally {
3061 Binder.restoreCallingIdentity(token);
3062 }
3063 }
3064
3065 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003066 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3067 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003068 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3069 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3070 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003071
3072 final long token = Binder.clearCallingIdentity();
3073 try {
3074 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3075 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003076 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003077 } catch (ImsException e) {
3078 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3079 + "is inactive, ignoring unregister.");
3080 // If the subscription is no longer active, just return, since the callback
3081 // will already have been removed internally.
3082 } finally {
3083 Binder.restoreCallingIdentity(token);
3084 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003085 }
3086
3087 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003088 public boolean isCapable(int subId, int capability, int regTech) {
3089 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003090 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3091 final long token = Binder.clearCallingIdentity();
3092 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003093 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003094 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003095 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003096 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3097 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003098 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003099 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3100 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003101 } finally {
3102 Binder.restoreCallingIdentity(token);
3103 }
3104 }
3105
3106 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003107 public boolean isAvailable(int subId, int capability, int regTech) {
3108 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003109 final long token = Binder.clearCallingIdentity();
3110 try {
3111 Phone phone = getPhone(subId);
3112 if (phone == null) return false;
3113 return phone.isImsCapabilityAvailable(capability, regTech);
3114 } finally {
3115 Binder.restoreCallingIdentity(token);
3116 }
3117 }
3118
Brad Ebinger77b832e2019-10-17 17:03:22 -07003119 /**
3120 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3121 * subscription.
3122 * @param subId The subscription to use to check the configuration.
3123 * @param callback The callback that will be used to send the result.
3124 * @param capability The MmTelFeature capability that will be used to send the result.
3125 * @param transportType The transport type of the MmTelFeature capability.
3126 */
3127 @Override
3128 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3129 int transportType) {
3130 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3131 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3132 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3133 "IMS not available on device.");
3134 }
3135 final long token = Binder.clearCallingIdentity();
3136 try {
3137 int slotId = getSlotIndex(subId);
3138 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3139 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3140 + subId + "'");
3141 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3142 }
3143 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3144 transportType, aBoolean -> {
3145 try {
3146 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3147 } catch (RemoteException e) {
3148 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3149 + "running. Ignore");
3150 }
3151 });
3152 } finally {
3153 Binder.restoreCallingIdentity(token);
3154 }
3155 }
3156
Brad Ebinger35c841c2018-10-01 10:40:55 -07003157 @Override
3158 public boolean isAdvancedCallingSettingEnabled(int subId) {
3159 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3160 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3161 final long token = Binder.clearCallingIdentity();
3162 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003163 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003164 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003165 } catch (ImsException e) {
3166 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003167 } finally {
3168 Binder.restoreCallingIdentity(token);
3169 }
3170 }
3171
3172 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003173 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003175 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003176 final long identity = Binder.clearCallingIdentity();
3177 try {
3178 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003179 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003180 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003181 } catch (ImsException e) {
3182 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003183 } finally {
3184 Binder.restoreCallingIdentity(identity);
3185 }
3186 }
3187
3188 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003189 public boolean isVtSettingEnabled(int subId) {
3190 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003191 final long identity = Binder.clearCallingIdentity();
3192 try {
3193 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003194 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3195 } catch (ImsException e) {
3196 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003197 } finally {
3198 Binder.restoreCallingIdentity(identity);
3199 }
3200 }
3201
3202 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003203 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003205 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003206 final long identity = Binder.clearCallingIdentity();
3207 try {
3208 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003209 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003210 } catch (ImsException e) {
3211 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003212 } finally {
3213 Binder.restoreCallingIdentity(identity);
3214 }
3215 }
3216
3217 @Override
3218 public boolean isVoWiFiSettingEnabled(int subId) {
3219 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3220 final long identity = Binder.clearCallingIdentity();
3221 try {
3222 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003223 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003224 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003225 } catch (ImsException e) {
3226 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003227 } finally {
3228 Binder.restoreCallingIdentity(identity);
3229 }
3230 }
3231
3232 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003233 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003235 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003236 final long identity = Binder.clearCallingIdentity();
3237 try {
3238 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003239 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003240 } catch (ImsException e) {
3241 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003242 } finally {
3243 Binder.restoreCallingIdentity(identity);
3244 }
3245 }
3246
3247 @Override
3248 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3249 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3250 final long identity = Binder.clearCallingIdentity();
3251 try {
3252 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003253 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003254 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003255 } catch (ImsException e) {
3256 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003257 } finally {
3258 Binder.restoreCallingIdentity(identity);
3259 }
3260 }
3261
3262 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003263 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003265 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003266 final long identity = Binder.clearCallingIdentity();
3267 try {
3268 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003269 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003271 } catch (ImsException e) {
3272 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 } finally {
3274 Binder.restoreCallingIdentity(identity);
3275 }
3276 }
3277
3278 @Override
3279 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3281 "setVoWiFiNonPersistent");
3282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003285 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003286 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003287 } catch (ImsException e) {
3288 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003289 } finally {
3290 Binder.restoreCallingIdentity(identity);
3291 }
3292 }
3293
3294 @Override
3295 public int getVoWiFiModeSetting(int subId) {
3296 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3297 final long identity = Binder.clearCallingIdentity();
3298 try {
3299 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003300 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003301 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003302 } catch (ImsException e) {
3303 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003304 } finally {
3305 Binder.restoreCallingIdentity(identity);
3306 }
3307 }
3308
3309 @Override
3310 public void setVoWiFiModeSetting(int subId, int mode) {
3311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3312 "setVoWiFiModeSetting");
3313 final long identity = Binder.clearCallingIdentity();
3314 try {
3315 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003316 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003317 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003318 } catch (ImsException e) {
3319 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003320 } finally {
3321 Binder.restoreCallingIdentity(identity);
3322 }
3323 }
3324
3325 @Override
3326 public int getVoWiFiRoamingModeSetting(int subId) {
3327 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3328 final long identity = Binder.clearCallingIdentity();
3329 try {
3330 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003331 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003332 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003333 } catch (ImsException e) {
3334 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
3338 }
3339
3340 @Override
3341 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3343 "setVoWiFiRoamingModeSetting");
3344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003347 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003348 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003349 } catch (ImsException e) {
3350 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003351 } finally {
3352 Binder.restoreCallingIdentity(identity);
3353 }
3354 }
3355
3356 @Override
3357 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3359 "setRttCapabilityEnabled");
3360 final long identity = Binder.clearCallingIdentity();
3361 try {
3362 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003363 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3364 } catch (ImsException e) {
3365 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 } finally {
3367 Binder.restoreCallingIdentity(identity);
3368 }
3369 }
3370
3371 @Override
3372 public boolean isTtyOverVolteEnabled(int subId) {
3373 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003377 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003378 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003379 } catch (ImsException e) {
3380 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 } finally {
3382 Binder.restoreCallingIdentity(identity);
3383 }
3384 }
3385
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003386 @Override
3387 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3388 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003392 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003393 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003394 } catch (ImsException e) {
3395 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003396 } finally {
3397 Binder.restoreCallingIdentity(identity);
3398 }
3399 }
3400
3401 @Override
3402 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3403 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3404 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003405 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3406 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3407 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003408 try {
3409 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003410 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003411 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003412 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003413 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3414 + "is inactive, ignoring unregister.");
3415 // If the subscription is no longer active, just return, since the callback will already
3416 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003417 } finally {
3418 Binder.restoreCallingIdentity(identity);
3419 }
3420 }
3421
3422 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003423 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3424 boolean isProvisioned) {
3425 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3426 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3427 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3428 }
3429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3430 "setProvisioningStatusForCapability");
3431 final long identity = Binder.clearCallingIdentity();
3432 try {
3433 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3434 Phone phone = getPhone(subId);
3435 if (phone == null) {
3436 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3437 + subId);
3438 return;
3439 }
3440 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3441 return;
3442 }
3443
3444 // this capability requires provisioning, route to the correct API.
3445 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3446 switch (capability) {
3447 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3448 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3449 ims.setVolteProvisioned(isProvisioned);
3450 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3451 ims.setWfcProvisioned(isProvisioned);
3452 }
3453 break;
3454 }
3455 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3456 // There is currently no difference in VT provisioning type.
3457 ims.setVtProvisioned(isProvisioned);
3458 break;
3459 }
3460 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3461 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3462 // change the capability of the feature instead if needed.
3463 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3464 == isProvisioned) {
3465 // No change in provisioning.
3466 return;
3467 }
3468 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3469 try {
3470 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003471 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003472 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3473 + ", Exception" + e.getMessage());
3474 }
3475 break;
3476 }
3477 default: {
3478 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3479 + capability + "', which does not require provisioning.");
3480 }
3481 }
3482
3483 } finally {
3484 Binder.restoreCallingIdentity(identity);
3485 }
3486 }
3487
3488 @Override
3489 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3490 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3491 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3492 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3493 }
3494 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3495 final long identity = Binder.clearCallingIdentity();
3496 try {
3497 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3498 Phone phone = getPhone(subId);
3499 if (phone == null) {
3500 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3501 + subId);
3502 // We will fail with "true" as the provisioning status because this is the default
3503 // if we do not require provisioning.
3504 return true;
3505 }
3506
3507 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3508 return true;
3509 }
3510
3511 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3512 switch (capability) {
3513 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3514 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3515 return ims.isVolteProvisionedOnDevice();
3516 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3517 return ims.isWfcProvisionedOnDevice();
3518 }
3519 // This should never happen, since we are checking tech above to make sure it
3520 // is either LTE or IWLAN.
3521 throw new IllegalArgumentException("Invalid radio technology for voice "
3522 + "capability.");
3523 }
3524 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3525 // There is currently no difference in VT provisioning type.
3526 return ims.isVtProvisionedOnDevice();
3527 }
3528 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3529 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3530 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3531 }
3532 default: {
3533 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3534 + capability + "', which does not require provisioning.");
3535 }
3536 }
3537
3538 } finally {
3539 Binder.restoreCallingIdentity(identity);
3540 }
3541 }
3542
3543 @Override
3544 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3545 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3546 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3547 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3548 }
3549 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3550 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3551 return (provisionedBits & capability) > 0;
3552 }
3553
3554 @Override
3555 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3556 boolean isProvisioned) {
3557 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3558 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3559 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3560 }
3561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3562 "setProvisioningStatusForCapability");
3563 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3564 // If the current provisioning status for capability already matches isProvisioned,
3565 // do nothing.
3566 if (((provisionedBits & capability) > 0) == isProvisioned) {
3567 return;
3568 }
3569 if (isProvisioned) {
3570 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3571 } else {
3572 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3573 }
3574 }
3575
3576 /**
3577 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3578 * technology. The bitfield should mirror the bitfield defined by
3579 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3580 */
3581 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3582 String key = getMmTelProvisioningKey(subId, tech);
3583 // Default is no capabilities are provisioned.
3584 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3585 }
3586
3587 /**
3588 * Sets the MmTel capability provisioning bitfield (defined by
3589 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3590 * technology specified.
3591 *
3592 * Note: This is a synchronous command and should not be called on UI thread.
3593 */
3594 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3595 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3596 String key = getMmTelProvisioningKey(subId, tech);
3597 editor.putInt(key, newField);
3598 editor.commit();
3599 }
3600
3601 private static String getMmTelProvisioningKey(int subId, int tech) {
3602 // resulting key is provision_ims_mmtel_{subId}_{tech}
3603 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3604 }
3605
3606 /**
3607 * Query CarrierConfig to see if the specified capability requires provisioning for the
3608 * carrier associated with the subscription id.
3609 */
3610 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3611 int capability) {
3612 CarrierConfigManager configManager = new CarrierConfigManager(context);
3613 PersistableBundle c = configManager.getConfigForSubId(subId);
3614 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003615 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003616 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3617 false);
3618 boolean requireVoiceVtProvisioning = c.getBoolean(
3619 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3620
3621 // First check to make sure that the capability requires provisioning.
3622 switch (capability) {
3623 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3624 // intentional fallthrough
3625 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3626 if (requireVoiceVtProvisioning) {
3627 // Voice and Video requires provisioning
3628 return true;
3629 }
3630 break;
3631 }
3632 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3633 if (requireUtProvisioning) {
3634 // UT requires provisioning
3635 return true;
3636 }
3637 break;
3638 }
3639 }
3640 return false;
3641 }
3642
3643 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003644 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003645 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3646 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3647 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003648 enforceReadPrivilegedPermission("getImsProvisioningInt");
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003652 int slotId = getSlotIndex(subId);
3653 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3654 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3655 + subId + "' for key:" + key);
3656 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3657 }
3658 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003659 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003660 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3661 + subId + "' for key:" + key);
3662 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
3666 }
3667
3668 @Override
3669 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003670 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3671 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3672 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003673 enforceReadPrivilegedPermission("getImsProvisioningString");
3674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003677 int slotId = getSlotIndex(subId);
3678 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3679 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3680 + subId + "' for key:" + key);
3681 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3682 }
3683 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003684 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003685 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3686 + subId + "' for key:" + key);
3687 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003688 } finally {
3689 Binder.restoreCallingIdentity(identity);
3690 }
3691 }
3692
3693 @Override
3694 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003695 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3696 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3697 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3699 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003703 int slotId = getSlotIndex(subId);
3704 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3705 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3706 + subId + "' for key:" + key);
3707 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3708 }
3709 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003710 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003711 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3712 + "' for key:" + key);
3713 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003714 } finally {
3715 Binder.restoreCallingIdentity(identity);
3716 }
3717 }
3718
3719 @Override
3720 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003721 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3722 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3723 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3725 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003726 final long identity = Binder.clearCallingIdentity();
3727 try {
3728 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003729 int slotId = getSlotIndex(subId);
3730 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3731 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3732 + subId + "' for key:" + key);
3733 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3734 }
3735 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003736 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003737 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3738 + "' for key:" + key);
3739 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003740 } finally {
3741 Binder.restoreCallingIdentity(identity);
3742 }
3743 }
3744
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003745 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003746 int slotId = SubscriptionManager.getSlotIndex(subId);
3747 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003748 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3749 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003750 }
3751 return slotId;
3752 }
3753
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003754 private int getSlotIndex(int subId) {
3755 int slotId = SubscriptionManager.getSlotIndex(subId);
3756 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3757 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3758 }
3759 return slotId;
3760 }
3761
Wink Saville36469e72014-06-11 15:17:00 -07003762 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003763 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003764 */
3765 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003766 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003767 final int targetSdk = getTargetSdk(callingPackage);
3768 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3769 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3770 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003771 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3772 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003773 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3774 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003776 final long identity = Binder.clearCallingIdentity();
3777 try {
3778 final Phone phone = getPhone(subId);
3779 if (phone != null) {
3780 return phone.getServiceState().getDataNetworkType();
3781 } else {
3782 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3783 }
3784 } finally {
3785 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003786 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003787 }
3788
3789 /**
3790 * Returns the data network type
3791 */
3792 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003793 public int getDataNetworkType(String callingPackage) {
3794 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003795 }
3796
3797 /**
3798 * Returns the data network type for a subId
3799 */
3800 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003801 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003803 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003804 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3805 }
3806
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 final Phone phone = getPhone(subId);
3810 if (phone != null) {
3811 return phone.getServiceState().getDataNetworkType();
3812 } else {
3813 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3814 }
3815 } finally {
3816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003818 }
3819
3820 /**
Wink Saville36469e72014-06-11 15:17:00 -07003821 * Returns the Voice network type for a subId
3822 */
3823 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003824 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003826 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003827 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3828 }
3829
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830 final long identity = Binder.clearCallingIdentity();
3831 try {
3832 final Phone phone = getPhone(subId);
3833 if (phone != null) {
3834 return phone.getServiceState().getVoiceNetworkType();
3835 } else {
3836 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3837 }
3838 } finally {
3839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003841 }
3842
3843 /**
3844 * @return true if a ICC card is present
3845 */
3846 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003847 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003848 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3849 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003850 }
3851
3852 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003853 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003854 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003855 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003856 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 final Phone phone = PhoneFactory.getPhone(slotIndex);
3860 if (phone != null) {
3861 return phone.getIccCard().hasIccCard();
3862 } else {
3863 return false;
3864 }
3865 } finally {
3866 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003867 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003868 }
3869
3870 /**
3871 * Return if the current radio is LTE on CDMA. This
3872 * is a tri-state return value as for a period of time
3873 * the mode may be unknown.
3874 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003875 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003876 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003877 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003878 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003879 @Override
3880 public int getLteOnCdmaMode(String callingPackage) {
3881 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003882 }
3883
Sanket Padawe356d7632015-06-22 14:03:32 -07003884 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003885 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003887 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003888 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3889 }
3890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891 final long identity = Binder.clearCallingIdentity();
3892 try {
3893 final Phone phone = getPhone(subId);
3894 if (phone == null) {
3895 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3896 } else {
3897 return phone.getLteOnCdmaMode();
3898 }
3899 } finally {
3900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003901 }
Wink Saville36469e72014-06-11 15:17:00 -07003902 }
3903
Wink Saville36469e72014-06-11 15:17:00 -07003904 /**
3905 * {@hide}
3906 * Returns Default subId, 0 in the case of single standby.
3907 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003908 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003909 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003910 }
3911
Shishir Agrawala9f32182016-04-12 12:00:16 -07003912 private int getSlotForDefaultSubscription() {
3913 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3914 }
3915
Wink Savilleb564aae2014-10-23 10:18:09 -07003916 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003917 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003918 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003919
Pengquan Menge92a50d2018-09-21 15:54:48 -07003920 private boolean isActiveSubscription(int subId) {
3921 return mSubscriptionController.isActiveSubId(subId);
3922 }
3923
Ihab Awadf2177b72013-11-25 13:33:23 -08003924 /**
3925 * @see android.telephony.TelephonyManager.WifiCallingChoices
3926 */
3927 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003928 final long identity = Binder.clearCallingIdentity();
3929 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003930 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003931 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3932 getWhenToMakeWifiCallsDefaultPreference());
3933 } finally {
3934 Binder.restoreCallingIdentity(identity);
3935 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003936 }
3937
3938 /**
3939 * @see android.telephony.TelephonyManager.WifiCallingChoices
3940 */
3941 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003945 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003946 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3947 } finally {
3948 Binder.restoreCallingIdentity(identity);
3949 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003950 }
3951
Sailesh Nepald1e68152013-12-12 19:08:02 -08003952 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003953 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003954 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003955 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003956
Jordan Liu4c733742019-02-28 12:03:40 -08003957 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3958 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3959 if (phoneId == -1) {
3960 throw new IllegalArgumentException("Given slot index: " + slotIndex
3961 + " does not correspond to an active phone");
3962 }
3963 return PhoneFactory.getPhone(phoneId);
3964 }
3965
Shishir Agrawal566b7612013-10-28 14:41:00 -07003966 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003967 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3968 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3970 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003971 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003972 if (DBG) {
3973 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3974 }
3975 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3976 p2);
3977 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003978
Jordan Liu4c733742019-02-28 12:03:40 -08003979
3980 @Override
3981 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3982 int slotIndex, String callingPackage, String aid, int p2) {
3983 enforceModifyPermission();
3984 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3985 if (DBG) {
3986 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3987 }
3988 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3989 callingPackage, aid, p2);
3990 }
3991
3992 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3993 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003994 final long identity = Binder.clearCallingIdentity();
3995 try {
3996 if (TextUtils.equals(ISDR_AID, aid)) {
3997 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003998 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3999 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004000 if (bestComponent == null
4001 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4002 loge("The calling package is not allowed to access ISD-R.");
4003 throw new SecurityException(
4004 "The calling package is not allowed to access ISD-R.");
4005 }
Derek Tan740e1672017-06-27 14:56:27 -07004006 }
Derek Tan740e1672017-06-27 14:56:27 -07004007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004008 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004009 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4010 null /* workSource */);
4011 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004012 return response;
4013 } finally {
4014 Binder.restoreCallingIdentity(identity);
4015 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004016 }
4017
4018 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004019 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004020 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4021 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004022 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4023 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4024 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004025
Jordan Liu4c733742019-02-28 12:03:40 -08004026 @Override
4027 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4028 enforceModifyPermission();
4029 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4030 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4031 channel);
4032 }
4033
4034 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004035 final long identity = Binder.clearCallingIdentity();
4036 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004037 if (channel < 0) {
4038 return false;
4039 }
Jordan Liu4c733742019-02-28 12:03:40 -08004040 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4041 null /* workSource */);
4042 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004043 return success;
4044 } finally {
4045 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004046 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004047 }
4048
4049 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004050 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004051 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4053 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004054 if (DBG) {
4055 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4056 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4057 + p3 + " data=" + data);
4058 }
4059 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4060 command, p1, p2, p3, data);
4061 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004062
Jordan Liu4c733742019-02-28 12:03:40 -08004063 @Override
4064 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4065 int command, int p1, int p2, int p3, String data) {
4066 enforceModifyPermission();
4067 if (DBG) {
4068 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4069 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4070 + p3 + " data=" + data);
4071 }
4072 return iccTransmitApduLogicalChannelWithPermission(
4073 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4074 data);
4075 }
4076
4077 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4078 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004079 final long identity = Binder.clearCallingIdentity();
4080 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004081 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082 return "";
4083 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004086 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4087 null /* workSource */);
4088 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004090 // Append the returned status code to the end of the response payload.
4091 String s = Integer.toHexString(
4092 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4093 if (response.payload != null) {
4094 s = IccUtils.bytesToHexString(response.payload) + s;
4095 }
4096 return s;
4097 } finally {
4098 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004099 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004100 }
Jake Hambye994d462014-02-03 13:10:13 -08004101
Evan Charltonc66da362014-05-16 14:06:40 -07004102 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004103 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4104 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4106 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004107 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004108 if (DBG) {
4109 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4110 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4111 }
4112 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4113 cla, command, p1, p2, p3, data);
4114 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004115
Jordan Liu4c733742019-02-28 12:03:40 -08004116 @Override
4117 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4118 int command, int p1, int p2, int p3, String data) {
4119 enforceModifyPermission();
4120 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4121 if (DBG) {
4122 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4123 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4124 + " data=" + data);
4125 }
4126
4127 return iccTransmitApduBasicChannelWithPermission(
4128 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4129 p2, p3, data);
4130 }
4131
4132 // open APDU basic channel assuming the caller has sufficient permissions
4133 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4134 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4138 && TextUtils.equals(ISDR_AID, data)) {
4139 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004140 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4141 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004142 if (bestComponent == null
4143 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4144 loge("The calling package is not allowed to select ISD-R.");
4145 throw new SecurityException(
4146 "The calling package is not allowed to select ISD-R.");
4147 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004148 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004149
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004150 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004151 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4152 null /* workSource */);
4153 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004155 // Append the returned status code to the end of the response payload.
4156 String s = Integer.toHexString(
4157 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4158 if (response.payload != null) {
4159 s = IccUtils.bytesToHexString(response.payload) + s;
4160 }
4161 return s;
4162 } finally {
4163 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004164 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004165 }
4166
4167 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004168 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004169 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4171 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004173 final long identity = Binder.clearCallingIdentity();
4174 try {
4175 if (DBG) {
4176 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4177 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4178 }
4179
4180 IccIoResult response =
4181 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4182 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4183 subId);
4184
4185 if (DBG) {
4186 log("Exchange SIM_IO [R]" + response);
4187 }
4188
4189 byte[] result = null;
4190 int length = 2;
4191 if (response.payload != null) {
4192 length = 2 + response.payload.length;
4193 result = new byte[length];
4194 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4195 } else {
4196 result = new byte[length];
4197 }
4198
4199 result[length - 1] = (byte) response.sw2;
4200 result[length - 2] = (byte) response.sw1;
4201 return result;
4202 } finally {
4203 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004204 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004205 }
4206
Nathan Haroldb3014052017-01-25 15:57:32 -08004207 /**
4208 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4209 * on a particular subscription
4210 */
sqianb6e41952018-03-12 14:54:01 -07004211 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4212 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4213 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4214 return null;
4215 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004216
4217 final long identity = Binder.clearCallingIdentity();
4218 try {
4219 if (appType != TelephonyManager.APPTYPE_USIM
4220 && appType != TelephonyManager.APPTYPE_SIM) {
4221 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4222 return null;
4223 }
4224 Object response = sendRequest(
4225 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4226 if (response instanceof String[]) {
4227 return (String[]) response;
4228 }
yincheng zhaod698b842019-09-06 17:06:54 -07004229 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004231 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004232 } finally {
4233 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004234 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004235 }
4236
yincheng zhaod698b842019-09-06 17:06:54 -07004237 /**
4238 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4239 * subscription.
4240 *
4241 * @param subId the id of the subscription.
4242 * @param appType the uicc app type, must be USIM or SIM.
4243 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4244 * @param callingPackage the op Package name.
4245 * @return number of fplmns that is successfully written to the SIM.
4246 */
4247 public int setForbiddenPlmns(
4248 int subId, int appType, List<String> fplmns, String callingPackage) {
4249 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4250 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4251 if (DBG) logv("no permissions for setForbiddenplmns");
4252 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4253 }
4254 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4255 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4256 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4257 }
4258 if (fplmns == null) {
4259 throw new IllegalArgumentException("Fplmn List provided is null");
4260 }
4261 for (String fplmn : fplmns) {
4262 if (!CellIdentity.isValidPlmn(fplmn)) {
4263 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4264 }
4265 }
4266 final long identity = Binder.clearCallingIdentity();
4267 try {
4268 Object response = sendRequest(
4269 CMD_SET_FORBIDDEN_PLMNS,
4270 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4271 subId);
4272 return (int) response;
4273 } finally {
4274 Binder.restoreCallingIdentity(identity);
4275 }
4276 }
4277
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004278 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004279 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4281 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283 final long identity = Binder.clearCallingIdentity();
4284 try {
4285 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4286 if (response.payload == null) {
4287 return "";
4288 }
Evan Charltonc66da362014-05-16 14:06:40 -07004289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290 // Append the returned status code to the end of the response payload.
4291 String s = Integer.toHexString(
4292 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4293 s = IccUtils.bytesToHexString(response.payload) + s;
4294 return s;
4295 } finally {
4296 Binder.restoreCallingIdentity(identity);
4297 }
Evan Charltonc66da362014-05-16 14:06:40 -07004298 }
4299
Jake Hambye994d462014-02-03 13:10:13 -08004300 /**
4301 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4302 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4303 *
4304 * @param itemID the ID of the item to read
4305 * @return the NV item as a String, or null on error.
4306 */
4307 @Override
4308 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004309 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4311 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004312
4313 final long identity = Binder.clearCallingIdentity();
4314 try {
4315 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004316 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004317 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4318 return value;
4319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
Jake Hambye994d462014-02-03 13:10:13 -08004322 }
4323
4324 /**
4325 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4326 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4327 *
4328 * @param itemID the ID of the item to read
4329 * @param itemValue the value to write, as a String
4330 * @return true on success; false on any failure
4331 */
4332 @Override
4333 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004334 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4336 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004337
4338 final long identity = Binder.clearCallingIdentity();
4339 try {
4340 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4341 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004342 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4344 return success;
4345 } finally {
4346 Binder.restoreCallingIdentity(identity);
4347 }
Jake Hambye994d462014-02-03 13:10:13 -08004348 }
4349
4350 /**
4351 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4352 * Used for device configuration by some CDMA operators.
4353 *
4354 * @param preferredRoamingList byte array containing the new PRL
4355 * @return true on success; false on any failure
4356 */
4357 @Override
4358 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4360 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004361
4362 final long identity = Binder.clearCallingIdentity();
4363 try {
4364 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4365 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4366 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4367 return success;
4368 } finally {
4369 Binder.restoreCallingIdentity(identity);
4370 }
Jake Hambye994d462014-02-03 13:10:13 -08004371 }
4372
4373 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004374 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004375 * Used for device configuration by some CDMA operators.
4376 *
chen xu6dac5ab2018-10-26 17:39:23 -07004377 * @param slotIndex - device slot.
4378 *
Jake Hambye994d462014-02-03 13:10:13 -08004379 * @return true on success; false on any failure
4380 */
4381 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004382 public boolean resetModemConfig(int slotIndex) {
4383 Phone phone = PhoneFactory.getPhone(slotIndex);
4384 if (phone != null) {
4385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4386 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387
chen xu6dac5ab2018-10-26 17:39:23 -07004388 final long identity = Binder.clearCallingIdentity();
4389 try {
4390 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4391 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4392 return success;
4393 } finally {
4394 Binder.restoreCallingIdentity(identity);
4395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004396 }
chen xu6dac5ab2018-10-26 17:39:23 -07004397 return false;
4398 }
4399
4400 /**
4401 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4402 *
4403 * @param slotIndex - device slot.
4404 *
4405 * @return true on success; false on any failure
4406 */
4407 @Override
4408 public boolean rebootModem(int slotIndex) {
4409 Phone phone = PhoneFactory.getPhone(slotIndex);
4410 if (phone != null) {
4411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4412 mApp, phone.getSubId(), "rebootModem");
4413
4414 final long identity = Binder.clearCallingIdentity();
4415 try {
4416 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4417 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4418 return success;
4419 } finally {
4420 Binder.restoreCallingIdentity(identity);
4421 }
4422 }
4423 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004424 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004425
Svet Ganovb320e182015-04-16 12:30:10 -07004426 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004427 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004428 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004429 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004430 return new String[0];
4431 }
4432
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004433 final long identity = Binder.clearCallingIdentity();
4434 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004435 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004436 } finally {
4437 Binder.restoreCallingIdentity(identity);
4438 }
Wink Saville36469e72014-06-11 15:17:00 -07004439 }
4440
Brad Ebinger51f743a2017-01-23 13:50:20 -08004441 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004442 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4443 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004444 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004445 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004446 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447
4448 final long identity = Binder.clearCallingIdentity();
4449 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004450 ImsResolver resolver = PhoneFactory.getImsResolver();
4451 if (resolver == null) {
4452 // may happen if the device does not support IMS.
4453 return;
4454 }
4455 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 } finally {
4457 Binder.restoreCallingIdentity(identity);
4458 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004459 }
4460
4461 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004462 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4463 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004464 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004465 public void disableIms(int slotId) {
4466 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004467
4468 final long identity = Binder.clearCallingIdentity();
4469 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004470 ImsResolver resolver = PhoneFactory.getImsResolver();
4471 if (resolver == null) {
4472 // may happen if the device does not support IMS.
4473 return;
4474 }
4475 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004476 } finally {
4477 Binder.restoreCallingIdentity(identity);
4478 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004479 }
4480
4481 /**
4482 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4483 * feature or {@link null} if the service is not available. If the feature is available, the
4484 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4485 */
4486 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004487 IImsServiceFeatureCallback callback) {
4488 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004489
4490 final long identity = Binder.clearCallingIdentity();
4491 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004492 ImsResolver resolver = PhoneFactory.getImsResolver();
4493 if (resolver == null) {
4494 // may happen if the device does not support IMS.
4495 return null;
4496 }
4497 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004501 }
4502
4503 /**
4504 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4505 * feature during emergency calling or {@link null} if the service is not available. If the
4506 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4507 * listener for feature updates.
4508 */
4509 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4510 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004511
4512 final long identity = Binder.clearCallingIdentity();
4513 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004514 ImsResolver resolver = PhoneFactory.getImsResolver();
4515 if (resolver == null) {
4516 // may happen if the device does not support IMS.
4517 return null;
4518 }
4519 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004520 } finally {
4521 Binder.restoreCallingIdentity(identity);
4522 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004523 }
4524
Brad Ebinger5f64b052017-12-14 14:26:15 -08004525 /**
4526 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004527 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004528 */
4529 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4530 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004531
4532 final long identity = Binder.clearCallingIdentity();
4533 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004534 ImsResolver resolver = PhoneFactory.getImsResolver();
4535 if (resolver == null) {
4536 // may happen if the device does not support IMS.
4537 return null;
4538 }
4539 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 } finally {
4541 Binder.restoreCallingIdentity(identity);
4542 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004543 }
4544
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004545 /**
4546 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004547 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004548 */
4549 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
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.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004560 } finally {
4561 Binder.restoreCallingIdentity(identity);
4562 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004563 }
4564
Brad Ebinger884c07b2018-02-15 16:17:40 -08004565 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004566 * Sets the ImsService Package Name that Telephony will bind to.
4567 *
4568 * @param slotId the slot ID that the ImsService should bind for.
4569 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4570 * ImsService is the device default ImsService.
4571 * @param packageName The package name of the application that contains the ImsService to bind
4572 * to.
4573 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4574 * @hide
4575 */
4576 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004577 int[] subIds = SubscriptionManager.getSubId(slotId);
4578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4579 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4580 "setImsService");
4581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004582 final long identity = Binder.clearCallingIdentity();
4583 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004584 ImsResolver resolver = PhoneFactory.getImsResolver();
4585 if (resolver == null) {
4586 // may happen if the device does not support IMS.
4587 return false;
4588 }
4589 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4590 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591 } finally {
4592 Binder.restoreCallingIdentity(identity);
4593 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004594 }
4595
4596 /**
4597 * Return the ImsService configuration.
4598 *
4599 * @param slotId The slot that the ImsService is associated with.
4600 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4601 * the device default.
4602 * @return the package name of the ImsService configuration.
4603 */
4604 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004605 int[] subIds = SubscriptionManager.getSubId(slotId);
4606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4607 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4608 "getImsService");
4609
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004610 final long identity = Binder.clearCallingIdentity();
4611 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004612 ImsResolver resolver = PhoneFactory.getImsResolver();
4613 if (resolver == null) {
4614 // may happen if the device does not support IMS.
4615 return "";
4616 }
4617 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004618 } finally {
4619 Binder.restoreCallingIdentity(identity);
4620 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004621 }
4622
Brad Ebinger77b832e2019-10-17 17:03:22 -07004623 /**
4624 * Get the MmTelFeature state associated with the requested subscription id.
4625 * @param subId The subscription that the MmTelFeature is associated with.
4626 * @param callback A callback with an integer containing the
4627 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4628 */
4629 @Override
4630 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4631 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4632 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4633 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4634 "IMS not available on device.");
4635 }
4636 final long token = Binder.clearCallingIdentity();
4637 try {
4638 int slotId = getSlotIndex(subId);
4639 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4640 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4641 + subId + "'");
4642 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4643 }
4644 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4645 try {
4646 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4647 } catch (RemoteException e) {
4648 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4649 + "Ignore");
4650 }
4651 });
4652 } finally {
4653 Binder.restoreCallingIdentity(token);
4654 }
4655 }
4656
Wink Saville36469e72014-06-11 15:17:00 -07004657 public void setImsRegistrationState(boolean registered) {
4658 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004659
4660 final long identity = Binder.clearCallingIdentity();
4661 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004662 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004663 } finally {
4664 Binder.restoreCallingIdentity(identity);
4665 }
Wink Saville36469e72014-06-11 15:17:00 -07004666 }
4667
4668 /**
Stuart Scott54788802015-03-30 13:18:01 -07004669 * Set the network selection mode to automatic.
4670 *
4671 */
4672 @Override
4673 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4675 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004676
Pengquan Menge92a50d2018-09-21 15:54:48 -07004677 if (!isActiveSubscription(subId)) {
4678 return;
4679 }
4680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681 final long identity = Binder.clearCallingIdentity();
4682 try {
4683 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4684 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4685 } finally {
4686 Binder.restoreCallingIdentity(identity);
4687 }
Stuart Scott54788802015-03-30 13:18:01 -07004688 }
4689
Pengquan Mengea84e042018-09-20 14:57:26 -07004690 /**
4691 * Ask the radio to connect to the input network and change selection mode to manual.
4692 *
4693 * @param subId the id of the subscription.
4694 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4695 * the operator to attach to.
4696 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4697 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4698 * normal network selection next time.
4699 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004700 */
4701 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004702 public boolean setNetworkSelectionModeManual(
4703 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4705 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004706
4707 if (!isActiveSubscription(subId)) {
4708 return false;
4709 }
4710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711 final long identity = Binder.clearCallingIdentity();
4712 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004713 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004714 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004715 if (DBG) {
4716 log("setNetworkSelectionModeManual: subId: " + subId
4717 + " operator: " + operatorInfo);
4718 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4720 } finally {
4721 Binder.restoreCallingIdentity(identity);
4722 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004723 }
4724
4725 /**
4726 * Scans for available networks.
4727 */
4728 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004729 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4731 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004732 LocationAccessPolicy.LocationPermissionResult locationResult =
4733 LocationAccessPolicy.checkLocationPermission(mApp,
4734 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4735 .setCallingPackage(callingPackage)
4736 .setCallingPid(Binder.getCallingPid())
4737 .setCallingUid(Binder.getCallingUid())
4738 .setMethod("getCellNetworkScanResults")
4739 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4740 .build());
4741 switch (locationResult) {
4742 case DENIED_HARD:
4743 throw new SecurityException("Not allowed to access scan results -- location");
4744 case DENIED_SOFT:
4745 return null;
4746 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004747
Pengquan Menga1bb6272018-09-06 09:59:22 -07004748 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004749 try {
4750 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004751 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004752 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004753 } finally {
4754 Binder.restoreCallingIdentity(identity);
4755 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004756 }
4757
4758 /**
yinxub1bed742017-04-17 11:45:04 -07004759 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004760 *
yinxub1bed742017-04-17 11:45:04 -07004761 * @param subId id of the subscription
4762 * @param request contains the radio access networks with bands/channels to scan
4763 * @param messenger callback messenger for scan results or errors
4764 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004765 * @return the id of the requested scan which can be used to stop the scan.
4766 */
4767 @Override
4768 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004769 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4771 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004772 LocationAccessPolicy.LocationPermissionResult locationResult =
4773 LocationAccessPolicy.checkLocationPermission(mApp,
4774 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4775 .setCallingPackage(callingPackage)
4776 .setCallingPid(Binder.getCallingPid())
4777 .setCallingUid(Binder.getCallingUid())
4778 .setMethod("requestNetworkScan")
4779 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4780 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004781 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004782 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004783 if (e != null) {
4784 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4785 throw e;
4786 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004787 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004788 return TelephonyScanManager.INVALID_SCAN_ID;
4789 }
4790 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004791 }
Hall Liu912dfd32019-04-25 14:02:26 -07004792 int callingUid = Binder.getCallingUid();
4793 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004794 final long identity = Binder.clearCallingIdentity();
4795 try {
4796 return mNetworkScanRequestTracker.startNetworkScan(
4797 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004798 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004799 } finally {
4800 Binder.restoreCallingIdentity(identity);
4801 }
yinxu504e1392017-04-12 16:03:22 -07004802 }
4803
Hall Liub2ac8ef2019-02-28 15:56:23 -08004804 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004805 NetworkScanRequest request, int subId) {
4806 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4807 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4808 boolean hasNetworkScanPermission =
4809 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4810 == PERMISSION_GRANTED;
4811
4812 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4813 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4814 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004815 }
4816
4817 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4818 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004819 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4820 return new SecurityException("Specific channels must not be"
4821 + " scanned without location access.");
4822 }
4823 }
4824 }
4825
Hall Liub2ac8ef2019-02-28 15:56:23 -08004826 return null;
4827 }
4828
yinxu504e1392017-04-12 16:03:22 -07004829 /**
4830 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004831 *
4832 * @param subId id of the subscription
4833 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004834 */
4835 @Override
4836 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4838 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004839
Hall Liu912dfd32019-04-25 14:02:26 -07004840 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004841 final long identity = Binder.clearCallingIdentity();
4842 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004843 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004844 } finally {
4845 Binder.restoreCallingIdentity(identity);
4846 }
yinxu504e1392017-04-12 16:03:22 -07004847 }
4848
4849 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004850 * Get the calculated preferred network type.
4851 * Used for debugging incorrect network type.
4852 *
4853 * @return the preferred network type, defined in RILConstants.java.
4854 */
4855 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004856 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004857 final Phone defaultPhone = getDefaultPhone();
4858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4859 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004860 return RILConstants.PREFERRED_NETWORK_MODE;
4861 }
4862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004863 final long identity = Binder.clearCallingIdentity();
4864 try {
4865 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004866 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004867 } finally {
4868 Binder.restoreCallingIdentity(identity);
4869 }
Junda Liu84d15a22014-07-02 11:21:04 -07004870 }
4871
4872 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004873 * Get the preferred network type.
4874 * Used for device configuration by some CDMA operators.
4875 *
4876 * @return the preferred network type, defined in RILConstants.java.
4877 */
4878 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004879 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004880 TelephonyPermissions
4881 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4882 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004883
4884 final long identity = Binder.clearCallingIdentity();
4885 try {
4886 if (DBG) log("getPreferredNetworkType");
4887 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4888 int networkType = (result != null ? result[0] : -1);
4889 if (DBG) log("getPreferredNetworkType: " + networkType);
4890 return networkType;
4891 } finally {
4892 Binder.restoreCallingIdentity(identity);
4893 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004894 }
4895
4896 /**
4897 * Set the preferred network type.
4898 * Used for device configuration by some CDMA operators.
4899 *
4900 * @param networkType the preferred network type, defined in RILConstants.java.
4901 * @return true on success; false on any failure.
4902 */
4903 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004904 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4906 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907
4908 final long identity = Binder.clearCallingIdentity();
4909 try {
4910 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4911 Boolean success = (Boolean) sendRequest(
4912 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4913 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4914 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004915 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004916 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4917 }
4918 return success;
4919 } finally {
4920 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004921 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004922 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004923
4924 /**
Miaoa84611c2019-03-15 09:21:10 +08004925 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004926 *
Miaoa84611c2019-03-15 09:21:10 +08004927 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004928 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004929 * @hide
4930 */
4931 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004932 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004933 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004935 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 try {
Miaoa84611c2019-03-15 09:21:10 +08004937 if (phone != null) {
4938 return phone.hasMatchedTetherApnSetting();
4939 } else {
4940 return false;
4941 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004942 } finally {
4943 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004944 }
Junda Liu475951f2014-11-07 16:45:03 -08004945 }
4946
4947 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004948 * Set mobile data enabled
4949 * Used by the user through settings etc to turn on/off mobile data
4950 *
4951 * @param enable {@code true} turn turn data on, else {@code false}
4952 */
4953 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004954 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4956 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004957
4958 final long identity = Binder.clearCallingIdentity();
4959 try {
4960 int phoneId = mSubscriptionController.getPhoneId(subId);
4961 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4962 Phone phone = PhoneFactory.getPhone(phoneId);
4963 if (phone != null) {
4964 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004965 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004967 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968 }
4969 } finally {
4970 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004971 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004972 }
4973
4974 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004975 * Get the user enabled state of Mobile Data.
4976 *
4977 * TODO: remove and use isUserDataEnabled.
4978 * This can't be removed now because some vendor codes
4979 * calls through ITelephony directly while they should
4980 * use TelephonyManager.
4981 *
4982 * @return true on enabled
4983 */
4984 @Override
4985 public boolean getDataEnabled(int subId) {
4986 return isUserDataEnabled(subId);
4987 }
4988
4989 /**
4990 * Get whether mobile data is enabled per user setting.
4991 *
4992 * There are other factors deciding whether mobile data is actually enabled, but they are
4993 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004994 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004995 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004996 *
4997 * @return {@code true} if data is enabled else {@code false}
4998 */
4999 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005000 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005001 try {
5002 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5003 null);
5004 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5006 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008
5009 final long identity = Binder.clearCallingIdentity();
5010 try {
5011 int phoneId = mSubscriptionController.getPhoneId(subId);
5012 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5013 Phone phone = PhoneFactory.getPhone(phoneId);
5014 if (phone != null) {
5015 boolean retVal = phone.isUserDataEnabled();
5016 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5017 return retVal;
5018 } else {
5019 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5020 return false;
5021 }
5022 } finally {
5023 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005024 }
5025 }
5026
5027 /**
5028 * Get whether mobile data is enabled.
5029 *
5030 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5031 * whether mobile data is actually enabled.
5032 *
5033 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5034 *
5035 * @return {@code true} if data is enabled else {@code false}
5036 */
5037 @Override
5038 public boolean isDataEnabled(int subId) {
5039 try {
5040 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5041 null);
5042 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5044 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005045 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046
5047 final long identity = Binder.clearCallingIdentity();
5048 try {
5049 int phoneId = mSubscriptionController.getPhoneId(subId);
5050 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5051 Phone phone = PhoneFactory.getPhone(phoneId);
5052 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005053 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5055 return retVal;
5056 } else {
5057 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5058 return false;
5059 }
5060 } finally {
5061 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005062 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005063 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005064
Nazanin Bakhshi63d0a362019-08-19 16:29:37 -07005065 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5066 Phone phone) {
5067 //load access rules from carrier configs, and check those as well: b/139133814
5068 SubscriptionController subController = SubscriptionController.getInstance();
5069 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5070 || subController == null) return privilegeFromSim;
5071
5072 int uid = Binder.getCallingUid();
5073 PackageManager pkgMgr = phone.getContext().getPackageManager();
5074 String[] packages = pkgMgr.getPackagesForUid(uid);
5075
5076 final long identity = Binder.clearCallingIdentity();
5077 try {
5078 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5079 SubscriptionManager subManager = (SubscriptionManager)
5080 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5081 for (String pkg : packages) {
5082 if (subManager.canManageSubscription(subInfo, pkg)) {
5083 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5084 }
5085 }
5086 return privilegeFromSim;
5087 } finally {
5088 Binder.restoreCallingIdentity(identity);
5089 }
5090 }
5091
5092 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5093 String pkgName) {
5094 //load access rules from carrier configs, and check those as well: b/139133814
5095 SubscriptionController subController = SubscriptionController.getInstance();
5096 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5097 || subController == null) return privilegeFromSim;
5098
5099 final long identity = Binder.clearCallingIdentity();
5100 try {
5101 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5102 SubscriptionManager subManager = (SubscriptionManager)
5103 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5104 return subManager.canManageSubscription(subInfo, pkgName)
5105 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5106 } finally {
5107 Binder.restoreCallingIdentity(identity);
5108 }
5109 }
5110
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005111 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005112 public int getCarrierPrivilegeStatus(int subId) {
5113 final Phone phone = getPhone(subId);
5114 if (phone == null) {
5115 loge("getCarrierPrivilegeStatus: Invalid subId");
5116 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5117 }
5118 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005119 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005120 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005121 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5122 }
Nazanin Bakhshi63d0a362019-08-19 16:29:37 -07005123
5124 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5125 card.getCarrierPrivilegeStatusForCurrentTransaction(
5126 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005127 }
Junda Liu29340342014-07-10 15:23:27 -07005128
5129 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005130 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5131 final Phone phone = getPhone(subId);
5132 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005133 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005134 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5135 }
5136 UiccProfile profile =
5137 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5138 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005139 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005140 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5141 }
Nazanin Bakhshi63d0a362019-08-19 16:29:37 -07005142 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5143 profile.getCarrierPrivilegeStatusForUid(
5144 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005145 }
5146
5147 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005148 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5149 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005150 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005151 }
5152
5153 int phoneId = SubscriptionManager.getPhoneId(subId);
5154 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005155 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005156 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005157 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5158 }
Nazanin Bakhshi63d0a362019-08-19 16:29:37 -07005159 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5160 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5161 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005162 }
5163
5164 @Override
5165 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005166 if (TextUtils.isEmpty(pkgName))
5167 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005168 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5169 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5170 UiccCard card = UiccController.getInstance().getUiccCard(i);
5171 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005172 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005173 continue;
5174 }
5175
Nazanin Bakhshi63d0a362019-08-19 16:29:37 -07005176 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5177 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5178 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005179 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5180 break;
5181 }
5182 }
5183
5184 return result;
Junda Liu29340342014-07-10 15:23:27 -07005185 }
Derek Tan89e89d42014-07-08 17:00:10 -07005186
5187 @Override
Junda Liue64de782015-04-16 17:19:16 -07005188 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5189 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5190 loge("phoneId " + phoneId + " is not valid.");
5191 return null;
5192 }
5193 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005194 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005195 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005196 return null ;
5197 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005198 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005199 }
5200
Amith Yamasani6e118872016-02-19 12:53:51 -08005201 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005202 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005203 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005204 List<String> privilegedPackages = new ArrayList<>();
5205 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005206 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5207 // has UICC in that slot.
5208 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005209 if (card.hasCarrierPrivilegeRules()) {
5210 if (packages == null) {
5211 // Only check packages in user 0 for now
5212 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi63d0a362019-08-19 16:29:37 -07005213 PackageManager.MATCH_DISABLED_COMPONENTS
5214 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
5215 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005216 }
5217 for (int p = packages.size() - 1; p >= 0; p--) {
5218 PackageInfo pkgInfo = packages.get(p);
5219 if (pkgInfo != null && pkgInfo.packageName != null
5220 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005221 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005222 privilegedPackages.add(pkgInfo.packageName);
5223 }
5224 }
5225 }
5226 }
5227 return privilegedPackages;
5228 }
5229
chen xuf7e9fe82019-05-09 19:31:02 -07005230 @Override
5231 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5232 List<String> privilegedPackages = new ArrayList<>();
5233 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5234 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5235 }
5236 return privilegedPackages;
5237 }
5238
Wink Savilleb564aae2014-10-23 10:18:09 -07005239 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005240 final Phone phone = getPhone(subId);
5241 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005242 if (card == null) {
5243 loge("getIccId: No UICC");
5244 return null;
5245 }
5246 String iccId = card.getIccId();
5247 if (TextUtils.isEmpty(iccId)) {
5248 loge("getIccId: ICC ID is null or empty.");
5249 return null;
5250 }
5251 return iccId;
5252 }
5253
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005254 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005255 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5256 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005257 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5258 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 final long identity = Binder.clearCallingIdentity();
5261 try {
5262 final String iccId = getIccId(subId);
5263 final Phone phone = getPhone(subId);
5264 if (phone == null) {
5265 return false;
5266 }
5267 final String subscriberId = phone.getSubscriberId();
5268
5269 if (DBG_MERGE) {
5270 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5271 + subscriberId + " to " + number);
5272 }
5273
5274 if (TextUtils.isEmpty(iccId)) {
5275 return false;
5276 }
5277
5278 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5279
5280 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5281 if (alphaTag == null) {
5282 editor.remove(alphaTagPrefKey);
5283 } else {
5284 editor.putString(alphaTagPrefKey, alphaTag);
5285 }
5286
5287 // Record both the line number and IMSI for this ICCID, since we need to
5288 // track all merged IMSIs based on line number
5289 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5290 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5291 if (number == null) {
5292 editor.remove(numberPrefKey);
5293 editor.remove(subscriberPrefKey);
5294 } else {
5295 editor.putString(numberPrefKey, number);
5296 editor.putString(subscriberPrefKey, subscriberId);
5297 }
5298
5299 editor.commit();
5300 return true;
5301 } finally {
5302 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005303 }
Derek Tan7226c842014-07-02 17:42:23 -07005304 }
5305
5306 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005307 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005308 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005310 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005311 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005312 return null;
5313 }
Derek Tan97ebb422014-09-05 16:55:38 -07005314
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005315 final long identity = Binder.clearCallingIdentity();
5316 try {
5317 String iccId = getIccId(subId);
5318 if (iccId != null) {
5319 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5320 if (DBG_MERGE) {
5321 log("getLine1NumberForDisplay returning "
5322 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5323 }
5324 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5327 return null;
5328 } finally {
5329 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005330 }
Derek Tan7226c842014-07-02 17:42:23 -07005331 }
5332
5333 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005334 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005336 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005337 return null;
5338 }
Derek Tan97ebb422014-09-05 16:55:38 -07005339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340 final long identity = Binder.clearCallingIdentity();
5341 try {
5342 String iccId = getIccId(subId);
5343 if (iccId != null) {
5344 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5345 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5346 }
5347 return null;
5348 } finally {
5349 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005350 }
Derek Tan7226c842014-07-02 17:42:23 -07005351 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005352
5353 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005354 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005355 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5356 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005357 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005358 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5359 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005360 return null;
5361 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005362
Jordan Liub49b04b2019-05-06 14:45:15 -07005363 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5364 // the process, where TelephonyManager was instantiated.
5365 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005366 final long identity = Binder.clearCallingIdentity();
5367 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005368 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 final TelephonyManager tele = TelephonyManager.from(context);
5370 final SubscriptionManager sub = SubscriptionManager.from(context);
5371
5372 // Figure out what subscribers are currently active
5373 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374
Jordan Liub49b04b2019-05-06 14:45:15 -07005375 // Only consider subs which match the current subId
5376 // This logic can be simplified. See b/131189269 for progress.
5377 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005378 activeSubscriberIds.add(tele.getSubscriberId(subId));
5379 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380
5381 // First pass, find a number override for an active subscriber
5382 String mergeNumber = null;
5383 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5384 for (String key : prefs.keySet()) {
5385 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5386 final String subscriberId = (String) prefs.get(key);
5387 if (activeSubscriberIds.contains(subscriberId)) {
5388 final String iccId = key.substring(
5389 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5390 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5391 mergeNumber = (String) prefs.get(numberKey);
5392 if (DBG_MERGE) {
5393 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5394 + " for active subscriber " + subscriberId);
5395 }
5396 if (!TextUtils.isEmpty(mergeNumber)) {
5397 break;
5398 }
5399 }
5400 }
5401 }
5402
5403 // Shortcut when no active merged subscribers
5404 if (TextUtils.isEmpty(mergeNumber)) {
5405 return null;
5406 }
5407
5408 // Second pass, find all subscribers under that line override
5409 final ArraySet<String> result = new ArraySet<>();
5410 for (String key : prefs.keySet()) {
5411 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5412 final String number = (String) prefs.get(key);
5413 if (mergeNumber.equals(number)) {
5414 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5415 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5416 final String subscriberId = (String) prefs.get(subscriberKey);
5417 if (!TextUtils.isEmpty(subscriberId)) {
5418 result.add(subscriberId);
5419 }
5420 }
5421 }
5422 }
5423
5424 final String[] resultArray = result.toArray(new String[result.size()]);
5425 Arrays.sort(resultArray);
5426 if (DBG_MERGE) {
5427 Slog.d(LOG_TAG,
5428 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5429 }
5430 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005431 } finally {
5432 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005433 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005434 }
5435
5436 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005437 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5438 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5439
5440 final long identity = Binder.clearCallingIdentity();
5441 try {
5442 final TelephonyManager telephonyManager = mApp.getSystemService(
5443 TelephonyManager.class);
5444 String subscriberId = telephonyManager.getSubscriberId(subId);
5445 if (subscriberId == null) {
5446 if (DBG) {
5447 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5448 + subId);
5449 }
5450 return null;
5451 }
5452
5453 final SubscriptionInfo info = SubscriptionController.getInstance()
5454 .getSubscriptionInfo(subId);
5455 final ParcelUuid groupUuid = info.getGroupUuid();
5456 // If it doesn't belong to any group, return just subscriberId of itself.
5457 if (groupUuid == null) {
5458 return new String[]{subscriberId};
5459 }
5460
5461 // Get all subscriberIds from the group.
5462 final List<String> mergedSubscriberIds = new ArrayList<>();
5463 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5464 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5465 for (SubscriptionInfo subInfo : groupInfos) {
5466 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5467 if (subscriberId != null) {
5468 mergedSubscriberIds.add(subscriberId);
5469 }
5470 }
5471
5472 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5473 } finally {
5474 Binder.restoreCallingIdentity(identity);
5475
5476 }
5477 }
5478
5479 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005480 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005481 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5482 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483
5484 final long identity = Binder.clearCallingIdentity();
5485 try {
5486 final Phone phone = getPhone(subId);
5487 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5488 } finally {
5489 Binder.restoreCallingIdentity(identity);
5490 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005491 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005492
5493 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005494 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005495 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5496 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005497 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005498
5499 final long identity = Binder.clearCallingIdentity();
5500 try {
5501 final Phone phone = getPhone(subId);
5502 if (phone == null) {
5503 return false;
5504 }
5505 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5506 cdmaNonRoamingList);
5507 } finally {
5508 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005509 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005510 }
5511
5512 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005513 @Deprecated
5514 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5515 enforceModifyPermission();
5516
5517 int returnValue = 0;
5518 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005519 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005520 if(result.exception == null) {
5521 if (result.result != null) {
5522 byte[] responseData = (byte[])(result.result);
5523 if(responseData.length > oemResp.length) {
5524 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5525 responseData.length + "bytes. Buffer Size is " +
5526 oemResp.length + "bytes.");
5527 }
5528 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5529 returnValue = responseData.length;
5530 }
5531 } else {
5532 CommandException ex = (CommandException) result.exception;
5533 returnValue = ex.getCommandError().ordinal();
5534 if(returnValue > 0) returnValue *= -1;
5535 }
5536 } catch (RuntimeException e) {
5537 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5538 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5539 if(returnValue > 0) returnValue *= -1;
5540 }
5541
5542 return returnValue;
5543 }
5544
5545 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005546 public void setRadioCapability(RadioAccessFamily[] rafs) {
5547 try {
5548 ProxyController.getInstance().setRadioCapability(rafs);
5549 } catch (RuntimeException e) {
5550 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5551 }
5552 }
5553
5554 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005555 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005556 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005557 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005558 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005559 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005560 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561 final long identity = Binder.clearCallingIdentity();
5562 try {
chen xub97461a2018-10-26 14:17:57 -07005563 TelephonyPermissions
5564 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5565 mApp, phone.getSubId(), "getRadioAccessFamily");
5566 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567 } finally {
5568 Binder.restoreCallingIdentity(identity);
5569 }
chen xub97461a2018-10-26 14:17:57 -07005570 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005571 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005572
5573 @Override
5574 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005575 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005576 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577
5578 final long identity = Binder.clearCallingIdentity();
5579 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005580 ImsManager.getInstance(defaultPhone.getContext(),
5581 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 } finally {
5583 Binder.restoreCallingIdentity(identity);
5584 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005585 }
5586
5587 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005588 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005589 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005591 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005592 return false;
5593 }
Svet Ganovb320e182015-04-16 12:30:10 -07005594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595 final long identity = Binder.clearCallingIdentity();
5596 try {
5597 // Check the user preference and the system-level IMS setting. Even if the user has
5598 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5599 // In the long run, we may instead need to check if there exists a connection service
5600 // which can support video calling.
5601 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005602 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603 return imsManager.isVtEnabledByPlatform()
5604 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5605 && imsManager.isVtEnabledByUser();
5606 } finally {
5607 Binder.restoreCallingIdentity(identity);
5608 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005609 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005610
Andrew Leea1239f22015-03-02 17:44:07 -08005611 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5613 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5614 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5615 return false;
5616 }
5617
5618 final long identity = Binder.clearCallingIdentity();
5619 try {
5620 CarrierConfigManager configManager =
5621 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005622 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5624 } finally {
5625 Binder.restoreCallingIdentity(identity);
5626 }
Andrew Leea1239f22015-03-02 17:44:07 -08005627 }
5628
5629 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630 public boolean isWorldPhone(int subId, String callingPackage) {
5631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5632 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5633 return false;
5634 }
5635
5636 final long identity = Binder.clearCallingIdentity();
5637 try {
5638 CarrierConfigManager configManager =
5639 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005640 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5642 } finally {
5643 Binder.restoreCallingIdentity(identity);
5644 }
Andrew Leea1239f22015-03-02 17:44:07 -08005645 }
5646
Andrew Lee9431b832015-03-09 18:46:45 -07005647 @Override
5648 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005649 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005650 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005651 }
5652
5653 @Override
5654 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655 final long identity = Binder.clearCallingIdentity();
5656 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005657 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658 } finally {
5659 Binder.restoreCallingIdentity(identity);
5660 }
Andrew Lee9431b832015-03-09 18:46:45 -07005661 }
5662
Hall Liuf6668912018-10-31 17:05:23 -07005663 /**
5664 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5665 * support for the feature and device firmware support.
5666 *
5667 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5668 */
5669 @Override
5670 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005672 final Phone phone = getPhone(subscriptionId);
5673 if (phone == null) {
5674 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5675 return false;
5676 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005678 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5680 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005681 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 return isCarrierSupported && isDeviceSupported;
5683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
Hall Liu98187582018-01-22 19:15:32 -08005686 }
5687
Hall Liuf6668912018-10-31 17:05:23 -07005688 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005689 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5690 * RTT setting, will return true if the device and carrier both support RTT.
5691 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005692 */
5693 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 final long identity = Binder.clearCallingIdentity();
5695 try {
Hall Liu6a06be62019-07-23 18:39:00 -07005696 boolean isRttSupported = isRttSupported(subscriptionId);
5697 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005698 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liu6a06be62019-07-23 18:39:00 -07005699 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5700 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5701 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 } finally {
5703 Binder.restoreCallingIdentity(identity);
5704 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005705 }
5706
Sanket Padawe7310cc72015-01-14 09:53:20 -08005707 /**
5708 * Returns the unique device ID of phone, for example, the IMEI for
5709 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5710 *
5711 * <p>Requires Permission:
5712 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5713 */
5714 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005715 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005716 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005717 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005718 return null;
5719 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005720 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005721 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5722 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005723 return null;
5724 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725
5726 final long identity = Binder.clearCallingIdentity();
5727 try {
5728 return phone.getDeviceId();
5729 } finally {
5730 Binder.restoreCallingIdentity(identity);
5731 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005732 }
5733
Ping Sunc67b7c22016-03-02 19:16:45 +08005734 /**
5735 * {@hide}
5736 * Returns the IMS Registration Status on a particular subid
5737 *
5738 * @param subId
5739 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005740 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005741 Phone phone = getPhone(subId);
5742 if (phone != null) {
5743 return phone.isImsRegistered();
5744 } else {
5745 return false;
5746 }
5747 }
5748
Santos Cordon7a1885b2015-02-03 11:15:19 -08005749 @Override
5750 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 final long identity = Binder.clearCallingIdentity();
5752 try {
5753 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5754 } finally {
5755 Binder.restoreCallingIdentity(identity);
5756 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005757 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005758
Tyler Gunnf70ed162019-04-03 15:28:53 -07005759 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005760 public int getSubIdForPhoneAccountHandle(
5761 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5763 callingPackage, "getSubIdForPhoneAccountHandle")) {
5764 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5765 }
5766 final long identity = Binder.clearCallingIdentity();
5767 try {
5768 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
5772 }
5773
5774 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005775 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5776 final long identity = Binder.clearCallingIdentity();
5777 try {
5778 Phone phone = getPhone(subscriptionId);
5779 if (phone == null) {
5780 return null;
5781 }
5782 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5783 } finally {
5784 Binder.restoreCallingIdentity(identity);
5785 }
5786 }
5787
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005788 /**
5789 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005790 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005791 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792 final long identity = Binder.clearCallingIdentity();
5793 try {
5794 Phone phone = getPhone(subId);
5795 if (phone != null) {
5796 return phone.isWifiCallingEnabled();
5797 } else {
5798 return false;
5799 }
5800 } finally {
5801 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005802 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005803 }
5804
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005805 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005806 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005807 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005808 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005809 final long identity = Binder.clearCallingIdentity();
5810 try {
5811 Phone phone = getPhone(subId);
5812 if (phone != null) {
5813 return phone.isVideoEnabled();
5814 } else {
5815 return false;
5816 }
5817 } finally {
5818 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005819 }
5820 }
5821
5822 /**
5823 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5824 * defined in {@link ImsRegistrationImplBase}.
5825 */
5826 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 final long identity = Binder.clearCallingIdentity();
5828 try {
5829 Phone phone = getPhone(subId);
5830 if (phone != null) {
5831 return phone.getImsRegistrationTech();
5832 } else {
5833 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5834 }
5835 } finally {
5836 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005837 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005838 }
5839
Stuart Scott8eef64f2015-04-08 15:13:54 -07005840 @Override
5841 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08005842 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005843 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5844 return;
5845 }
5846
Svet Ganovcc087f82015-05-12 20:35:54 -07005847 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005848
Svet Ganovcc087f82015-05-12 20:35:54 -07005849 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005850 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5851 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005852 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005853 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005854 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005855 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5856 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005857 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005858 // There has been issues when Sms raw table somehow stores orphan
5859 // fragments. They lead to garbled message when new fragments come
5860 // in and combined with those stale ones. In case this happens again,
5861 // user can reset all network settings which will clean up this table.
5862 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005863 // Clean up IMS settings as well here.
5864 int slotId = getSlotIndex(subId);
5865 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5866 ImsManager.getInstance(mApp, slotId).factoryReset();
5867 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07005868
5869 // Erase modem config if erase modem on network setting is enabled.
5870 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5871 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5872 if (configValue != null && Boolean.parseBoolean(configValue)) {
5873 sendEraseModemConfig(getDefaultPhone());
5874 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005875 } finally {
5876 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005877 }
5878 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005879
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005880 private void cleanUpSmsRawTable(Context context) {
5881 ContentResolver resolver = context.getContentResolver();
5882 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5883 resolver.delete(uri, null, null);
5884 }
5885
Narayan Kamath1c496c22015-04-16 14:40:19 +01005886 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005887 public String getSimLocaleForSubscriber(int subId) {
5888 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5889 final Phone phone = getPhone(subId);
5890 if (phone == null) {
5891 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005892 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005893 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 final long identity = Binder.clearCallingIdentity();
5895 try {
chen xu5d3637b2019-01-21 23:31:38 -08005896 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5897 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005898 if (info == null) {
5899 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5900 return null;
5901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 // Try and fetch the locale from the carrier properties or from the SIM language
5903 // preferences (EF-PL and EF-LI)...
5904 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005905 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005906 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5907 if (localeFromDefaultSim != null) {
5908 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5909 if (DBG) log("Using locale from subId: " + subId + " locale: "
5910 + localeFromDefaultSim);
5911 return localeFromDefaultSim.toLanguageTag();
5912 } else {
5913 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914 }
5915 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005916
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917 // The SIM language preferences only store a language (e.g. fr = French), not an
5918 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5919 // the SIM and carrier preferences does not include a country we add the country
5920 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005921 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005923 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005924 return mccLocale.toLanguageTag();
5925 }
5926
5927 if (DBG) log("No locale found - returning null");
5928 return null;
5929 } finally {
5930 Binder.restoreCallingIdentity(identity);
5931 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005932 }
5933
5934 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005935 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005936 }
5937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005938 /**
5939 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5940 */
5941 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005942 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005943 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005944
Chenjie Yu1ba97252018-01-11 18:16:20 -08005945 private final ModemActivityInfo mLastModemActivityInfo =
5946 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5947
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005948 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005949 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5950 * representing the state of the modem.
5951 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005952 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5953 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005954 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005955 */
5956 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005957 public void requestModemActivityInfo(ResultReceiver result) {
5958 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005959 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960
5961 final long identity = Binder.clearCallingIdentity();
5962 try {
5963 ModemActivityInfo ret = null;
5964 synchronized (mLastModemActivityInfo) {
5965 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5966 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005967 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005968 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5970 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005971 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5972 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005973 }
5974 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005975 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5976 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005977 mLastModemActivityInfo.setIdleTimeMillis(
5978 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5979 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5980 mLastModemActivityInfo.setRxTimeMillis(
5981 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5982 mLastModemActivityInfo.setEnergyUsed(
5983 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5986 mLastModemActivityInfo.getSleepTimeMillis(),
5987 mLastModemActivityInfo.getIdleTimeMillis(),
5988 mLastModemActivityInfo.getTxTimeMillis(),
5989 mLastModemActivityInfo.getRxTimeMillis(),
5990 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 Bundle bundle = new Bundle();
5993 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5994 result.send(0, bundle);
5995 } finally {
5996 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005997 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005998 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005999
Siddharth Rayb8114062018-06-17 15:02:38 -07006000 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6001 // less than total activity duration.
6002 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6003 if (info == null) {
6004 return false;
6005 }
6006 int activityDurationMs =
6007 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6008 int totalTxTimeMs = 0;
6009 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
6010 totalTxTimeMs += info.getTxTimeMillis()[i];
6011 }
6012 return (info.isValid()
6013 && (info.getSleepTimeMillis() <= activityDurationMs)
6014 && (info.getIdleTimeMillis() <= activityDurationMs)
6015 && (info.getRxTimeMillis() <= activityDurationMs)
6016 && (totalTxTimeMs <= activityDurationMs));
6017 }
6018
Jack Yu85bd38a2015-11-09 11:34:32 -08006019 /**
6020 * {@hide}
6021 * Returns the service state information on specified subscription.
6022 */
6023 @Override
6024 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006025 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006026 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006027 return null;
6028 }
6029
Hall Liuf19c44f2018-11-27 14:38:17 -08006030 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6031 LocationAccessPolicy.checkLocationPermission(mApp,
6032 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6033 .setCallingPackage(callingPackage)
6034 .setCallingPid(Binder.getCallingPid())
6035 .setCallingUid(Binder.getCallingUid())
6036 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006037 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006038 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6039 .build());
6040
6041 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6042 LocationAccessPolicy.checkLocationPermission(mApp,
6043 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6044 .setCallingPackage(callingPackage)
6045 .setCallingPid(Binder.getCallingPid())
6046 .setCallingUid(Binder.getCallingUid())
6047 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006048 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006049 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6050 .build());
6051 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6052 boolean hasFinePermission =
6053 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6054 boolean hasCoarsePermission =
6055 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057 final long identity = Binder.clearCallingIdentity();
6058 try {
6059 final Phone phone = getPhone(subId);
6060 if (phone == null) {
6061 return null;
6062 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006063
Hall Liuf19c44f2018-11-27 14:38:17 -08006064 ServiceState ss = phone.getServiceState();
6065
6066 // Scrub out the location info in ServiceState depending on what level of access
6067 // the caller has.
6068 if (hasFinePermission) return ss;
6069 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6070 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 } finally {
6072 Binder.restoreCallingIdentity(identity);
6073 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006074 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006075
6076 /**
6077 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6078 *
6079 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6080 * voicemail ringtone.
6081 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6082 * PhoneAccount.
6083 */
6084 @Override
6085 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086 final long identity = Binder.clearCallingIdentity();
6087 try {
6088 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6089 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006090 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6094 } finally {
6095 Binder.restoreCallingIdentity(identity);
6096 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006097 }
6098
6099 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006100 * Sets the per-account voicemail ringtone.
6101 *
6102 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6103 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6104 *
6105 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6106 * voicemail ringtone.
6107 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6108 * PhoneAccount.
6109 */
6110 @Override
6111 public void setVoicemailRingtoneUri(String callingPackage,
6112 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006113 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006114 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006115 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6116 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6118 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6119 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006120 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121
6122 final long identity = Binder.clearCallingIdentity();
6123 try {
6124 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6125 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006126 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006127 }
6128 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6129 } finally {
6130 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006131 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006132 }
6133
6134 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006135 * Returns whether vibration is set for voicemail notification in Phone settings.
6136 *
6137 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6138 * voicemail vibration setting.
6139 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6140 */
6141 @Override
6142 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 final long identity = Binder.clearCallingIdentity();
6144 try {
6145 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6146 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006147 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006149
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006150 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6151 } finally {
6152 Binder.restoreCallingIdentity(identity);
6153 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006154 }
6155
Youhan Wange64578a2016-05-02 15:32:42 -07006156 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006157 * Sets the per-account voicemail vibration.
6158 *
6159 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6160 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6161 *
6162 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6163 * voicemail vibration setting.
6164 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6165 * specific PhoneAccount.
6166 */
6167 @Override
6168 public void setVoicemailVibrationEnabled(String callingPackage,
6169 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006170 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006171 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006172 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6173 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6175 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6176 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006177 }
6178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006179 final long identity = Binder.clearCallingIdentity();
6180 try {
6181 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6182 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006183 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006184 }
6185 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6186 } finally {
6187 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006188 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006189 }
6190
6191 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006192 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6193 *
6194 * @throws SecurityException if the caller does not have the required permission
6195 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006196 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006197 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006198 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006199 }
6200
6201 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006202 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6203 * permission.
6204 *
6205 * @throws SecurityException if the caller does not have the required permission
6206 */
6207 private void enforceSendSmsPermission() {
6208 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6209 }
6210
6211 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006212 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006213 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006214 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006215 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006216 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006217 final long identity = Binder.clearCallingIdentity();
6218 try {
6219 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006220 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006221 if (componentName == null) {
6222 throw new SecurityException(
6223 "Caller not current active visual voicemail package[null]");
6224 }
6225 String vvmPackage = componentName.getPackageName();
6226 if (!callingPackage.equals(vvmPackage)) {
6227 throw new SecurityException("Caller not current active visual voicemail package["
6228 + vvmPackage + "]");
6229 }
6230 } finally {
6231 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006232 }
6233 }
6234
6235 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006236 * Return the application ID for the app type.
6237 *
6238 * @param subId the subscription ID that this request applies to.
6239 * @param appType the uicc app type.
6240 * @return Application ID for specificied app type, or null if no uicc.
6241 */
6242 @Override
6243 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006244 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006245 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006246
6247 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006248 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249 if (phone == null) {
6250 return null;
6251 }
6252 String aid = null;
6253 try {
6254 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6255 .getApplicationByType(appType).getAid();
6256 } catch (Exception e) {
6257 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6258 }
6259 return aid;
6260 } finally {
6261 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006262 }
Youhan Wange64578a2016-05-02 15:32:42 -07006263 }
6264
Youhan Wang4001d252016-05-11 10:29:41 -07006265 /**
6266 * Return the Electronic Serial Number.
6267 *
6268 * @param subId the subscription ID that this request applies to.
6269 * @return ESN or null if error.
6270 */
6271 @Override
6272 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006273 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006274 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275
6276 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006277 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278 if (phone == null) {
6279 return null;
6280 }
6281 String esn = null;
6282 try {
6283 esn = phone.getEsn();
6284 } catch (Exception e) {
6285 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6286 }
6287 return esn;
6288 } finally {
6289 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006290 }
Youhan Wang4001d252016-05-11 10:29:41 -07006291 }
6292
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006293 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006294 * Return the Preferred Roaming List Version.
6295 *
6296 * @param subId the subscription ID that this request applies to.
6297 * @return PRLVersion or null if error.
6298 */
6299 @Override
6300 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006301 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006302 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006303
6304 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006305 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 if (phone == null) {
6307 return null;
6308 }
6309 String cdmaPrlVersion = null;
6310 try {
6311 cdmaPrlVersion = phone.getCdmaPrlVersion();
6312 } catch (Exception e) {
6313 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6314 }
6315 return cdmaPrlVersion;
6316 } finally {
6317 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006318 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006319 }
6320
6321 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006322 * Get snapshot of Telephony histograms
6323 * @return List of Telephony histograms
6324 * @hide
6325 */
6326 @Override
6327 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6329 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006330
6331 final long identity = Binder.clearCallingIdentity();
6332 try {
6333 return RIL.getTelephonyRILTimingHistograms();
6334 } finally {
6335 Binder.restoreCallingIdentity(identity);
6336 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006337 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006338
6339 /**
6340 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006341 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6342 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006343 * Require system privileges. In the future we may add this to carrier APIs.
6344 *
Michele Berionne482f8202018-11-27 18:57:59 -08006345 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006346 */
6347 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006348 @TelephonyManager.SetCarrierRestrictionResult
6349 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006350 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006351 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006352
Michele Berionne482f8202018-11-27 18:57:59 -08006353 if (carrierRestrictionRules == null) {
6354 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006355 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006357 final long identity = Binder.clearCallingIdentity();
6358 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006359 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006360 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006361 } finally {
6362 Binder.restoreCallingIdentity(identity);
6363 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006364 }
6365
6366 /**
6367 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006368 * Get the allowed carrier list and the excluded carrier list, including the priority between
6369 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006370 * Require system privileges. In the future we may add this to carrier APIs.
6371 *
Michele Berionne482f8202018-11-27 18:57:59 -08006372 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006373 */
6374 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006375 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006376 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006377 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378
6379 final long identity = Binder.clearCallingIdentity();
6380 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006381 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6382 if (response instanceof CarrierRestrictionRules) {
6383 return (CarrierRestrictionRules) response;
6384 }
6385 // Response is an Exception of some kind,
6386 // which is signalled to the user as a NULL retval
6387 return null;
6388 } catch (Exception e) {
6389 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6390 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006391 } finally {
6392 Binder.restoreCallingIdentity(identity);
6393 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006394 }
6395
fionaxu59545b42016-05-25 15:53:37 -07006396 /**
6397 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6398 * @param subId the subscription ID that this action applies to.
6399 * @param enabled control enable or disable metered apns.
6400 * {@hide}
6401 */
6402 @Override
6403 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6404 enforceModifyPermission();
6405 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406
6407 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006408 if (phone == null) {
6409 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6410 return;
6411 }
6412 try {
6413 phone.carrierActionSetMeteredApnsEnabled(enabled);
6414 } catch (Exception e) {
6415 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006416 } finally {
6417 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006418 }
6419 }
6420
6421 /**
6422 * Action set from carrier signalling broadcast receivers to enable/disable radio
6423 * @param subId the subscription ID that this action applies to.
6424 * @param enabled control enable or disable radio.
6425 * {@hide}
6426 */
6427 @Override
6428 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6429 enforceModifyPermission();
6430 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006431
6432 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006433 if (phone == null) {
6434 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6435 return;
6436 }
6437 try {
6438 phone.carrierActionSetRadioEnabled(enabled);
6439 } catch (Exception e) {
6440 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006441 } finally {
6442 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006443 }
6444 }
6445
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006446 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006447 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6448 * network status based on which carrier apps could apply actions accordingly,
6449 * enable/disable default url handler for example.
6450 *
6451 * @param subId the subscription ID that this action applies to.
6452 * @param report control start/stop reporting the default network status.
6453 * {@hide}
6454 */
6455 @Override
6456 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6457 enforceModifyPermission();
6458 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006459
6460 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006461 if (phone == null) {
6462 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6463 return;
6464 }
6465 try {
6466 phone.carrierActionReportDefaultNetworkStatus(report);
6467 } catch (Exception e) {
6468 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469 } finally {
6470 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006471 }
6472 }
6473
6474 /**
fionaxud9622282017-07-17 17:51:30 -07006475 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6476 * @param subId the subscription ID that this action applies to.
6477 * {@hide}
6478 */
6479 @Override
6480 public void carrierActionResetAll(int subId) {
6481 enforceModifyPermission();
6482 final Phone phone = getPhone(subId);
6483 if (phone == null) {
6484 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6485 return;
6486 }
6487 try {
6488 phone.carrierActionResetAll();
6489 } catch (Exception e) {
6490 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6491 }
6492 }
6493
6494 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006495 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6496 * bug report is being generated.
6497 */
6498 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006499 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006500 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6501 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006502 writer.println("Permission Denial: can't dump Phone from pid="
6503 + Binder.getCallingPid()
6504 + ", uid=" + Binder.getCallingUid()
6505 + "without permission "
6506 + android.Manifest.permission.DUMP);
6507 return;
6508 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006509 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006510 }
Jack Yueb89b242016-06-22 13:27:47 -07006511
Brad Ebingerdac2f002018-04-03 15:17:52 -07006512 @Override
6513 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6514 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6515 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006516 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6517 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006518 }
6519
Jack Yueb89b242016-06-22 13:27:47 -07006520 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006521 * Get aggregated video call data usage since boot.
6522 *
6523 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6524 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006525 * {@hide}
6526 */
6527 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006528 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006529 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6530 null);
6531
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006532 final long identity = Binder.clearCallingIdentity();
6533 try {
6534 // NetworkStatsService keeps tracking the active network interface and identity. It
6535 // records the delta with the corresponding network identity.
6536 // We just return the total video call data usage snapshot since boot.
6537 Phone phone = getPhone(subId);
6538 if (phone != null) {
6539 return phone.getVtDataUsage(perUidStats);
6540 }
6541 return null;
6542 } finally {
6543 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006544 }
Jack Yueb89b242016-06-22 13:27:47 -07006545 }
Jack Yu75ab2952016-07-08 14:29:33 -07006546
6547 /**
6548 * Policy control of data connection. Usually used when data limit is passed.
6549 * @param enabled True if enabling the data, otherwise disabling.
6550 * @param subId Subscription index
6551 * {@hide}
6552 */
6553 @Override
6554 public void setPolicyDataEnabled(boolean enabled, int subId) {
6555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556
6557 final long identity = Binder.clearCallingIdentity();
6558 try {
6559 Phone phone = getPhone(subId);
6560 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006561 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 }
6563 } finally {
6564 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006565 }
6566 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006567
6568 /**
6569 * Get Client request stats
6570 * @return List of Client Request Stats
6571 * @hide
6572 */
6573 @Override
6574 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006575 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006576 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006577 return null;
6578 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006579 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581 final long identity = Binder.clearCallingIdentity();
6582 try {
6583 if (phone != null) {
6584 return phone.getClientRequestStats();
6585 }
6586
6587 return null;
6588 } finally {
6589 Binder.restoreCallingIdentity(identity);
6590 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006591 }
6592
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006593 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006594 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006595 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006596 }
Jack Yueb4124c2017-02-16 15:32:43 -08006597
6598 /**
Grace Chen70990072017-03-24 17:21:30 -07006599 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006600 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006601 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006602 * @param state State of SIM (power down, power up, pass through)
6603 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6604 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6605 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006606 *
6607 **/
6608 @Override
Grace Chen70990072017-03-24 17:21:30 -07006609 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006610 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006611 Phone phone = PhoneFactory.getPhone(slotIndex);
6612
vagdeviaf9a5b92018-08-15 16:01:53 -07006613 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006615 final long identity = Binder.clearCallingIdentity();
6616 try {
6617 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006618 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006619 }
6620 } finally {
6621 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006622 }
6623 }
Shuo Qiandd210312017-04-12 22:11:33 +00006624
Tyler Gunn65d45c22017-06-05 11:22:26 -07006625 private boolean isUssdApiAllowed(int subId) {
6626 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006627 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006628 if (configManager == null) {
6629 return false;
6630 }
6631 PersistableBundle pb = configManager.getConfigForSubId(subId);
6632 if (pb == null) {
6633 return false;
6634 }
6635 return pb.getBoolean(
6636 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6637 }
6638
Shuo Qiandd210312017-04-12 22:11:33 +00006639 /**
6640 * Check if phone is in emergency callback mode
6641 * @return true if phone is in emergency callback mode
6642 * @param subId sub id
6643 */
goneil9c5f4872017-12-05 14:07:56 -08006644 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006645 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006646 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006647 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006648
6649 final long identity = Binder.clearCallingIdentity();
6650 try {
6651 if (phone != null) {
6652 return phone.isInEcm();
6653 } else {
6654 return false;
6655 }
6656 } finally {
6657 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006658 }
6659 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006660
6661 /**
6662 * Get the current signal strength information for the given subscription.
6663 * Because this information is not updated when the device is in a low power state
6664 * it should not be relied-upon to be current.
6665 * @param subId Subscription index
6666 * @return the most recent cached signal strength info from the modem
6667 */
6668 @Override
6669 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006670 final long identity = Binder.clearCallingIdentity();
6671 try {
6672 Phone p = getPhone(subId);
6673 if (p == null) {
6674 return null;
6675 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006677 return p.getSignalStrength();
6678 } finally {
6679 Binder.restoreCallingIdentity(identity);
6680 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006681 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006682
Pengquan Meng77b7f132018-08-22 14:49:57 -07006683 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006684 * Get the current modem radio state for the given slot.
6685 * @param slotIndex slot index.
6686 * @param callingPackage the name of the package making the call.
6687 * @return the current radio power state from the modem
6688 */
6689 @Override
6690 public int getRadioPowerState(int slotIndex, String callingPackage) {
6691 Phone phone = PhoneFactory.getPhone(slotIndex);
6692 if (phone != null) {
6693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6694 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6695 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6696 }
6697
6698 final long identity = Binder.clearCallingIdentity();
6699 try {
6700 return phone.getRadioPowerState();
6701 } finally {
6702 Binder.restoreCallingIdentity(identity);
6703 }
6704 }
6705 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6706 }
6707
6708 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006709 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6710 *
6711 * <p>Requires one of the following permissions:
6712 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6713 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6714 * privileges.
6715 *
6716 * @param subId subscription id
6717 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6718 * {@code false}.
6719 */
6720 @Override
6721 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006722 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6723 null /* message */);
6724
Pengquan Menga1bb6272018-09-06 09:59:22 -07006725 boolean isEnabled = false;
6726 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006727 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006728 Phone phone = getPhone(subId);
6729 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006730 } catch (Exception e) {
6731 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6732 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006733 } finally {
6734 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006735 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006736 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006737 }
6738
6739
6740 /**
6741 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6742 *
6743 * <p> Requires permission:
6744 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6745 * privileges.
6746 *
6747 * @param subId subscription id
6748 * @param isEnabled {@code true} means enable, {@code false} means disable.
6749 */
6750 @Override
6751 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6753 mApp, subId, "setDataRoamingEnabled");
6754
Pengquan Menga1bb6272018-09-06 09:59:22 -07006755 final long identity = Binder.clearCallingIdentity();
6756 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006757 Phone phone = getPhone(subId);
6758 if (phone != null) {
6759 phone.setDataRoamingEnabled(isEnabled);
6760 }
6761 } finally {
6762 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006763 }
6764 }
6765
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006766 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006767 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006768 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6769 mApp, subId, "isManualNetworkSelectionAllowed");
6770
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006771 boolean isAllowed = true;
6772 final long identity = Binder.clearCallingIdentity();
6773 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006774 Phone phone = getPhone(subId);
6775 if (phone != null) {
6776 isAllowed = phone.isCspPlmnEnabled();
6777 }
6778 } finally {
6779 Binder.restoreCallingIdentity(identity);
6780 }
6781 return isAllowed;
6782 }
6783
6784 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006785 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006786 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006787 try {
6788 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006789 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006790 } catch (SecurityException e) {
6791 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6792 // has carrier privileges on an active UICC
6793 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6794 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006795 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006796 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006797 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006798
6799 final long identity = Binder.clearCallingIdentity();
6800 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006801 UiccController uiccController = UiccController.getInstance();
6802 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006803 if (hasReadPermission) {
6804 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006805 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006806
6807 // Remove private info if the caller doesn't have access
6808 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6809 for (UiccCardInfo cardInfo : cardInfos) {
6810 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6811 // is available
6812 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6813 if (card == null || card.getUiccProfile() == null) {
6814 // assume no access if the card or profile is unavailable
6815 filteredInfos.add(cardInfo.getUnprivileged());
6816 continue;
6817 }
6818 UiccProfile profile = card.getUiccProfile();
6819 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6820 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6821 filteredInfos.add(cardInfo);
6822 } else {
6823 filteredInfos.add(cardInfo.getUnprivileged());
6824 }
6825 }
6826 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006827 } finally {
6828 Binder.restoreCallingIdentity(identity);
6829 }
6830 }
6831
6832 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006833 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006834 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006835
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006836 final long identity = Binder.clearCallingIdentity();
6837 try {
6838 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6839 if (slots == null) {
6840 Rlog.i(LOG_TAG, "slots is null.");
6841 return null;
6842 }
6843
6844 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6845 for (int i = 0; i < slots.length; i++) {
6846 UiccSlot slot = slots[i];
6847 if (slot == null) {
6848 continue;
6849 }
6850
Jordan Liu7be7e652019-05-06 18:55:02 +00006851 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852 UiccCard card = slot.getUiccCard();
6853 if (card != null) {
6854 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006855 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006856 cardId = slot.getEid();
6857 if (TextUtils.isEmpty(cardId)) {
6858 cardId = slot.getIccId();
6859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006860 }
6861
Jordan Liu857451f2019-05-09 16:35:35 -07006862 if (cardId != null) {
6863 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6864 // if cardId is an EID, it's all digits so this is fine
6865 cardId = IccUtils.stripTrailingFs(cardId);
6866 }
6867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868 int cardState = 0;
6869 switch (slot.getCardState()) {
6870 case CARDSTATE_ABSENT:
6871 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6872 break;
6873 case CARDSTATE_PRESENT:
6874 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6875 break;
6876 case CARDSTATE_ERROR:
6877 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6878 break;
6879 case CARDSTATE_RESTRICTED:
6880 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6881 break;
6882 default:
6883 break;
6884
6885 }
6886
6887 infos[i] = new UiccSlotInfo(
6888 slot.isActive(),
6889 slot.isEuicc(),
6890 cardId,
6891 cardState,
6892 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006893 slot.isExtendedApduSupported(),
6894 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895 }
6896 return infos;
6897 } finally {
6898 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006899 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006900 }
6901
6902 @Override
6903 public boolean switchSlots(int[] physicalSlots) {
6904 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006905
6906 final long identity = Binder.clearCallingIdentity();
6907 try {
6908 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6909 } finally {
6910 Binder.restoreCallingIdentity(identity);
6911 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006912 }
Jack Yu4c988042018-02-27 15:30:01 -08006913
6914 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006915 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006916 final long identity = Binder.clearCallingIdentity();
6917 try {
6918 return UiccController.getInstance().getCardIdForDefaultEuicc();
6919 } finally {
6920 Binder.restoreCallingIdentity(identity);
6921 }
6922 }
6923
6924 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006925 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6926 enforceModifyPermission();
6927 final Phone phone = getPhone(subId);
6928 if (phone == null) {
6929 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6930 return;
6931 }
6932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006933 final long identity = Binder.clearCallingIdentity();
6934 try {
6935 phone.setRadioIndicationUpdateMode(filters, mode);
6936 } finally {
6937 Binder.restoreCallingIdentity(identity);
6938 }
Jack Yu4c988042018-02-27 15:30:01 -08006939 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006940
6941 /**
goneil47ffb6e2018-04-06 15:40:58 -07006942 * A test API to reload the UICC profile.
6943 *
6944 * <p>Requires that the calling app has permission
6945 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6946 * @hide
6947 */
6948 @Override
6949 public void refreshUiccProfile(int subId) {
6950 enforceModifyPermission();
6951
6952 final long identity = Binder.clearCallingIdentity();
6953 try {
6954 Phone phone = getPhone(subId);
6955 if (phone == null) {
6956 return;
6957 }
6958 UiccCard uiccCard = phone.getUiccCard();
6959 if (uiccCard == null) {
6960 return;
6961 }
6962 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6963 if (uiccProfile == null) {
6964 return;
6965 }
6966 uiccProfile.refresh();
6967 } finally {
6968 Binder.restoreCallingIdentity(identity);
6969 }
6970 }
6971
6972 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006973 * Returns false if the mobile data is disabled by default, otherwise return true.
6974 */
6975 private boolean getDefaultDataEnabled() {
6976 return "true".equalsIgnoreCase(
6977 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6978 }
6979
6980 /**
6981 * Returns true if the data roaming is enabled by default, i.e the system property
6982 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6983 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6984 */
6985 private boolean getDefaultDataRoamingEnabled(int subId) {
6986 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006987 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006988 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6989 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6990 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6991 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6992 return isDataRoamingEnabled;
6993 }
6994
6995 /**
6996 * Returns the default network type for the given {@code subId}, if the default network type is
6997 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6998 */
6999 private int getDefaultNetworkType(int subId) {
7000 return Integer.parseInt(
7001 TelephonyManager.getTelephonyProperty(
7002 mSubscriptionController.getPhoneId(subId),
7003 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
7004 String.valueOf(Phone.PREFERRED_NT_MODE)));
7005 }
fionaxua13278b2018-03-21 00:08:13 -07007006
7007 @Override
7008 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007009 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007010 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007011
7012 final long identity = Binder.clearCallingIdentity();
7013 try {
7014 final Phone phone = getPhone(subId);
7015 if (phone == null) {
7016 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7017 return;
7018 }
chen xueaba88a2019-03-15 13:15:10 -07007019 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7020 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007021 } finally {
7022 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007023 }
fionaxua13278b2018-03-21 00:08:13 -07007024 }
7025
7026 @Override
7027 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007028 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029
7030 final long identity = Binder.clearCallingIdentity();
7031 try {
7032 final Phone phone = getPhone(subId);
7033 if (phone == null) {
7034 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7035 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7036 }
7037 return phone.getCarrierIdListVersion();
7038 } finally {
7039 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007040 }
fionaxua13278b2018-03-21 00:08:13 -07007041 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007042
7043 @Override
7044 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
7045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7046 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
7047 return -1;
7048 }
7049
7050 final long identity = Binder.clearCallingIdentity();
7051 try {
7052 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7053 } finally {
7054 Binder.restoreCallingIdentity(identity);
7055 }
7056 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007057
7058 @Override
7059 public int getCdmaRoamingMode(int subId) {
7060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7061 mApp, subId, "getCdmaRoamingMode");
7062
7063 final long identity = Binder.clearCallingIdentity();
7064 try {
7065 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7066 } finally {
7067 Binder.restoreCallingIdentity(identity);
7068 }
7069 }
7070
7071 @Override
7072 public boolean setCdmaRoamingMode(int subId, int mode) {
7073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7074 mApp, subId, "setCdmaRoamingMode");
7075
7076 final long identity = Binder.clearCallingIdentity();
7077 try {
7078 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7079 } finally {
7080 Binder.restoreCallingIdentity(identity);
7081 }
7082 }
7083
7084 @Override
7085 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7087 mApp, subId, "setCdmaSubscriptionMode");
7088
7089 final long identity = Binder.clearCallingIdentity();
7090 try {
7091 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7092 } finally {
7093 Binder.restoreCallingIdentity(identity);
7094 }
7095 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007096
sqianc5eccab2018-10-19 18:46:41 -07007097 @Override
sqian8c685422019-02-22 15:55:18 -08007098 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007099 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007100 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007101 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007102 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7103 }
7104 final long identity = Binder.clearCallingIdentity();
7105 try {
sqian854d44b2018-12-12 16:48:18 -08007106 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7107 for (Phone phone: PhoneFactory.getPhones()) {
7108 if (phone.getEmergencyNumberTracker() != null
7109 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7110 emergencyNumberListInternal.put(
7111 phone.getSubId(),
7112 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7113 }
sqian11b7a0e2018-12-05 18:48:28 -08007114 }
sqian854d44b2018-12-12 16:48:18 -08007115 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007116 } finally {
7117 Binder.restoreCallingIdentity(identity);
7118 }
sqianc5eccab2018-10-19 18:46:41 -07007119 }
7120
7121 @Override
sqian8c685422019-02-22 15:55:18 -08007122 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007123 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007124 if (!exactMatch) {
7125 TelephonyPermissions
7126 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007127 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007128 }
7129 final long identity = Binder.clearCallingIdentity();
7130 try {
sqian854d44b2018-12-12 16:48:18 -08007131 for (Phone phone: PhoneFactory.getPhones()) {
7132 if (phone.getEmergencyNumberTracker() != null
7133 && phone.getEmergencyNumberTracker() != null) {
7134 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7135 number, exactMatch)) {
7136 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007137 }
7138 }
sqian11b7a0e2018-12-05 18:48:28 -08007139 }
7140 return false;
7141 } finally {
7142 Binder.restoreCallingIdentity(identity);
7143 }
7144 }
7145
sqianf4ca7ed2019-01-15 18:32:07 -08007146 /**
7147 * Update emergency number list for test mode.
7148 */
7149 @Override
7150 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7151 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7152 "updateEmergencyNumberListTestMode");
7153
7154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 for (Phone phone: PhoneFactory.getPhones()) {
7157 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7158 if (tracker != null) {
7159 tracker.executeEmergencyNumberTestModeCommand(action, num);
7160 }
7161 }
7162 } finally {
7163 Binder.restoreCallingIdentity(identity);
7164 }
7165 }
7166
7167 /**
7168 * Get the full emergency number list for test mode.
7169 */
7170 @Override
7171 public List<String> getEmergencyNumberListTestMode() {
7172 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7173 "getEmergencyNumberListTestMode");
7174
7175 final long identity = Binder.clearCallingIdentity();
7176 try {
7177 Set<String> emergencyNumbers = new HashSet<>();
7178 for (Phone phone: PhoneFactory.getPhones()) {
7179 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7180 if (tracker != null) {
7181 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7182 emergencyNumbers.add(num.getNumber());
7183 }
7184 }
7185 }
7186 return new ArrayList<>(emergencyNumbers);
7187 } finally {
7188 Binder.restoreCallingIdentity(identity);
7189 }
7190 }
7191
chen xud6b45bd2018-10-30 22:27:10 -07007192 @Override
7193 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7194 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7195 Phone phone = getPhone(subId);
7196 if (phone == null) {
7197 return null;
7198 }
7199 final long identity = Binder.clearCallingIdentity();
7200 try {
7201 UiccProfile profile = UiccController.getInstance()
7202 .getUiccProfileForPhone(phone.getPhoneId());
7203 if (profile != null) {
7204 return profile.getCertsFromCarrierPrivilegeAccessRules();
7205 }
7206 } finally {
7207 Binder.restoreCallingIdentity(identity);
7208 }
7209 return null;
7210 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007211
7212 /**
7213 * Enable or disable a modem stack.
7214 */
7215 @Override
7216 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7217 enforceModifyPermission();
7218
7219 final long identity = Binder.clearCallingIdentity();
7220 try {
7221 Phone phone = PhoneFactory.getPhone(slotIndex);
7222 if (phone == null) {
7223 return false;
7224 } else {
7225 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7226 }
7227 } finally {
7228 Binder.restoreCallingIdentity(identity);
7229 }
7230 }
Michelecea4cf22018-12-21 15:00:11 -08007231
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007232 /**
7233 * Whether a modem stack is enabled or not.
7234 */
7235 @Override
7236 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7237 Phone phone = PhoneFactory.getPhone(slotIndex);
7238 if (phone == null) return false;
7239
7240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7241 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7242 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7243 }
7244
7245 final long identity = Binder.clearCallingIdentity();
7246 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007247 try {
7248 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7249 } catch (NoSuchElementException ex) {
7250 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7251 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007252 } finally {
7253 Binder.restoreCallingIdentity(identity);
7254 }
7255 }
7256
Michelecea4cf22018-12-21 15:00:11 -08007257 @Override
Michele0ea7d782019-03-19 14:58:42 -07007258 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007259 enforceModifyPermission();
7260
7261 final long identity = Binder.clearCallingIdentity();
7262 try {
7263 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007264 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007265 .commit();
7266 } finally {
7267 Binder.restoreCallingIdentity(identity);
7268 }
7269 }
7270
7271 @Override
Michele0ea7d782019-03-19 14:58:42 -07007272 @TelephonyManager.IsMultiSimSupportedResult
7273 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007274 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007275 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7276 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007277 }
Michelecea4cf22018-12-21 15:00:11 -08007278
7279 final long identity = Binder.clearCallingIdentity();
7280 try {
Michele0ea7d782019-03-19 14:58:42 -07007281 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007282 } finally {
7283 Binder.restoreCallingIdentity(identity);
7284 }
7285 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007286
Michele0ea7d782019-03-19 14:58:42 -07007287 @TelephonyManager.IsMultiSimSupportedResult
7288 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007289 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7290 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7291 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007292 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7293 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007294 }
7295 // Check if the hardware supports multisim functionality. If usage of multisim is not
7296 // supported by the modem, indicate that it is restricted.
7297 PhoneCapability staticCapability =
7298 mPhoneConfigurationManager.getStaticPhoneCapability();
7299 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007300 loge("isMultiSimSupportedInternal: no static configuration available");
7301 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007302 }
7303 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007304 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7305 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007306 }
7307 // Check if support of multiple SIMs is restricted by carrier
7308 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007309 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007310 }
7311
Michele0ea7d782019-03-19 14:58:42 -07007312 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007313 }
7314
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007315 /**
7316 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007317 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7318 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7319 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007320 * @param numOfSims number of active sims we want to switch to
7321 */
7322 @Override
7323 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007324 if (numOfSims == 1) {
7325 enforceModifyPermission();
7326 } else {
7327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7328 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7329 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007330 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007331
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007332 try {
Michele30b57b22019-03-01 12:01:14 -08007333 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007334 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007335 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7336 return;
7337 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007338 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7339 } finally {
7340 Binder.restoreCallingIdentity(identity);
7341 }
7342 }
7343
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007344 @Override
7345 public boolean isApplicationOnUicc(int subId, int appType) {
7346 enforceReadPrivilegedPermission("isApplicationOnUicc");
7347 Phone phone = getPhone(subId);
7348 if (phone == null) {
7349 return false;
7350 }
7351 final long identity = Binder.clearCallingIdentity();
7352 try {
7353 UiccCard uiccCard = phone.getUiccCard();
7354 if (uiccCard == null) {
7355 return false;
7356 }
7357 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7358 if (uiccProfile == null) {
7359 return false;
7360 }
7361 if (TelephonyManager.APPTYPE_SIM <= appType
7362 && appType <= TelephonyManager.APPTYPE_ISIM) {
7363 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7364 }
7365 return false;
7366 } finally {
7367 Binder.restoreCallingIdentity(identity);
7368 }
7369 }
7370
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007371 /**
chen xub4baa772019-04-03 10:23:41 -07007372 * Get whether making changes to modem configurations will trigger reboot.
7373 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007374 */
7375 @Override
chen xub4baa772019-04-03 10:23:41 -07007376 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7377 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7378 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7379 return false;
7380 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007381 final long identity = Binder.clearCallingIdentity();
7382 try {
7383 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7384 } finally {
7385 Binder.restoreCallingIdentity(identity);
7386 }
7387 }
7388
Nathan Harold29f5f052019-02-15 13:41:57 -08007389 private void updateModemStateMetrics() {
7390 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7391 // TODO: check the state for each modem if the api is ready.
7392 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7393 }
7394
Pengquan Meng3889a572019-01-23 11:16:29 -08007395 @Override
7396 public int[] getSlotsMapping() {
7397 enforceReadPrivilegedPermission("getSlotsMapping");
7398
7399 final long identity = Binder.clearCallingIdentity();
7400 try {
7401 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7402 // All logical slots should have a mapping to a physical slot.
7403 int[] logicalSlotsMapping = new int[phoneCount];
7404 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7405 for (int i = 0; i < slotInfos.length; i++) {
7406 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7407 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7408 }
7409 }
7410 return logicalSlotsMapping;
7411 } finally {
7412 Binder.restoreCallingIdentity(identity);
7413 }
7414 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007415
7416 /**
7417 * Get the IRadio HAL Version
7418 */
7419 @Override
7420 public int getRadioHalVersion() {
7421 Phone phone = getDefaultPhone();
7422 if (phone == null) return -1;
7423 HalVersion hv = phone.getHalVersion();
7424 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7425 return hv.major * 100 + hv.minor;
7426 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007427
7428 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007429 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7430 * corresponding network requests on a subId.
7431 *
7432 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007433 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007434 * 2) APN is un-metered for this subscription, or
7435 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7436 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7437 *
7438 * @return whether data is allowed for a apn type.
7439 *
7440 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007441 */
7442 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007443 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007444 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7445 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007446
7447 // Now that all security checks passes, perform the operation as ourselves.
7448 final long identity = Binder.clearCallingIdentity();
7449 try {
7450 Phone phone = getPhone(subId);
7451 if (phone == null) return false;
7452
Jack Yu41407ee2019-05-13 16:54:09 -07007453 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007454 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7455 } finally {
7456 Binder.restoreCallingIdentity(identity);
7457 }
7458 }
7459
7460 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007461 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007462 enforceReadPrivilegedPermission("isApnMetered");
7463
7464 // Now that all security checks passes, perform the operation as ourselves.
7465 final long identity = Binder.clearCallingIdentity();
7466 try {
7467 Phone phone = getPhone(subId);
7468 if (phone == null) return true; // By default return true.
7469
Jack Yu41407ee2019-05-13 16:54:09 -07007470 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007471 } finally {
7472 Binder.restoreCallingIdentity(identity);
7473 }
7474 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007475
7476 @Override
7477 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7478 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7479 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7480 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7481 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7482 }
7483 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7484 Intent intent = new Intent();
7485 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7486 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7487 // Bring up choose default SMS subscription dialog right now
7488 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7489 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7490 mApp.startActivity(intent);
7491 }
chen xud5ca2d52019-05-28 15:20:57 -07007492
7493 @Override
7494 public String getMmsUAProfUrl(int subId) {
7495 //TODO investigate if this API should require proper permission check in R b/133791609
7496 final long identity = Binder.clearCallingIdentity();
7497 try {
7498 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7499 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7500 } finally {
7501 Binder.restoreCallingIdentity(identity);
7502 }
7503 }
7504
7505 @Override
7506 public String getMmsUserAgent(int subId) {
7507 //TODO investigate if this API should require proper permission check in R b/133791609
7508 final long identity = Binder.clearCallingIdentity();
7509 try {
7510 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7511 .getString(com.android.internal.R.string.config_mms_user_agent);
7512 } finally {
7513 Binder.restoreCallingIdentity(identity);
7514 }
7515 }
Jack Yub07d4972019-05-28 16:12:25 -07007516
7517 @Override
7518 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7519 enforceModifyPermission();
7520
7521 // Now that all security checks passes, perform the operation as ourselves.
7522 final long identity = Binder.clearCallingIdentity();
7523 try {
7524 Phone phone = getPhone(subId);
7525 if (phone == null) return false;
7526
7527 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7528 } finally {
7529 Binder.restoreCallingIdentity(identity);
7530 }
7531 }
7532
7533 @Override
7534 public boolean isDataAllowedInVoiceCall(int subId) {
7535 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7536
7537 // Now that all security checks passes, perform the operation as ourselves.
7538 final long identity = Binder.clearCallingIdentity();
7539 try {
7540 Phone phone = getPhone(subId);
7541 if (phone == null) return false;
7542
7543 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7544 } finally {
7545 Binder.restoreCallingIdentity(identity);
7546 }
7547 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007548
7549 /**
7550 * Updates whether conference event pacakge handling is enabled.
7551 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7552 * otherwise.
7553 */
7554 @Override
7555 public void setCepEnabled(boolean isCepEnabled) {
7556 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7557
7558 final long identity = Binder.clearCallingIdentity();
7559 try {
7560 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7561 for (Phone phone : PhoneFactory.getPhones()) {
7562 Phone defaultPhone = phone.getImsPhone();
7563 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7564 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7565 ImsPhoneCallTracker imsPhoneCallTracker =
7566 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7567 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7568 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7569 + imsPhone.getMsisdn());
7570 }
7571 }
7572 } finally {
7573 Binder.restoreCallingIdentity(identity);
7574 }
7575 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007576}