blob: 183a50c44a8105542d76f4069feb3611b9131c2d [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;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800284 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700285 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800286 private AppOpsManager mAppOps;
287 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800288 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800289 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700290 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291
Derek Tan97ebb422014-09-05 16:55:38 -0700292 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
293 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800294 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800295 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700296
Michelecea4cf22018-12-21 15:00:11 -0800297 // String to store multi SIM allowed
298 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
299
Derek Tan740e1672017-06-27 14:56:27 -0700300 // The AID of ISD-R.
301 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
302
yinxub1bed742017-04-17 11:45:04 -0700303 private NetworkScanRequestTracker mNetworkScanRequestTracker;
304
David Kelly5e06a7f2018-03-12 14:10:59 +0000305 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
306 private static final int MANUFACTURER_CODE_LENGTH = 8;
307
Derek Tan89e89d42014-07-08 17:00:10 -0700308 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700309 * Experiment flag to enable erase modem config on reset network, default value is false
310 */
311 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
312 "reset_network_erase_modem_config_enabled";
313
314 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700315 * A request object to use for transmitting data to an ICC.
316 */
317 private static final class IccAPDUArgument {
318 public int channel, cla, command, p1, p2, p3;
319 public String data;
320
321 public IccAPDUArgument(int channel, int cla, int command,
322 int p1, int p2, int p3, String data) {
323 this.channel = channel;
324 this.cla = cla;
325 this.command = command;
326 this.p1 = p1;
327 this.p2 = p2;
328 this.p3 = p3;
329 this.data = data;
330 }
331 }
332
333 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700334 * A request object to use for transmitting data to an ICC.
335 */
336 private static final class ManualNetworkSelectionArgument {
337 public OperatorInfo operatorInfo;
338 public boolean persistSelection;
339
340 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
341 this.operatorInfo = operatorInfo;
342 this.persistSelection = persistSelection;
343 }
344 }
345
346 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
348 * request after sending. The main thread will notify the request when it is complete.
349 */
350 private static final class MainThreadRequest {
351 /** The argument to use for the request */
352 public Object argument;
353 /** The result of the request that is run on the main thread */
354 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800355 // The subscriber id that this request applies to. Defaults to
356 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
357 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358
Nathan Harold92bed182018-10-12 18:16:49 -0700359 // In cases where subId is unavailable, the caller needs to specify the phone.
360 public Phone phone;
361
vagdeviaf9a5b92018-08-15 16:01:53 -0700362 public WorkSource workSource;
363
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 public MainThreadRequest(Object argument) {
365 this.argument = argument;
366 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800367
Nathan Harold92bed182018-10-12 18:16:49 -0700368 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
369 this.argument = argument;
370 if (phone != null) {
371 this.phone = phone;
372 }
373 this.workSource = workSource;
374 }
375
vagdeviaf9a5b92018-08-15 16:01:53 -0700376 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800377 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800378 if (subId != null) {
379 this.subId = subId;
380 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700381 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 }
384
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800385 private static final class IncomingThirdPartyCallArgs {
386 public final ComponentName component;
387 public final String callId;
388 public final String callerDisplayName;
389
390 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
391 String callerDisplayName) {
392 this.component = component;
393 this.callId = callId;
394 this.callerDisplayName = callerDisplayName;
395 }
396 }
397
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 /**
399 * A handler that processes messages on the main thread in the phone process. Since many
400 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
401 * inbound binder threads to the main thread in the phone process. The Binder thread
402 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
403 * on, which will be notified when the operation completes and will contain the result of the
404 * request.
405 *
406 * <p>If a MainThreadRequest object is provided in the msg.obj field,
407 * note that request.result must be set to something non-null for the calling thread to
408 * unblock.
409 */
410 private final class MainThreadHandler extends Handler {
411 @Override
412 public void handleMessage(Message msg) {
413 MainThreadRequest request;
414 Message onCompleted;
415 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800416 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700417 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800418 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700419
420 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700421 case CMD_HANDLE_USSD_REQUEST: {
422 request = (MainThreadRequest) msg.obj;
423 final Phone phone = getPhoneFromRequest(request);
424 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
425 String ussdRequest = ussdObject.first;
426 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700427
Pengquan Menga1bb6272018-09-06 09:59:22 -0700428 if (!isUssdApiAllowed(request.subId)) {
429 // Carrier does not support use of this API, return failure.
430 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
431 UssdResponse response = new UssdResponse(ussdRequest, null);
432 Bundle returnData = new Bundle();
433 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
434 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700435
Pengquan Menga1bb6272018-09-06 09:59:22 -0700436 request.result = true;
437 notifyRequester(request);
438 return;
439 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700440
Pengquan Menga1bb6272018-09-06 09:59:22 -0700441 try {
442 request.result = phone != null
443 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
444 } catch (CallStateException cse) {
445 request.result = false;
446 }
447 // Wake up the requesting thread
448 notifyRequester(request);
449 break;
pkanwar32d516d2016-10-14 19:37:38 -0700450 }
451
Yorke Lee716f67e2015-06-17 15:39:16 -0700452 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700453 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700454 final Phone phone = getPhoneFromRequest(request);
455 request.result = phone != null ?
456 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
457 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700459 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700461 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700462
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700464 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800466 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700467 if (uiccCard == null) {
468 loge("iccTransmitApduLogicalChannel: No UICC");
469 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700470 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700471 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
473 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700474 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700475 iccArgument.channel, iccArgument.cla, iccArgument.command,
476 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700478 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 break;
480
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700481 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700482 ar = (AsyncResult) msg.obj;
483 request = (MainThreadRequest) ar.userObj;
484 if (ar.exception == null && ar.result != null) {
485 request.result = ar.result;
486 } else {
487 request.result = new IccIoResult(0x6F, 0, (byte[])null);
488 if (ar.result == null) {
489 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800490 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700491 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800492 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700493 } else {
494 loge("iccTransmitApduLogicalChannel: Unknown exception");
495 }
496 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700497 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700498 break;
499
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
501 request = (MainThreadRequest) msg.obj;
502 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800503 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700504 if (uiccCard == null) {
505 loge("iccTransmitApduBasicChannel: No UICC");
506 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700507 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 } else {
509 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
510 request);
511 uiccCard.iccTransmitApduBasicChannel(
512 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
513 iccArgument.p3, iccArgument.data, onCompleted);
514 }
515 break;
516
517 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
518 ar = (AsyncResult) msg.obj;
519 request = (MainThreadRequest) ar.userObj;
520 if (ar.exception == null && ar.result != null) {
521 request.result = ar.result;
522 } else {
523 request.result = new IccIoResult(0x6F, 0, (byte[])null);
524 if (ar.result == null) {
525 loge("iccTransmitApduBasicChannel: Empty response");
526 } else if (ar.exception instanceof CommandException) {
527 loge("iccTransmitApduBasicChannel: CommandException: " +
528 ar.exception);
529 } else {
530 loge("iccTransmitApduBasicChannel: Unknown exception");
531 }
532 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 break;
535
536 case CMD_EXCHANGE_SIM_IO:
537 request = (MainThreadRequest) msg.obj;
538 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800539 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 if (uiccCard == null) {
541 loge("iccExchangeSimIO: No UICC");
542 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700543 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700544 } else {
545 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
546 request);
547 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
548 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
549 iccArgument.data, onCompleted);
550 }
551 break;
552
553 case EVENT_EXCHANGE_SIM_IO_DONE:
554 ar = (AsyncResult) msg.obj;
555 request = (MainThreadRequest) ar.userObj;
556 if (ar.exception == null && ar.result != null) {
557 request.result = ar.result;
558 } else {
559 request.result = new IccIoResult(0x6f, 0, (byte[])null);
560 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700561 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 break;
563
Derek Tan4d5e5c12014-02-04 11:54:58 -0800564 case CMD_SEND_ENVELOPE:
565 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800566 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700567 if (uiccCard == null) {
568 loge("sendEnvelopeWithStatus: No UICC");
569 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700571 } else {
572 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
573 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
574 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800575 break;
576
577 case EVENT_SEND_ENVELOPE_DONE:
578 ar = (AsyncResult) msg.obj;
579 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700580 if (ar.exception == null && ar.result != null) {
581 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800582 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700583 request.result = new IccIoResult(0x6F, 0, (byte[])null);
584 if (ar.result == null) {
585 loge("sendEnvelopeWithStatus: Empty response");
586 } else if (ar.exception instanceof CommandException) {
587 loge("sendEnvelopeWithStatus: CommandException: " +
588 ar.exception);
589 } else {
590 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
591 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800592 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800594 break;
595
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 case CMD_OPEN_CHANNEL:
597 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800598 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800599 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 if (uiccCard == null) {
601 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800602 request.result = new IccOpenLogicalChannelResponse(-1,
603 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700604 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700605 } else {
606 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800607 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
608 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700609 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 break;
611
612 case EVENT_OPEN_CHANNEL_DONE:
613 ar = (AsyncResult) msg.obj;
614 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 int[] result = (int[]) ar.result;
618 int channelId = result[0];
619 byte[] selectResponse = null;
620 if (result.length > 1) {
621 selectResponse = new byte[result.length - 1];
622 for (int i = 1; i < result.length; ++i) {
623 selectResponse[i - 1] = (byte) result[i];
624 }
625 }
626 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700627 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 if (ar.result == null) {
630 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 if (ar.exception != null) {
633 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
634 }
635
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700636 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700637 if (ar.exception instanceof CommandException) {
638 CommandException.Error error =
639 ((CommandException) (ar.exception)).getCommandError();
640 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700641 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700642 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700643 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 }
645 }
646 openChannelResp = new IccOpenLogicalChannelResponse(
647 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700649 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700650 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 break;
652
653 case CMD_CLOSE_CHANNEL:
654 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800655 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700656 if (uiccCard == null) {
657 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900658 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700659 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700660 } else {
661 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
662 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
663 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 break;
665
666 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800667 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
668 break;
669
670 case CMD_NV_READ_ITEM:
671 request = (MainThreadRequest) msg.obj;
672 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800673 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
674 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800675 break;
676
677 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 ar = (AsyncResult) msg.obj;
679 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800680 if (ar.exception == null && ar.result != null) {
681 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800683 request.result = "";
684 if (ar.result == null) {
685 loge("nvReadItem: Empty response");
686 } else if (ar.exception instanceof CommandException) {
687 loge("nvReadItem: CommandException: " +
688 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800690 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 }
692 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700693 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 break;
695
Jake Hambye994d462014-02-03 13:10:13 -0800696 case CMD_NV_WRITE_ITEM:
697 request = (MainThreadRequest) msg.obj;
698 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
699 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800700 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700701 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800702 break;
703
704 case EVENT_NV_WRITE_ITEM_DONE:
705 handleNullReturnEvent(msg, "nvWriteItem");
706 break;
707
708 case CMD_NV_WRITE_CDMA_PRL:
709 request = (MainThreadRequest) msg.obj;
710 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800711 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800712 break;
713
714 case EVENT_NV_WRITE_CDMA_PRL_DONE:
715 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
716 break;
717
chen xu6dac5ab2018-10-26 17:39:23 -0700718 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800719 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700720 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800721 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800722 break;
723
chen xu6dac5ab2018-10-26 17:39:23 -0700724 case EVENT_RESET_MODEM_CONFIG_DONE:
725 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800726 break;
727
Jake Hamby7c27be32014-03-03 13:25:59 -0800728 case CMD_GET_PREFERRED_NETWORK_TYPE:
729 request = (MainThreadRequest) msg.obj;
730 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700731 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800732 break;
733
734 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
735 ar = (AsyncResult) msg.obj;
736 request = (MainThreadRequest) ar.userObj;
737 if (ar.exception == null && ar.result != null) {
738 request.result = ar.result; // Integer
739 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800740 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800741 if (ar.result == null) {
742 loge("getPreferredNetworkType: Empty response");
743 } else if (ar.exception instanceof CommandException) {
744 loge("getPreferredNetworkType: CommandException: " +
745 ar.exception);
746 } else {
747 loge("getPreferredNetworkType: Unknown exception");
748 }
749 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700750 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800751 break;
752
753 case CMD_SET_PREFERRED_NETWORK_TYPE:
754 request = (MainThreadRequest) msg.obj;
755 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
756 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700757 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800758 break;
759
760 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
761 handleNullReturnEvent(msg, "setPreferredNetworkType");
762 break;
763
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000764 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
765 request = (MainThreadRequest)msg.obj;
766 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800767 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000768 break;
769
770 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
771 ar = (AsyncResult)msg.obj;
772 request = (MainThreadRequest)ar.userObj;
773 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700774 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000775 break;
776
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800777 case CMD_SET_VOICEMAIL_NUMBER:
778 request = (MainThreadRequest) msg.obj;
779 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
780 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800781 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
782 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800783 break;
784
785 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
786 handleNullReturnEvent(msg, "setVoicemailNumber");
787 break;
788
Stuart Scott54788802015-03-30 13:18:01 -0700789 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
790 request = (MainThreadRequest) msg.obj;
791 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
792 request);
793 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
794 break;
795
796 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
797 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
798 break;
799
Shishir Agrawal302c8692015-06-19 13:49:39 -0700800 case CMD_PERFORM_NETWORK_SCAN:
801 request = (MainThreadRequest) msg.obj;
802 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
803 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
804 break;
805
806 case EVENT_PERFORM_NETWORK_SCAN_DONE:
807 ar = (AsyncResult) msg.obj;
808 request = (MainThreadRequest) ar.userObj;
809 CellNetworkScanResult cellScanResult;
810 if (ar.exception == null && ar.result != null) {
811 cellScanResult = new CellNetworkScanResult(
812 CellNetworkScanResult.STATUS_SUCCESS,
813 (List<OperatorInfo>) ar.result);
814 } else {
815 if (ar.result == null) {
816 loge("getCellNetworkScanResults: Empty response");
817 }
818 if (ar.exception != null) {
819 loge("getCellNetworkScanResults: Exception: " + ar.exception);
820 }
821 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
822 if (ar.exception instanceof CommandException) {
823 CommandException.Error error =
824 ((CommandException) (ar.exception)).getCommandError();
825 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
826 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
827 } else if (error == CommandException.Error.GENERIC_FAILURE) {
828 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
829 }
830 }
831 cellScanResult = new CellNetworkScanResult(errorCode, null);
832 }
833 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700834 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700835 break;
836
837 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
838 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700839 ManualNetworkSelectionArgument selArg =
840 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700841 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
842 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700843 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
844 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700845 break;
846
847 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700848 ar = (AsyncResult) msg.obj;
849 request = (MainThreadRequest) ar.userObj;
850 if (ar.exception == null) {
851 request.result = true;
852 } else {
853 request.result = false;
854 loge("setNetworkSelectionModeManual " + ar.exception);
855 }
856 notifyRequester(request);
857 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700858 break;
859
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700860 case CMD_GET_MODEM_ACTIVITY_INFO:
861 request = (MainThreadRequest) msg.obj;
862 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700863 if (defaultPhone != null) {
864 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
865 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700866 break;
867
868 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
869 ar = (AsyncResult) msg.obj;
870 request = (MainThreadRequest) ar.userObj;
871 if (ar.exception == null && ar.result != null) {
872 request.result = ar.result;
873 } else {
874 if (ar.result == null) {
875 loge("queryModemActivityInfo: Empty response");
876 } else if (ar.exception instanceof CommandException) {
877 loge("queryModemActivityInfo: CommandException: " +
878 ar.exception);
879 } else {
880 loge("queryModemActivityInfo: Unknown exception");
881 }
882 }
Amit Mahajand4766222016-01-28 15:28:28 -0800883 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
884 if (request.result == null) {
885 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
886 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700887 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700888 break;
889
Meng Wang1a7c35a2016-05-05 20:56:15 -0700890 case CMD_SET_ALLOWED_CARRIERS:
891 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800892 CarrierRestrictionRules argument =
893 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700894 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800895 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700896 break;
897
898 case EVENT_SET_ALLOWED_CARRIERS_DONE:
899 ar = (AsyncResult) msg.obj;
900 request = (MainThreadRequest) ar.userObj;
901 if (ar.exception == null && ar.result != null) {
902 request.result = ar.result;
903 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800904 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
905 if (ar.exception instanceof CommandException) {
906 loge("setAllowedCarriers: CommandException: " + ar.exception);
907 CommandException.Error error =
908 ((CommandException) (ar.exception)).getCommandError();
909 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
910 request.result =
911 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
912 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700913 } else {
914 loge("setAllowedCarriers: Unknown exception");
915 }
916 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700917 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700918 break;
919
920 case CMD_GET_ALLOWED_CARRIERS:
921 request = (MainThreadRequest) msg.obj;
922 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800923 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700924 break;
925
926 case EVENT_GET_ALLOWED_CARRIERS_DONE:
927 ar = (AsyncResult) msg.obj;
928 request = (MainThreadRequest) ar.userObj;
929 if (ar.exception == null && ar.result != null) {
930 request.result = ar.result;
931 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800932 request.result = new IllegalStateException(
933 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700934 if (ar.result == null) {
935 loge("getAllowedCarriers: Empty response");
936 } else if (ar.exception instanceof CommandException) {
937 loge("getAllowedCarriers: CommandException: " +
938 ar.exception);
939 } else {
940 loge("getAllowedCarriers: Unknown exception");
941 }
942 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700943 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700944 break;
945
Nathan Haroldb3014052017-01-25 15:57:32 -0800946 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
947 ar = (AsyncResult) msg.obj;
948 request = (MainThreadRequest) ar.userObj;
949 if (ar.exception == null && ar.result != null) {
950 request.result = ar.result;
951 } else {
952 request.result = new IllegalArgumentException(
953 "Failed to retrieve Forbidden Plmns");
954 if (ar.result == null) {
955 loge("getForbiddenPlmns: Empty response");
956 } else {
957 loge("getForbiddenPlmns: Unknown exception");
958 }
959 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700960 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800961 break;
962
963 case CMD_GET_FORBIDDEN_PLMNS:
964 request = (MainThreadRequest) msg.obj;
965 uiccCard = getUiccCardFromRequest(request);
966 if (uiccCard == null) {
967 loge("getForbiddenPlmns() UiccCard is null");
968 request.result = new IllegalArgumentException(
969 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700970 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800971 break;
972 }
973 Integer appType = (Integer) request.argument;
974 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
975 if (uiccApp == null) {
976 loge("getForbiddenPlmns() no app with specified type -- "
977 + appType);
978 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700979 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800980 break;
981 } else {
982 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
983 + " specified type -- " + appType);
984 }
985 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
986 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
987 onCompleted);
988 break;
989
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000990 case CMD_SWITCH_SLOTS:
991 request = (MainThreadRequest) msg.obj;
992 int[] physicalSlots = (int[]) request.argument;
993 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
994 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
995 break;
996
997 case EVENT_SWITCH_SLOTS_DONE:
998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
1000 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001001 notifyRequester(request);
1002 break;
1003 case CMD_GET_NETWORK_SELECTION_MODE:
1004 request = (MainThreadRequest) msg.obj;
1005 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1006 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1007 break;
1008
1009 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1010 ar = (AsyncResult) msg.obj;
1011 request = (MainThreadRequest) ar.userObj;
1012 if (ar.exception != null) {
1013 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1014 } else {
1015 int mode = ((int[]) ar.result)[0];
1016 if (mode == 0) {
1017 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1018 } else {
1019 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1020 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001021 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001022 notifyRequester(request);
1023 break;
1024 case CMD_GET_CDMA_ROAMING_MODE:
1025 request = (MainThreadRequest) msg.obj;
1026 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1027 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1028 break;
1029 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 if (ar.exception != null) {
1033 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1034 } else {
1035 request.result = ((int[]) ar.result)[0];
1036 }
1037 notifyRequester(request);
1038 break;
1039 case CMD_SET_CDMA_ROAMING_MODE:
1040 request = (MainThreadRequest) msg.obj;
1041 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1042 int mode = (int) request.argument;
1043 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1044 break;
1045 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1046 ar = (AsyncResult) msg.obj;
1047 request = (MainThreadRequest) ar.userObj;
1048 request.result = ar.exception == null;
1049 notifyRequester(request);
1050 break;
1051 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1052 request = (MainThreadRequest) msg.obj;
1053 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1054 int subscriptionMode = (int) request.argument;
1055 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1056 break;
1057 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1058 ar = (AsyncResult) msg.obj;
1059 request = (MainThreadRequest) ar.userObj;
1060 request.result = ar.exception == null;
1061 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001062 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 case CMD_GET_ALL_CELL_INFO:
1064 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001065 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001066 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001067 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001068 case EVENT_GET_ALL_CELL_INFO_DONE:
1069 ar = (AsyncResult) msg.obj;
1070 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001071 // If a timeout occurs, the response will be null
1072 request.result = (ar.exception == null && ar.result != null)
1073 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001074 synchronized (request) {
1075 request.notifyAll();
1076 }
1077 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001078 case CMD_REQUEST_CELL_INFO_UPDATE:
1079 request = (MainThreadRequest) msg.obj;
1080 request.phone.requestCellInfoUpdate(request.workSource,
1081 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1082 break;
1083 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1084 ar = (AsyncResult) msg.obj;
1085 request = (MainThreadRequest) ar.userObj;
1086 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1087 try {
1088 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001089 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001090 cb.onError(
1091 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1092 ar.exception.getClass().getName(),
1093 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001094 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001095 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001096 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001097 } else {
1098 // use the result as returned
1099 cb.onCellInfo((List<CellInfo>) ar.result);
1100 }
1101 } catch (RemoteException re) {
1102 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1103 }
1104 break;
1105 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001106 request = (MainThreadRequest) msg.obj;
1107 WorkSource ws = (WorkSource) request.argument;
1108 Phone phone = getPhoneFromRequest(request);
1109 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1110 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001111 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001112 ar = (AsyncResult) msg.obj;
1113 request = (MainThreadRequest) ar.userObj;
1114 if (ar.exception == null) {
1115 request.result = ar.result;
1116 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001117 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001118 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1119 ? new CdmaCellLocation() : new GsmCellLocation();
1120 }
1121
1122 synchronized (request) {
1123 request.notifyAll();
1124 }
1125 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001126 case CMD_MODEM_REBOOT:
1127 request = (MainThreadRequest) msg.obj;
1128 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001129 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001130 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001131 case EVENT_CMD_MODEM_REBOOT_DONE:
1132 handleNullReturnEvent(msg, "rebootModem");
1133 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001134 case CMD_REQUEST_ENABLE_MODEM:
1135 request = (MainThreadRequest) msg.obj;
1136 boolean enable = (boolean) request.argument;
1137 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001138 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001139 PhoneConfigurationManager.getInstance()
1140 .enablePhone(request.phone, enable, onCompleted);
1141 break;
1142 case EVENT_ENABLE_MODEM_DONE:
1143 ar = (AsyncResult) msg.obj;
1144 request = (MainThreadRequest) ar.userObj;
1145 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001146 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001147 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001148 if ((boolean) request.result) {
1149 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1150 updateModemStateMetrics();
1151 } else {
1152 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1153 + ar.exception);
1154 }
1155 notifyRequester(request);
1156 break;
1157 case CMD_GET_MODEM_STATUS:
1158 request = (MainThreadRequest) msg.obj;
1159 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1160 PhoneConfigurationManager.getInstance()
1161 .getPhoneStatusFromModem(request.phone, onCompleted);
1162 break;
1163 case EVENT_GET_MODEM_STATUS_DONE:
1164 ar = (AsyncResult) msg.obj;
1165 request = (MainThreadRequest) ar.userObj;
1166 int id = request.phone.getPhoneId();
1167 if (ar.exception == null && ar.result != null) {
1168 request.result = ar.result;
1169 //update the cache as modem status has changed
1170 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1171 (boolean) request.result);
1172 } else {
1173 // Return true if modem status cannot be retrieved. For most cases,
1174 // modem status is on. And for older version modems, GET_MODEM_STATUS
1175 // and disable modem are not supported. Modem is always on.
1176 // TODO: this should be fixed in R to support a third
1177 // status UNKNOWN b/131631629
1178 request.result = true;
1179 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1180 + ar.exception);
1181 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001182 notifyRequester(request);
1183 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001184 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1185 ar = (AsyncResult) msg.obj;
1186 request = (MainThreadRequest) ar.userObj;
1187 if (ar.exception == null && ar.result != null) {
1188 request.result = ar.result;
1189 } else {
1190 request.result = -1;
1191 loge("Failed to set Forbidden Plmns");
1192 if (ar.result == null) {
1193 loge("setForbidenPlmns: Empty response");
1194 } else if (ar.exception != null) {
1195 loge("setForbiddenPlmns: Exception: " + ar.exception);
1196 request.result = -1;
1197 } else {
1198 loge("setForbiddenPlmns: Unknown exception");
1199 }
1200 }
1201 notifyRequester(request);
1202 break;
1203 case CMD_SET_FORBIDDEN_PLMNS:
1204 request = (MainThreadRequest) msg.obj;
1205 uiccCard = getUiccCardFromRequest(request);
1206 if (uiccCard == null) {
1207 loge("setForbiddenPlmns: UiccCard is null");
1208 request.result = -1;
1209 notifyRequester(request);
1210 break;
1211 }
1212 Pair<Integer, List<String>> setFplmnsArgs =
1213 (Pair<Integer, List<String>>) request.argument;
1214 appType = setFplmnsArgs.first;
1215 List<String> fplmns = setFplmnsArgs.second;
1216 uiccApp = uiccCard.getApplicationByType(appType);
1217 if (uiccApp == null) {
1218 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1219 request.result = -1;
1220 loge("Failed to get UICC App");
1221 notifyRequester(request);
1222 } else {
1223 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1224 ((SIMRecords) uiccApp.getIccRecords())
1225 .setForbiddenPlmns(onCompleted, fplmns);
1226 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001227 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001228 case CMD_ERASE_MODEM_CONFIG:
1229 request = (MainThreadRequest) msg.obj;
1230 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1231 defaultPhone.eraseModemConfig(onCompleted);
1232 break;
1233 case EVENT_ERASE_MODEM_CONFIG_DONE:
1234 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001235 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001236 default:
1237 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1238 break;
1239 }
1240 }
Jake Hambye994d462014-02-03 13:10:13 -08001241
Pengquan Menga1bb6272018-09-06 09:59:22 -07001242 private void notifyRequester(MainThreadRequest request) {
1243 synchronized (request) {
1244 request.notifyAll();
1245 }
1246 }
1247
Jake Hambye994d462014-02-03 13:10:13 -08001248 private void handleNullReturnEvent(Message msg, String command) {
1249 AsyncResult ar = (AsyncResult) msg.obj;
1250 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1251 if (ar.exception == null) {
1252 request.result = true;
1253 } else {
1254 request.result = false;
1255 if (ar.exception instanceof CommandException) {
1256 loge(command + ": CommandException: " + ar.exception);
1257 } else {
1258 loge(command + ": Unknown exception");
1259 }
1260 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001261 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 }
1264
1265 /**
1266 * Posts the specified command to be executed on the main thread,
1267 * waits for the request to complete, and returns the result.
1268 * @see #sendRequestAsync
1269 */
1270 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001271 return sendRequest(
1272 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001273 }
1274
1275 /**
1276 * Posts the specified command to be executed on the main thread,
1277 * waits for the request to complete, and returns the result.
1278 * @see #sendRequestAsync
1279 */
1280 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1281 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001282 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001283 }
1284
1285 /**
1286 * Posts the specified command to be executed on the main thread,
1287 * waits for the request to complete, and returns the result.
1288 * @see #sendRequestAsync
1289 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001290 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001291 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001292 }
1293
1294 /**
1295 * Posts the specified command to be executed on the main thread,
1296 * waits for the request to complete, and returns the result.
1297 * @see #sendRequestAsync
1298 */
Nathan Harold92bed182018-10-12 18:16:49 -07001299 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1300 return sendRequest(command, argument, subId, null, workSource);
1301 }
1302
1303 /**
1304 * Posts the specified command to be executed on the main thread,
1305 * waits for the request to complete, and returns the result.
1306 * @see #sendRequestAsync
1307 */
1308 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1309 return sendRequest(
1310 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1311 }
1312
1313 /**
1314 * Posts the specified command to be executed on the main thread,
1315 * waits for the request to complete, and returns the result.
1316 * @see #sendRequestAsync
1317 */
1318 private Object sendRequest(
1319 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001320 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1321 throw new RuntimeException("This method will deadlock if called from the main thread.");
1322 }
1323
Nathan Harold92bed182018-10-12 18:16:49 -07001324 MainThreadRequest request = null;
1325 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1326 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1327 } else if (phone != null) {
1328 request = new MainThreadRequest(argument, phone, workSource);
1329 } else {
1330 request = new MainThreadRequest(argument, subId, workSource);
1331 }
1332
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 Message msg = mMainThreadHandler.obtainMessage(command, request);
1334 msg.sendToTarget();
1335
1336 // Wait for the request to complete
1337 synchronized (request) {
1338 while (request.result == null) {
1339 try {
1340 request.wait();
1341 } catch (InterruptedException e) {
1342 // Do nothing, go back and wait until the request is complete
1343 }
1344 }
1345 }
1346 return request.result;
1347 }
1348
1349 /**
1350 * Asynchronous ("fire and forget") version of sendRequest():
1351 * Posts the specified command to be executed on the main thread, and
1352 * returns immediately.
1353 * @see #sendRequest
1354 */
1355 private void sendRequestAsync(int command) {
1356 mMainThreadHandler.sendEmptyMessage(command);
1357 }
1358
1359 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001360 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001361 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001362 */
1363 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001364 sendRequestAsync(command, argument, null, null);
1365 }
1366
1367 /**
1368 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1369 * @see {@link #sendRequest(int,Object)}
1370 */
1371 private void sendRequestAsync(
1372 int command, Object argument, Phone phone, WorkSource workSource) {
1373 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001374 Message msg = mMainThreadHandler.obtainMessage(command, request);
1375 msg.sendToTarget();
1376 }
1377
1378 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 * Initialize the singleton PhoneInterfaceManager instance.
1380 * This is only done once, at startup, from PhoneApp.onCreate().
1381 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001382 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383 synchronized (PhoneInterfaceManager.class) {
1384 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001385 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 } else {
1387 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1388 }
1389 return sInstance;
1390 }
1391 }
1392
1393 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001394 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001397 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001398 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001399 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1400 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001401 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001402 mTelephonySharedPreferences =
1403 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001404 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001405 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001406
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 publish();
1408 }
1409
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001410 private Phone getDefaultPhone() {
1411 Phone thePhone = getPhone(getDefaultSubscription());
1412 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1413 }
1414
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415 private void publish() {
1416 if (DBG) log("publish: " + this);
1417
1418 ServiceManager.addService("phone", this);
1419 }
1420
Stuart Scott584921c2015-01-15 17:10:34 -08001421 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001422 if (request.phone != null) {
1423 return request.phone;
1424 } else {
1425 return getPhoneFromSubId(request.subId);
1426 }
1427 }
1428
1429 private Phone getPhoneFromSubId(int subId) {
1430 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1431 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001432 }
1433
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001434 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1435 Phone phone = getPhoneFromRequest(request);
1436 return phone == null ? null :
1437 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1438 }
1439
Wink Saville36469e72014-06-11 15:17:00 -07001440 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001441 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001442 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001444
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001445 private void sendEraseModemConfig(Phone phone) {
1446 if (phone != null) {
1447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1448 mApp, phone.getSubId(), "eraseModemConfig");
1449 final long identity = Binder.clearCallingIdentity();
1450 try {
1451 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1452 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1453 } finally {
1454 Binder.restoreCallingIdentity(identity);
1455 }
1456 }
1457 }
1458
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001460 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001461 }
1462
Wink Savilleb564aae2014-10-23 10:18:09 -07001463 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001464 if (DBG) log("dial: " + number);
1465 // No permission check needed here: This is just a wrapper around the
1466 // ACTION_DIAL intent, which is available to any app since it puts up
1467 // the UI before it does anything.
1468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001469 final long identity = Binder.clearCallingIdentity();
1470 try {
1471 String url = createTelUrl(number);
1472 if (url == null) {
1473 return;
1474 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001476 // PENDING: should we just silently fail if phone is offhook or ringing?
1477 PhoneConstants.State state = mCM.getState(subId);
1478 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1479 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1480 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1481 mApp.startActivity(intent);
1482 }
1483 } finally {
1484 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001485 }
1486 }
1487
1488 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001489 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001490 }
1491
Wink Savilleb564aae2014-10-23 10:18:09 -07001492 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001493 if (DBG) log("call: " + number);
1494
1495 // This is just a wrapper around the ACTION_CALL intent, but we still
1496 // need to do a permission check since we're calling startActivity()
1497 // from the context of the phone app.
1498 enforceCallPermission();
1499
Jordan Liu1617b712019-07-10 15:06:26 -07001500 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 != AppOpsManager.MODE_ALLOWED) {
1502 return;
1503 }
1504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001505 final long identity = Binder.clearCallingIdentity();
1506 try {
1507 String url = createTelUrl(number);
1508 if (url == null) {
1509 return;
1510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001512 boolean isValid = false;
1513 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1514 if (slist != null) {
1515 for (SubscriptionInfo subInfoRecord : slist) {
1516 if (subInfoRecord.getSubscriptionId() == subId) {
1517 isValid = true;
1518 break;
1519 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001520 }
Wink Saville08874612014-08-31 19:19:58 -07001521 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001522 if (!isValid) {
1523 return;
1524 }
Wink Saville08874612014-08-31 19:19:58 -07001525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001526 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1527 intent.putExtra(SUBSCRIPTION_KEY, subId);
1528 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1529 mApp.startActivity(intent);
1530 } finally {
1531 Binder.restoreCallingIdentity(identity);
1532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 }
1534
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001535 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001537 }
1538
Wink Savilleb564aae2014-10-23 10:18:09 -07001539 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001540 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001541 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1542 }
1543
1544 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001545 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001546 }
1547
Wink Savilleb564aae2014-10-23 10:18:09 -07001548 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001549 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001550 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1551 }
1552
1553 /** {@hide} */
1554 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001555 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001556 }
1557
Wink Savilleb564aae2014-10-23 10:18:09 -07001558 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001560
1561 final long identity = Binder.clearCallingIdentity();
1562 try {
1563 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1564 checkSimPin.start();
1565 return checkSimPin.unlockSim(null, pin);
1566 } finally {
1567 Binder.restoreCallingIdentity(identity);
1568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 }
1570
Wink Saville9de0f752013-10-22 19:04:03 -07001571 /** {@hide} */
1572 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001573 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001574 }
1575
Wink Savilleb564aae2014-10-23 10:18:09 -07001576 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001578
1579 final long identity = Binder.clearCallingIdentity();
1580 try {
1581 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1582 checkSimPuk.start();
1583 return checkSimPuk.unlockSim(puk, pin);
1584 } finally {
1585 Binder.restoreCallingIdentity(identity);
1586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 }
1588
1589 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001590 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 * a synchronous one.
1592 */
1593 private static class UnlockSim extends Thread {
1594
1595 private final IccCard mSimCard;
1596
1597 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001598 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1599 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600
1601 // For replies from SimCard interface
1602 private Handler mHandler;
1603
1604 // For async handler to identify request type
1605 private static final int SUPPLY_PIN_COMPLETE = 100;
1606
1607 public UnlockSim(IccCard simCard) {
1608 mSimCard = simCard;
1609 }
1610
1611 @Override
1612 public void run() {
1613 Looper.prepare();
1614 synchronized (UnlockSim.this) {
1615 mHandler = new Handler() {
1616 @Override
1617 public void handleMessage(Message msg) {
1618 AsyncResult ar = (AsyncResult) msg.obj;
1619 switch (msg.what) {
1620 case SUPPLY_PIN_COMPLETE:
1621 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1622 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001623 mRetryCount = msg.arg1;
1624 if (ar.exception != null) {
1625 if (ar.exception instanceof CommandException &&
1626 ((CommandException)(ar.exception)).getCommandError()
1627 == CommandException.Error.PASSWORD_INCORRECT) {
1628 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1629 } else {
1630 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1631 }
1632 } else {
1633 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 mDone = true;
1636 UnlockSim.this.notifyAll();
1637 }
1638 break;
1639 }
1640 }
1641 };
1642 UnlockSim.this.notifyAll();
1643 }
1644 Looper.loop();
1645 }
1646
1647 /*
1648 * Use PIN or PUK to unlock SIM card
1649 *
1650 * If PUK is null, unlock SIM card with PIN
1651 *
1652 * If PUK is not null, unlock SIM card with PUK and set PIN code
1653 */
Wink Saville9de0f752013-10-22 19:04:03 -07001654 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655
1656 while (mHandler == null) {
1657 try {
1658 wait();
1659 } catch (InterruptedException e) {
1660 Thread.currentThread().interrupt();
1661 }
1662 }
1663 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1664
1665 if (puk == null) {
1666 mSimCard.supplyPin(pin, callback);
1667 } else {
1668 mSimCard.supplyPuk(puk, pin, callback);
1669 }
1670
1671 while (!mDone) {
1672 try {
1673 Log.d(LOG_TAG, "wait for done");
1674 wait();
1675 } catch (InterruptedException e) {
1676 // Restore the interrupted status
1677 Thread.currentThread().interrupt();
1678 }
1679 }
1680 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001681 int[] resultArray = new int[2];
1682 resultArray[0] = mResult;
1683 resultArray[1] = mRetryCount;
1684 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 }
1686 }
1687
1688 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001689 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001690
1691 }
1692
Wink Savilleb564aae2014-10-23 10:18:09 -07001693 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 // No permission check needed here: this call is harmless, and it's
1695 // needed for the ServiceState.requestStateUpdate() call (which is
1696 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001697 final long identity = Binder.clearCallingIdentity();
1698 try {
1699 final Phone phone = getPhone(subId);
1700 if (phone != null) {
1701 phone.updateServiceLocation();
1702 }
1703 } finally {
1704 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 }
1707
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001708 @Override
1709 public boolean isRadioOn(String callingPackage) {
1710 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001711 }
1712
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001713 @Override
1714 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001716 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001717 return false;
1718 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001719
1720 final long identity = Binder.clearCallingIdentity();
1721 try {
1722 return isRadioOnForSubscriber(subId);
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
1725 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001726 }
1727
1728 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001729 final long identity = Binder.clearCallingIdentity();
1730 try {
1731 final Phone phone = getPhone(subId);
1732 if (phone != null) {
1733 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1734 } else {
1735 return false;
1736 }
1737 } finally {
1738 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 }
1741
1742 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001743 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 }
Wink Saville36469e72014-06-11 15:17:00 -07001745
Wink Savilleb564aae2014-10-23 10:18:09 -07001746 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001748
1749 final long identity = Binder.clearCallingIdentity();
1750 try {
1751 final Phone phone = getPhone(subId);
1752 if (phone != null) {
1753 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1754 }
1755 } finally {
1756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001757 }
Wink Saville36469e72014-06-11 15:17:00 -07001758 }
1759
1760 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001761 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001762 }
1763
Wink Savilleb564aae2014-10-23 10:18:09 -07001764 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001765 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001766
1767 final long identity = Binder.clearCallingIdentity();
1768 try {
1769 final Phone phone = getPhone(subId);
1770 if (phone == null) {
1771 return false;
1772 }
1773 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1774 toggleRadioOnOffForSubscriber(subId);
1775 }
1776 return true;
1777 } finally {
1778 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001779 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001780 }
Wink Saville36469e72014-06-11 15:17:00 -07001781
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001782 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001783 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001784 /*
1785 * If any of the Radios are available, it will need to be
1786 * shutdown. So return true if any Radio is available.
1787 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001788 final long identity = Binder.clearCallingIdentity();
1789 try {
1790 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1791 Phone phone = PhoneFactory.getPhone(i);
1792 if (phone != null && phone.isRadioAvailable()) return true;
1793 }
1794 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1795 return false;
1796 } finally {
1797 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001798 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001799 }
1800
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001801 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001802 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001803 enforceModifyPermission();
1804
1805 final long identity = Binder.clearCallingIdentity();
1806 try {
1807 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1808 logv("Shutting down Phone " + i);
1809 shutdownRadioUsingPhoneId(i);
1810 }
1811 } finally {
1812 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001813 }
1814 }
1815
1816 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001817 Phone phone = PhoneFactory.getPhone(phoneId);
1818 if (phone != null && phone.isRadioAvailable()) {
1819 phone.shutdownRadio();
1820 }
1821 }
1822
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001824 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001825
1826 final long identity = Binder.clearCallingIdentity();
1827 try {
1828 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1829 if (defaultPhone != null) {
1830 defaultPhone.setRadioPower(turnOn);
1831 return true;
1832 } else {
1833 loge("There's no default phone.");
1834 return false;
1835 }
1836 } finally {
1837 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001838 }
Wink Saville36469e72014-06-11 15:17:00 -07001839 }
1840
Wink Savilleb564aae2014-10-23 10:18:09 -07001841 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001843
1844 final long identity = Binder.clearCallingIdentity();
1845 try {
1846 final Phone phone = getPhone(subId);
1847 if (phone != null) {
1848 phone.setRadioPower(turnOn);
1849 return true;
1850 } else {
1851 return false;
1852 }
1853 } finally {
1854 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001855 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 }
1857
Wink Saville36469e72014-06-11 15:17:00 -07001858 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001859 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 public boolean enableDataConnectivity() {
1861 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001862
1863 final long identity = Binder.clearCallingIdentity();
1864 try {
1865 int subId = mSubscriptionController.getDefaultDataSubId();
1866 final Phone phone = getPhone(subId);
1867 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001868 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001869 return true;
1870 } else {
1871 return false;
1872 }
1873 } finally {
1874 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 }
1877
Wink Saville36469e72014-06-11 15:17:00 -07001878 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001879 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 public boolean disableDataConnectivity() {
1881 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001882
1883 final long identity = Binder.clearCallingIdentity();
1884 try {
1885 int subId = mSubscriptionController.getDefaultDataSubId();
1886 final Phone phone = getPhone(subId);
1887 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001888 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001889 return true;
1890 } else {
1891 return false;
1892 }
1893 } finally {
1894 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 }
1897
Sanket Padawe356d7632015-06-22 14:03:32 -07001898 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001899 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001900 final long identity = Binder.clearCallingIdentity();
1901 try {
1902 final Phone phone = getPhone(subId);
1903 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001904 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001905 } else {
1906 return false;
1907 }
1908 } finally {
1909 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001911 }
1912
1913 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001914 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001915 }
1916
pkanwarae03a6b2016-11-06 20:37:09 -08001917 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001918 enforceCallPermission();
1919
1920 final long identity = Binder.clearCallingIdentity();
1921 try {
1922 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1923 return;
1924 }
1925 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1926 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1927 } finally {
1928 Binder.restoreCallingIdentity(identity);
1929 }
pkanwar32d516d2016-10-14 19:37:38 -07001930 };
1931
Wink Savilleb564aae2014-10-23 10:18:09 -07001932 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001934
1935 final long identity = Binder.clearCallingIdentity();
1936 try {
1937 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1938 return false;
1939 }
1940 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1941 } finally {
1942 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001943 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 }
1945
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001947 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001948 }
1949
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001950 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001951 final long identity = Binder.clearCallingIdentity();
1952 try {
1953 Phone phone = PhoneFactory.getPhone(slotIndex);
1954 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1955 PhoneConstantConversions.convertCallState(phone.getState());
1956 } finally {
1957 Binder.restoreCallingIdentity(identity);
1958 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 }
1960
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001962 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001963 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1964 }
1965
1966 @Override
1967 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001968 final long identity = Binder.clearCallingIdentity();
1969 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001970 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001971 if (phone != null) {
1972 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1973 } else {
1974 return PhoneConstantConversions.convertDataState(
1975 PhoneConstants.DataState.DISCONNECTED);
1976 }
1977 } finally {
1978 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001979 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001980 }
1981
Sanket Padawe356d7632015-06-22 14:03:32 -07001982 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001983 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001984 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1985 }
1986
1987 @Override
1988 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001989 final long identity = Binder.clearCallingIdentity();
1990 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001991 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001992 if (phone != null) {
1993 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1994 } else {
1995 return TelephonyManager.DATA_ACTIVITY_NONE;
1996 }
1997 } finally {
1998 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 }
2001
2002 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002003 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002004 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002005 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002006
2007 LocationAccessPolicy.LocationPermissionResult locationResult =
2008 LocationAccessPolicy.checkLocationPermission(mApp,
2009 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2010 .setCallingPackage(callingPackage)
2011 .setCallingPid(Binder.getCallingPid())
2012 .setCallingUid(Binder.getCallingUid())
2013 .setMethod("getCellLocation")
2014 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2015 .build());
2016 switch (locationResult) {
2017 case DENIED_HARD:
2018 throw new SecurityException("Not allowed to access cell location");
2019 case DENIED_SOFT:
2020 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021 }
2022
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002023 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002024 final long identity = Binder.clearCallingIdentity();
2025 try {
2026 if (DBG_LOC) log("getCellLocation: is active user");
2027 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002028 int subId = mSubscriptionController.getDefaultDataSubId();
2029 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2030 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002031 return data;
2032 } finally {
2033 Binder.restoreCallingIdentity(identity);
2034 }
Svetoslav64fad262015-04-14 14:35:21 -07002035 }
2036
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002037 @Override
Jack Yu7c5d91a2019-09-26 11:48:33 -07002038 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) {
2039 if (!TextUtils.isEmpty(callingPackage)) {
2040 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
2041 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2042 mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) {
2043 return "";
2044 }
2045 }
2046
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002047 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2048 // registered cell info, so return a NULL country instead.
2049 final long identity = Binder.clearCallingIdentity();
2050 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002051 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2052 // Get default phone in this case.
2053 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2054 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002055 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002056 // Todo: fix this when we can get the actual cellular network info when the device
2057 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002058 if (TelephonyManager.NETWORK_TYPE_IWLAN
2059 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2060 return "";
2061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002062 Phone phone = PhoneFactory.getPhone(phoneId);
2063 if (phone != null) {
2064 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002065 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002066 if (sst != null) {
2067 LocaleTracker lt = sst.getLocaleTracker();
2068 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002069 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2070 return lt.getCurrentCountry();
2071 } else if (emergencyNumberTracker != null) {
2072 return emergencyNumberTracker.getEmergencyCountryIso();
2073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002074 }
2075 }
2076 }
2077 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002078 } finally {
2079 Binder.restoreCallingIdentity(identity);
2080 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002081 }
2082
2083 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002084 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002085 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002086 }
2087
Sanket Padawe356d7632015-06-22 14:03:32 -07002088 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002089 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 mApp.enforceCallingOrSelfPermission(
2091 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002092
2093 final long identity = Binder.clearCallingIdentity();
2094 try {
2095 final Phone phone = getPhone(subId);
2096 if (phone != null) {
2097 phone.enableLocationUpdates();
2098 }
2099 } finally {
2100 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002101 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 }
2103
2104 @Override
2105 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002106 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002107 }
2108
Sanket Padawe356d7632015-06-22 14:03:32 -07002109 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002110 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 mApp.enforceCallingOrSelfPermission(
2112 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002113
2114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 final Phone phone = getPhone(subId);
2117 if (phone != null) {
2118 phone.disableLocationUpdates();
2119 }
2120 } finally {
2121 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002122 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 }
2124
Nathan Harold31d7ff32018-10-15 20:20:30 -07002125 /**
2126 * Returns the target SDK version number for a given package name.
2127 *
Nathan Haroldec184742019-07-10 17:04:16 -07002128 * This call MUST be invoked before clearing the calling UID.
2129 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002130 * @return target SDK if the package is found or INT_MAX.
2131 */
2132 private int getTargetSdk(String packageName) {
2133 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002134 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002135 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002136 if (ai != null) return ai.targetSdkVersion;
2137 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002138 loge("Failed to get package info for pkg="
2139 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002140 }
2141 return Integer.MAX_VALUE;
2142 }
2143
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 @Override
2145 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002146 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2147 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002148 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2149 throw new SecurityException(
2150 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2151 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002152
Jordan Liu1617b712019-07-10 15:06:26 -07002153 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2155 return null;
2156 }
Svetoslav64fad262015-04-14 14:35:21 -07002157
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002158 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159
Nathan Haroldf180aac2018-06-01 18:43:55 -07002160 List<CellInfo> info = getAllCellInfo(callingPackage);
2161 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162
Nathan Haroldf180aac2018-06-01 18:43:55 -07002163 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2164 for (CellInfo ci : info) {
2165 if (ci instanceof CellInfoGsm) {
2166 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2167 } else if (ci instanceof CellInfoWcdma) {
2168 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002171 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 }
2173
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002174 private List<CellInfo> getCachedCellInfo() {
2175 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2176 for (Phone phone : PhoneFactory.getPhones()) {
2177 List<CellInfo> info = phone.getAllCellInfo();
2178 if (info != null) cellInfos.addAll(info);
2179 }
2180 return cellInfos;
2181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182
2183 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002184 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002185 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002186 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002187
2188 LocationAccessPolicy.LocationPermissionResult locationResult =
2189 LocationAccessPolicy.checkLocationPermission(mApp,
2190 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2191 .setCallingPackage(callingPackage)
2192 .setCallingPid(Binder.getCallingPid())
2193 .setCallingUid(Binder.getCallingUid())
2194 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002195 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002196 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2197 .build());
2198 switch (locationResult) {
2199 case DENIED_HARD:
2200 throw new SecurityException("Not allowed to access cell info");
2201 case DENIED_SOFT:
2202 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 }
2204
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002205 final int targetSdk = getTargetSdk(callingPackage);
2206 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2207 return getCachedCellInfo();
2208 }
2209
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002210 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002211 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002212 final long identity = Binder.clearCallingIdentity();
2213 try {
2214 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2215 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002216 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002217 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002218 if (info != null) cellInfos.addAll(info);
2219 }
2220 return cellInfos;
2221 } finally {
2222 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 }
2224 }
2225
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002226 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002227 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2228 requestCellInfoUpdateInternal(
2229 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2230 }
2231
2232 @Override
2233 public void requestCellInfoUpdateWithWorkSource(
2234 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2235 enforceModifyPermission();
2236 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2237 }
2238
2239 private void requestCellInfoUpdateInternal(
2240 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002241 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002242 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002243
2244 LocationAccessPolicy.LocationPermissionResult locationResult =
2245 LocationAccessPolicy.checkLocationPermission(mApp,
2246 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2247 .setCallingPackage(callingPackage)
2248 .setCallingPid(Binder.getCallingPid())
2249 .setCallingUid(Binder.getCallingUid())
2250 .setMethod("requestCellInfoUpdate")
2251 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2252 .build());
2253 switch (locationResult) {
2254 case DENIED_HARD:
2255 throw new SecurityException("Not allowed to access cell info");
2256 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002257 try {
2258 cb.onCellInfo(new ArrayList<CellInfo>());
2259 } catch (RemoteException re) {
2260 // Drop without consequences
2261 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002262 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002263 }
2264
Nathan Harolda939a962019-05-09 10:13:47 -07002265
2266 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002267 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2268
2269 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2270 }
2271
2272 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002274 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002275 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002276
2277 final long identity = Binder.clearCallingIdentity();
2278 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002279 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002280 } finally {
2281 Binder.restoreCallingIdentity(identity);
2282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 }
2284
Shishir Agrawala9f32182016-04-12 12:00:16 -07002285 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002286 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002287 Phone phone = PhoneFactory.getPhone(slotIndex);
2288 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002289 return null;
2290 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002291 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002292 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2293 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002294 return null;
2295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002296
2297 final long identity = Binder.clearCallingIdentity();
2298 try {
2299 return phone.getImei();
2300 } finally {
2301 Binder.restoreCallingIdentity(identity);
2302 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002303 }
2304
2305 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002306 public String getTypeAllocationCodeForSlot(int slotIndex) {
2307 Phone phone = PhoneFactory.getPhone(slotIndex);
2308 String tac = null;
2309 if (phone != null) {
2310 String imei = phone.getImei();
2311 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2312 }
2313 return tac;
2314 }
2315
2316 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002317 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002318 Phone phone = PhoneFactory.getPhone(slotIndex);
2319 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002320 return null;
2321 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002322
Jeff Davidson913390f2018-02-23 17:11:49 -08002323 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002324 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2325 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002326 return null;
2327 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002328
2329 final long identity = Binder.clearCallingIdentity();
2330 try {
2331 return phone.getMeid();
2332 } finally {
2333 Binder.restoreCallingIdentity(identity);
2334 }
Jack Yu2af8d712017-03-15 17:14:14 -07002335 }
2336
2337 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002338 public String getManufacturerCodeForSlot(int slotIndex) {
2339 Phone phone = PhoneFactory.getPhone(slotIndex);
2340 String manufacturerCode = null;
2341 if (phone != null) {
2342 String meid = phone.getMeid();
2343 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2344 }
2345 return manufacturerCode;
2346 }
2347
2348 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002349 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002350 Phone phone = PhoneFactory.getPhone(slotIndex);
2351 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002352 return null;
2353 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002354 int subId = phone.getSubId();
2355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2356 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2357 return null;
2358 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002359
2360 final long identity = Binder.clearCallingIdentity();
2361 try {
2362 return phone.getDeviceSvn();
2363 } finally {
2364 Binder.restoreCallingIdentity(identity);
2365 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002366 }
2367
fionaxu43304da2017-11-27 22:51:16 -08002368 @Override
2369 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002370 final long identity = Binder.clearCallingIdentity();
2371 try {
2372 final Phone phone = getPhone(subId);
2373 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2374 } finally {
2375 Binder.restoreCallingIdentity(identity);
2376 }
fionaxu43304da2017-11-27 22:51:16 -08002377 }
2378
2379 @Override
2380 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002381 final long identity = Binder.clearCallingIdentity();
2382 try {
2383 final Phone phone = getPhone(subId);
2384 return phone == null ? null : phone.getCarrierName();
2385 } finally {
2386 Binder.restoreCallingIdentity(identity);
2387 }
fionaxu43304da2017-11-27 22:51:16 -08002388 }
2389
calvinpanffe225e2018-11-01 19:43:06 +08002390 @Override
chen xu0026ca62019-03-06 15:28:50 -08002391 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002392 final long identity = Binder.clearCallingIdentity();
2393 try {
2394 final Phone phone = getPhone(subId);
2395 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002396 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002397 } finally {
2398 Binder.restoreCallingIdentity(identity);
2399 }
2400 }
2401
2402 @Override
chen xu0026ca62019-03-06 15:28:50 -08002403 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002404 final long identity = Binder.clearCallingIdentity();
2405 try {
2406 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002407 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002408 } finally {
2409 Binder.restoreCallingIdentity(identity);
2410 }
2411 }
2412
chen xu651eec72018-11-11 19:03:44 -08002413 @Override
chen xu864e11c2018-12-06 22:10:03 -08002414 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2415 if (!isSubscriptionMccMnc) {
2416 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2417 }
chen xu651eec72018-11-11 19:03:44 -08002418 final Phone phone = PhoneFactory.getPhone(slotIndex);
2419 if (phone == null) {
2420 return TelephonyManager.UNKNOWN_CARRIER_ID;
2421 }
2422 final long identity = Binder.clearCallingIdentity();
2423 try {
2424 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2425 } finally {
2426 Binder.restoreCallingIdentity(identity);
2427 }
2428 }
2429
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 //
2431 // Internal helper methods.
2432 //
2433
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002434 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2436 *
2437 * @throws SecurityException if the caller does not have the required permission
2438 */
2439 private void enforceModifyPermission() {
2440 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2441 }
2442
Shuo Qianf2b2df42019-11-13 17:43:31 -08002443 private void enforceActiveEmergencySessionPermission() {
2444 mApp.enforceCallingOrSelfPermission(
2445 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2446 }
2447
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 /**
2449 * Make sure the caller has the CALL_PHONE permission.
2450 *
2451 * @throws SecurityException if the caller does not have the required permission
2452 */
2453 private void enforceCallPermission() {
2454 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2455 }
2456
paulhu423b5f22019-08-23 19:17:33 +08002457 private void enforceSettingsPermission() {
2458 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002459 }
2460
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 private String createTelUrl(String number) {
2462 if (TextUtils.isEmpty(number)) {
2463 return null;
2464 }
2465
Jake Hambye994d462014-02-03 13:10:13 -08002466 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 }
2468
Ihab Awadf9e92732013-12-05 18:02:52 -08002469 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2471 }
2472
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002473 private static void logv(String msg) {
2474 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2475 }
2476
Ihab Awadf9e92732013-12-05 18:02:52 -08002477 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2479 }
2480
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002481 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002483 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002484 }
2485
Sanket Padawe356d7632015-06-22 14:03:32 -07002486 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002487 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002488 final long identity = Binder.clearCallingIdentity();
2489 try {
2490 final Phone phone = PhoneFactory.getPhone(slotIndex);
2491 if (phone == null) {
2492 return PhoneConstants.PHONE_TYPE_NONE;
2493 } else {
2494 return phone.getPhoneType();
2495 }
2496 } finally {
2497 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002498 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 }
2500
2501 /**
2502 * Returns the CDMA ERI icon index to display
2503 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002504 @Override
2505 public int getCdmaEriIconIndex(String callingPackage) {
2506 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002507 }
2508
Sanket Padawe356d7632015-06-22 14:03:32 -07002509 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002510 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002511 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002512 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002513 return -1;
2514 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002515
2516 final long identity = Binder.clearCallingIdentity();
2517 try {
2518 final Phone phone = getPhone(subId);
2519 if (phone != null) {
2520 return phone.getCdmaEriIconIndex();
2521 } else {
2522 return -1;
2523 }
2524 } finally {
2525 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 }
2528
2529 /**
2530 * Returns the CDMA ERI icon mode,
2531 * 0 - ON
2532 * 1 - FLASHING
2533 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002534 @Override
2535 public int getCdmaEriIconMode(String callingPackage) {
2536 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002537 }
2538
Sanket Padawe356d7632015-06-22 14:03:32 -07002539 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002540 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002542 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002543 return -1;
2544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545
2546 final long identity = Binder.clearCallingIdentity();
2547 try {
2548 final Phone phone = getPhone(subId);
2549 if (phone != null) {
2550 return phone.getCdmaEriIconMode();
2551 } else {
2552 return -1;
2553 }
2554 } finally {
2555 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 }
2558
2559 /**
2560 * Returns the CDMA ERI text,
2561 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002562 @Override
2563 public String getCdmaEriText(String callingPackage) {
2564 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002565 }
2566
Sanket Padawe356d7632015-06-22 14:03:32 -07002567 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002568 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002570 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002571 return null;
2572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573
2574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 final Phone phone = getPhone(subId);
2577 if (phone != null) {
2578 return phone.getCdmaEriText();
2579 } else {
2580 return null;
2581 }
2582 } finally {
2583 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002585 }
2586
2587 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002588 * Returns the CDMA MDN.
2589 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002590 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002591 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2593 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002594
2595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002598 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599 return phone.getLine1Number();
2600 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002601 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 return null;
2603 }
2604 } finally {
2605 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002606 }
2607 }
2608
2609 /**
2610 * Returns the CDMA MIN.
2611 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002612 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002613 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2615 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616
2617 final long identity = Binder.clearCallingIdentity();
2618 try {
2619 final Phone phone = getPhone(subId);
2620 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2621 return phone.getCdmaMin();
2622 } else {
2623 return null;
2624 }
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002627 }
2628 }
2629
Hall Liud892bec2018-11-30 14:51:45 -08002630 @Override
2631 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2632 INumberVerificationCallback callback, String callingPackage) {
2633 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2634 != PERMISSION_GRANTED) {
2635 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2636 }
2637 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2638
2639 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2640 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2641 throw new SecurityException("Calling package must be configured in the device config");
2642 }
2643
2644 if (range == null) {
2645 throw new NullPointerException("Range must be non-null");
2646 }
2647
2648 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002649 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002650
2651 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2652 }
2653
Junda Liuca05d5d2014-08-14 22:36:34 -07002654 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 * Returns true if CDMA provisioning needs to run.
2656 */
2657 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 final long identity = Binder.clearCallingIdentity();
2659 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002660 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661 } finally {
2662 Binder.restoreCallingIdentity(identity);
2663 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002664 }
2665
2666 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002667 * Sets the voice mail number of a given subId.
2668 */
2669 @Override
2670 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002671 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672
2673 final long identity = Binder.clearCallingIdentity();
2674 try {
2675 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2676 new Pair<String, String>(alphaTag, number), new Integer(subId));
2677 return success;
2678 } finally {
2679 Binder.restoreCallingIdentity(identity);
2680 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002681 }
2682
Ta-wei Yen87c49842016-05-13 21:19:52 -07002683 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002684 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2685 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002686 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2687 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002688 if (!TextUtils.equals(callingPackage, systemDialer)) {
2689 throw new SecurityException("caller must be system dialer");
2690 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002691
2692 final long identity = Binder.clearCallingIdentity();
2693 try {
2694 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2695 if (phoneAccountHandle == null) {
2696 return null;
2697 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002698 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699 } finally {
2700 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002701 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002702 }
2703
2704 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002705 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002706 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002707 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002708 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002709 return null;
2710 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002711
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002712 final long identity = Binder.clearCallingIdentity();
2713 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002714 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002715 } finally {
2716 Binder.restoreCallingIdentity(identity);
2717 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002718 }
2719
2720 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002721 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2722 VisualVoicemailSmsFilterSettings settings) {
2723 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724
2725 final long identity = Binder.clearCallingIdentity();
2726 try {
2727 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002728 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729 } finally {
2730 Binder.restoreCallingIdentity(identity);
2731 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002732 }
2733
2734 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002735 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737
2738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002741 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 } finally {
2743 Binder.restoreCallingIdentity(identity);
2744 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002745 }
2746
2747 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002748 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2749 String callingPackage, int subId) {
2750 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002751
2752 final long identity = Binder.clearCallingIdentity();
2753 try {
2754 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002755 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756 } finally {
2757 Binder.restoreCallingIdentity(identity);
2758 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002759 }
2760
2761 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002762 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002763 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002768 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769 } finally {
2770 Binder.restoreCallingIdentity(identity);
2771 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002772 }
2773
2774 @Override
2775 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2776 String number, int port, String text, PendingIntent sentIntent) {
2777 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002778 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002779 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002780 SmsController smsController = PhoneFactory.getSmsController();
2781 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2782 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002783 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002784
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002785 /**
fionaxu0152e512016-11-14 13:36:14 -08002786 * Sets the voice activation state of a given subId.
2787 */
2788 @Override
2789 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2791 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002792
2793 final long identity = Binder.clearCallingIdentity();
2794 try {
2795 final Phone phone = getPhone(subId);
2796 if (phone != null) {
2797 phone.setVoiceActivationState(activationState);
2798 } else {
2799 loge("setVoiceActivationState fails with invalid subId: " + subId);
2800 }
2801 } finally {
2802 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002803 }
2804 }
2805
2806 /**
2807 * Sets the data activation state of a given subId.
2808 */
2809 @Override
2810 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2812 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002813
2814 final long identity = Binder.clearCallingIdentity();
2815 try {
2816 final Phone phone = getPhone(subId);
2817 if (phone != null) {
2818 phone.setDataActivationState(activationState);
2819 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002820 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821 }
2822 } finally {
2823 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002824 }
2825 }
2826
2827 /**
2828 * Returns the voice activation state of a given subId.
2829 */
2830 @Override
2831 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002832 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833
fionaxu0152e512016-11-14 13:36:14 -08002834 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 final long identity = Binder.clearCallingIdentity();
2836 try {
2837 if (phone != null) {
2838 return phone.getVoiceActivationState();
2839 } else {
2840 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2841 }
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002844 }
2845 }
2846
2847 /**
2848 * Returns the data activation state of a given subId.
2849 */
2850 @Override
2851 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002852 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853
fionaxu0152e512016-11-14 13:36:14 -08002854 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 if (phone != null) {
2858 return phone.getDataActivationState();
2859 } else {
2860 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2861 }
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002864 }
2865 }
2866
2867 /**
Wink Saville36469e72014-06-11 15:17:00 -07002868 * Returns the unread count of voicemails for a subId
2869 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002870 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002871 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2872 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2873 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2874 return 0;
2875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 final long identity = Binder.clearCallingIdentity();
2877 try {
2878 final Phone phone = getPhone(subId);
2879 if (phone != null) {
2880 return phone.getVoiceMessageCount();
2881 } else {
2882 return 0;
2883 }
2884 } finally {
2885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002887 }
2888
2889 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002890 * returns true, if the device is in a state where both voice and data
2891 * are supported simultaneously. This can change based on location or network condition.
2892 */
2893 @Override
2894 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002895 final long identity = Binder.clearCallingIdentity();
2896 try {
2897 final Phone phone = getPhone(subId);
2898 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2899 } finally {
2900 Binder.restoreCallingIdentity(identity);
2901 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002902 }
2903
2904 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002905 * Send the dialer code if called from the current default dialer or the caller has
2906 * carrier privilege.
2907 * @param inputCode The dialer code to send
2908 */
2909 @Override
2910 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002911 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002913 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2914 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002915 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002916 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2917 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919
2920 final long identity = Binder.clearCallingIdentity();
2921 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002922 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923 } finally {
2924 Binder.restoreCallingIdentity(identity);
2925 }
fionaxu235cc5e2017-03-06 22:25:57 -08002926 }
2927
Pengquan Menga1bb6272018-09-06 09:59:22 -07002928 @Override
2929 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002930 if (!isActiveSubscription(subId)) {
2931 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2932 }
2933
Pengquan Menga1bb6272018-09-06 09:59:22 -07002934 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2935 }
2936
Brad Ebinger35c841c2018-10-01 10:40:55 -07002937 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002938 public boolean isInEmergencySmsMode() {
2939 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2940 final long identity = Binder.clearCallingIdentity();
2941 try {
2942 for (Phone phone : PhoneFactory.getPhones()) {
2943 if (phone.isInEmergencySmsMode()) {
2944 return true;
2945 }
2946 }
2947 } finally {
2948 Binder.restoreCallingIdentity(identity);
2949 }
2950 return false;
2951 }
2952
2953 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002954 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2955 throws RemoteException {
2956 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002957 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2958 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2959 "IMS not available on device.");
2960 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002961 final long token = Binder.clearCallingIdentity();
2962 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002964 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002965 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002966 } catch (ImsException e) {
2967 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002968 } finally {
2969 Binder.restoreCallingIdentity(token);
2970 }
2971 }
2972
2973 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002974 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2975 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002976 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2977 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2978 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002979 final long token = Binder.clearCallingIdentity();
2980 try {
2981 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2982 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2983 .removeRegistrationCallbackForSubscription(c, subId);
2984 } catch (ImsException e) {
2985 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2986 + "is inactive, ignoring unregister.");
2987 // If the subscription is no longer active, just return, since the callback
2988 // will already have been removed internally.
2989 } finally {
2990 Binder.restoreCallingIdentity(token);
2991 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002992 }
2993
Brad Ebinger774ba362019-10-22 17:36:18 -07002994 /**
2995 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2996 */
2997 @Override
2998 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2999 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3000 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3001 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3002 "IMS not available on device.");
3003 }
3004 final long token = Binder.clearCallingIdentity();
3005 try {
3006 Phone phone = getPhone(subId);
3007 if (phone == null) {
3008 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3009 + subId + "'");
3010 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3011 }
3012 phone.getImsRegistrationState(regState -> {
3013 try {
3014 consumer.accept((regState == null)
3015 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3016 } catch (RemoteException e) {
3017 // Ignore if the remote process is no longer available to call back.
3018 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3019 }
3020 });
3021 } finally {
3022 Binder.restoreCallingIdentity(token);
3023 }
3024 }
3025
3026 /**
3027 * Get the transport type for the IMS service registration state.
3028 */
3029 @Override
3030 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3031 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3032 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3033 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3034 "IMS not available on device.");
3035 }
3036 final long token = Binder.clearCallingIdentity();
3037 try {
3038 Phone phone = getPhone(subId);
3039 if (phone == null) {
3040 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3041 + subId + "'");
3042 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3043 }
3044 phone.getImsRegistrationTech(regTech -> {
3045 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3046 int regTechConverted = (regTech == null)
3047 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3048 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3049 regTechConverted);
3050 try {
3051 consumer.accept(regTechConverted);
3052 } catch (RemoteException e) {
3053 // Ignore if the remote process is no longer available to call back.
3054 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3055 }
3056 });
3057 } finally {
3058 Binder.restoreCallingIdentity(token);
3059 }
3060 }
3061
Brad Ebinger35c841c2018-10-01 10:40:55 -07003062 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003063 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3064 throws RemoteException {
3065 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003066 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3067 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3068 "IMS not available on device.");
3069 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3071 final long token = Binder.clearCallingIdentity();
3072 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003073 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003074 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003075 } catch (ImsException e) {
3076 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003077 } finally {
3078 Binder.restoreCallingIdentity(token);
3079 }
3080 }
3081
3082 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003083 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3084 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003085 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3086 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3087 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003088
3089 final long token = Binder.clearCallingIdentity();
3090 try {
3091 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3092 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003093 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003094 } catch (ImsException e) {
3095 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3096 + "is inactive, ignoring unregister.");
3097 // If the subscription is no longer active, just return, since the callback
3098 // will already have been removed internally.
3099 } finally {
3100 Binder.restoreCallingIdentity(token);
3101 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003102 }
3103
3104 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003105 public boolean isCapable(int subId, int capability, int regTech) {
3106 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003107 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3108 final long token = Binder.clearCallingIdentity();
3109 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003110 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003111 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003112 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003113 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3114 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003115 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003116 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3117 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003118 } finally {
3119 Binder.restoreCallingIdentity(token);
3120 }
3121 }
3122
3123 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003124 public boolean isAvailable(int subId, int capability, int regTech) {
3125 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003126 final long token = Binder.clearCallingIdentity();
3127 try {
3128 Phone phone = getPhone(subId);
3129 if (phone == null) return false;
3130 return phone.isImsCapabilityAvailable(capability, regTech);
3131 } finally {
3132 Binder.restoreCallingIdentity(token);
3133 }
3134 }
3135
Brad Ebinger77b832e2019-10-17 17:03:22 -07003136 /**
3137 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3138 * subscription.
3139 * @param subId The subscription to use to check the configuration.
3140 * @param callback The callback that will be used to send the result.
3141 * @param capability The MmTelFeature capability that will be used to send the result.
3142 * @param transportType The transport type of the MmTelFeature capability.
3143 */
3144 @Override
3145 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3146 int transportType) {
3147 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3148 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3149 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3150 "IMS not available on device.");
3151 }
3152 final long token = Binder.clearCallingIdentity();
3153 try {
3154 int slotId = getSlotIndex(subId);
3155 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3156 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3157 + subId + "'");
3158 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3159 }
3160 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3161 transportType, aBoolean -> {
3162 try {
3163 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3164 } catch (RemoteException e) {
3165 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3166 + "running. Ignore");
3167 }
3168 });
3169 } finally {
3170 Binder.restoreCallingIdentity(token);
3171 }
3172 }
3173
Brad Ebinger35c841c2018-10-01 10:40:55 -07003174 @Override
3175 public boolean isAdvancedCallingSettingEnabled(int subId) {
3176 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3177 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3178 final long token = Binder.clearCallingIdentity();
3179 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003180 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003181 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003182 } catch (ImsException e) {
3183 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003184 } finally {
3185 Binder.restoreCallingIdentity(token);
3186 }
3187 }
3188
3189 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003190 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003192 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003193 final long identity = Binder.clearCallingIdentity();
3194 try {
3195 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003196 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003197 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003198 } catch (ImsException e) {
3199 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003200 } finally {
3201 Binder.restoreCallingIdentity(identity);
3202 }
3203 }
3204
3205 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003206 public boolean isVtSettingEnabled(int subId) {
3207 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003211 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3212 } catch (ImsException e) {
3213 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003214 } finally {
3215 Binder.restoreCallingIdentity(identity);
3216 }
3217 }
3218
3219 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003220 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003222 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003226 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003227 } catch (ImsException e) {
3228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
3232 }
3233
3234 @Override
3235 public boolean isVoWiFiSettingEnabled(int subId) {
3236 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003240 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003242 } catch (ImsException e) {
3243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 } finally {
3245 Binder.restoreCallingIdentity(identity);
3246 }
3247 }
3248
3249 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003250 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003252 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003253 final long identity = Binder.clearCallingIdentity();
3254 try {
3255 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003256 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003257 } catch (ImsException e) {
3258 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003259 } finally {
3260 Binder.restoreCallingIdentity(identity);
3261 }
3262 }
3263
3264 @Override
3265 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3266 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3267 final long identity = Binder.clearCallingIdentity();
3268 try {
3269 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003270 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003271 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003272 } catch (ImsException e) {
3273 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 } finally {
3275 Binder.restoreCallingIdentity(identity);
3276 }
3277 }
3278
3279 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003280 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003282 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003283 final long identity = Binder.clearCallingIdentity();
3284 try {
3285 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003286 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003287 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003288 } catch (ImsException e) {
3289 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003290 } finally {
3291 Binder.restoreCallingIdentity(identity);
3292 }
3293 }
3294
3295 @Override
3296 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3298 "setVoWiFiNonPersistent");
3299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003302 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003303 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003304 } catch (ImsException e) {
3305 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003306 } finally {
3307 Binder.restoreCallingIdentity(identity);
3308 }
3309 }
3310
3311 @Override
3312 public int getVoWiFiModeSetting(int subId) {
3313 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003317 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003318 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003319 } catch (ImsException e) {
3320 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
3324 }
3325
3326 @Override
3327 public void setVoWiFiModeSetting(int subId, int mode) {
3328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3329 "setVoWiFiModeSetting");
3330 final long identity = Binder.clearCallingIdentity();
3331 try {
3332 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003333 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003334 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003335 } catch (ImsException e) {
3336 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003337 } finally {
3338 Binder.restoreCallingIdentity(identity);
3339 }
3340 }
3341
3342 @Override
3343 public int getVoWiFiRoamingModeSetting(int subId) {
3344 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003348 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003350 } catch (ImsException e) {
3351 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
3355 }
3356
3357 @Override
3358 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3360 "setVoWiFiRoamingModeSetting");
3361 final long identity = Binder.clearCallingIdentity();
3362 try {
3363 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003364 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003366 } catch (ImsException e) {
3367 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003368 } finally {
3369 Binder.restoreCallingIdentity(identity);
3370 }
3371 }
3372
3373 @Override
3374 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3376 "setRttCapabilityEnabled");
3377 final long identity = Binder.clearCallingIdentity();
3378 try {
3379 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003380 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3381 } catch (ImsException e) {
3382 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 } finally {
3384 Binder.restoreCallingIdentity(identity);
3385 }
3386 }
3387
3388 @Override
3389 public boolean isTtyOverVolteEnabled(int subId) {
3390 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3391 final long identity = Binder.clearCallingIdentity();
3392 try {
3393 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003394 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003395 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003396 } catch (ImsException e) {
3397 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003398 } finally {
3399 Binder.restoreCallingIdentity(identity);
3400 }
3401 }
3402
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003403 @Override
3404 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3405 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003409 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003410 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003411 } catch (ImsException e) {
3412 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003413 } finally {
3414 Binder.restoreCallingIdentity(identity);
3415 }
3416 }
3417
3418 @Override
3419 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3420 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3421 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003422 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3423 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3424 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003425 try {
3426 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003427 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003428 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003429 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003430 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3431 + "is inactive, ignoring unregister.");
3432 // If the subscription is no longer active, just return, since the callback will already
3433 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003434 } finally {
3435 Binder.restoreCallingIdentity(identity);
3436 }
3437 }
3438
3439 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003440 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3441 boolean isProvisioned) {
3442 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3443 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3444 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3445 }
3446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3447 "setProvisioningStatusForCapability");
3448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3451 Phone phone = getPhone(subId);
3452 if (phone == null) {
3453 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3454 + subId);
3455 return;
3456 }
3457 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3458 return;
3459 }
3460
3461 // this capability requires provisioning, route to the correct API.
3462 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3463 switch (capability) {
3464 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3465 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3466 ims.setVolteProvisioned(isProvisioned);
3467 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3468 ims.setWfcProvisioned(isProvisioned);
3469 }
3470 break;
3471 }
3472 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3473 // There is currently no difference in VT provisioning type.
3474 ims.setVtProvisioned(isProvisioned);
3475 break;
3476 }
3477 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3478 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3479 // change the capability of the feature instead if needed.
3480 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3481 == isProvisioned) {
3482 // No change in provisioning.
3483 return;
3484 }
3485 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3486 try {
3487 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003488 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003489 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3490 + ", Exception" + e.getMessage());
3491 }
3492 break;
3493 }
3494 default: {
3495 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3496 + capability + "', which does not require provisioning.");
3497 }
3498 }
3499
3500 } finally {
3501 Binder.restoreCallingIdentity(identity);
3502 }
3503 }
3504
3505 @Override
3506 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3507 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3508 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3509 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3510 }
3511 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3512 final long identity = Binder.clearCallingIdentity();
3513 try {
3514 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3515 Phone phone = getPhone(subId);
3516 if (phone == null) {
3517 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3518 + subId);
3519 // We will fail with "true" as the provisioning status because this is the default
3520 // if we do not require provisioning.
3521 return true;
3522 }
3523
3524 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3525 return true;
3526 }
3527
3528 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3529 switch (capability) {
3530 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3531 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3532 return ims.isVolteProvisionedOnDevice();
3533 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3534 return ims.isWfcProvisionedOnDevice();
3535 }
3536 // This should never happen, since we are checking tech above to make sure it
3537 // is either LTE or IWLAN.
3538 throw new IllegalArgumentException("Invalid radio technology for voice "
3539 + "capability.");
3540 }
3541 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3542 // There is currently no difference in VT provisioning type.
3543 return ims.isVtProvisionedOnDevice();
3544 }
3545 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3546 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3547 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3548 }
3549 default: {
3550 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3551 + capability + "', which does not require provisioning.");
3552 }
3553 }
3554
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
3558 }
3559
3560 @Override
3561 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3562 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3563 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3564 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3565 }
3566 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3567 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3568 return (provisionedBits & capability) > 0;
3569 }
3570
3571 @Override
3572 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3573 boolean isProvisioned) {
3574 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3575 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3576 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3577 }
3578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3579 "setProvisioningStatusForCapability");
3580 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3581 // If the current provisioning status for capability already matches isProvisioned,
3582 // do nothing.
3583 if (((provisionedBits & capability) > 0) == isProvisioned) {
3584 return;
3585 }
3586 if (isProvisioned) {
3587 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3588 } else {
3589 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3590 }
3591 }
3592
3593 /**
3594 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3595 * technology. The bitfield should mirror the bitfield defined by
3596 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3597 */
3598 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3599 String key = getMmTelProvisioningKey(subId, tech);
3600 // Default is no capabilities are provisioned.
3601 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3602 }
3603
3604 /**
3605 * Sets the MmTel capability provisioning bitfield (defined by
3606 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3607 * technology specified.
3608 *
3609 * Note: This is a synchronous command and should not be called on UI thread.
3610 */
3611 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3612 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3613 String key = getMmTelProvisioningKey(subId, tech);
3614 editor.putInt(key, newField);
3615 editor.commit();
3616 }
3617
3618 private static String getMmTelProvisioningKey(int subId, int tech) {
3619 // resulting key is provision_ims_mmtel_{subId}_{tech}
3620 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3621 }
3622
3623 /**
3624 * Query CarrierConfig to see if the specified capability requires provisioning for the
3625 * carrier associated with the subscription id.
3626 */
3627 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3628 int capability) {
3629 CarrierConfigManager configManager = new CarrierConfigManager(context);
3630 PersistableBundle c = configManager.getConfigForSubId(subId);
3631 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003632 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003633 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3634 false);
3635 boolean requireVoiceVtProvisioning = c.getBoolean(
3636 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3637
3638 // First check to make sure that the capability requires provisioning.
3639 switch (capability) {
3640 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3641 // intentional fallthrough
3642 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3643 if (requireVoiceVtProvisioning) {
3644 // Voice and Video requires provisioning
3645 return true;
3646 }
3647 break;
3648 }
3649 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3650 if (requireUtProvisioning) {
3651 // UT requires provisioning
3652 return true;
3653 }
3654 break;
3655 }
3656 }
3657 return false;
3658 }
3659
3660 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003661 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003662 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3663 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3664 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003665 enforceReadPrivilegedPermission("getImsProvisioningInt");
3666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003669 int slotId = getSlotIndex(subId);
3670 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3671 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3672 + subId + "' for key:" + key);
3673 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3674 }
3675 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003676 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003677 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3678 + subId + "' for key:" + key);
3679 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
3683 }
3684
3685 @Override
3686 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003687 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3688 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3689 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003690 enforceReadPrivilegedPermission("getImsProvisioningString");
3691 final long identity = Binder.clearCallingIdentity();
3692 try {
3693 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003694 int slotId = getSlotIndex(subId);
3695 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3696 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3697 + subId + "' for key:" + key);
3698 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3699 }
3700 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003701 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003702 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3703 + subId + "' for key:" + key);
3704 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003705 } finally {
3706 Binder.restoreCallingIdentity(identity);
3707 }
3708 }
3709
3710 @Override
3711 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003712 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3713 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3714 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3716 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003720 int slotId = getSlotIndex(subId);
3721 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3722 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3723 + subId + "' for key:" + key);
3724 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3725 }
3726 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003727 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003728 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3729 + "' for key:" + key);
3730 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003731 } finally {
3732 Binder.restoreCallingIdentity(identity);
3733 }
3734 }
3735
3736 @Override
3737 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003738 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3739 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3740 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3742 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003746 int slotId = getSlotIndex(subId);
3747 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3748 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3749 + subId + "' for key:" + key);
3750 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3751 }
3752 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003753 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003754 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3755 + "' for key:" + key);
3756 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003757 } finally {
3758 Binder.restoreCallingIdentity(identity);
3759 }
3760 }
3761
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003762 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003763 int slotId = SubscriptionManager.getSlotIndex(subId);
3764 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003765 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3766 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003767 }
3768 return slotId;
3769 }
3770
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003771 private int getSlotIndex(int subId) {
3772 int slotId = SubscriptionManager.getSlotIndex(subId);
3773 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3774 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3775 }
3776 return slotId;
3777 }
3778
Wink Saville36469e72014-06-11 15:17:00 -07003779 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003780 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003781 */
3782 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003783 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003784 final int targetSdk = getTargetSdk(callingPackage);
3785 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3786 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3787 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003788 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3789 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003790 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3791 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003792
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793 final long identity = Binder.clearCallingIdentity();
3794 try {
3795 final Phone phone = getPhone(subId);
3796 if (phone != null) {
3797 return phone.getServiceState().getDataNetworkType();
3798 } else {
3799 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3800 }
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003803 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003804 }
3805
3806 /**
3807 * Returns the data network type
3808 */
3809 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003810 public int getDataNetworkType(String callingPackage) {
3811 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003812 }
3813
3814 /**
3815 * Returns the data network type for a subId
3816 */
3817 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003818 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003819 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003820 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003821 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3822 }
3823
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003824 final long identity = Binder.clearCallingIdentity();
3825 try {
3826 final Phone phone = getPhone(subId);
3827 if (phone != null) {
3828 return phone.getServiceState().getDataNetworkType();
3829 } else {
3830 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3831 }
3832 } finally {
3833 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003834 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003835 }
3836
3837 /**
Wink Saville36469e72014-06-11 15:17:00 -07003838 * Returns the Voice network type for a subId
3839 */
3840 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003841 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003842 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003843 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003844 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3845 }
3846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003847 final long identity = Binder.clearCallingIdentity();
3848 try {
3849 final Phone phone = getPhone(subId);
3850 if (phone != null) {
3851 return phone.getServiceState().getVoiceNetworkType();
3852 } else {
3853 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3854 }
3855 } finally {
3856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003858 }
3859
3860 /**
3861 * @return true if a ICC card is present
3862 */
3863 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003864 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003865 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3866 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003867 }
3868
3869 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003870 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003871 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003872 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003873 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003874 final long identity = Binder.clearCallingIdentity();
3875 try {
3876 final Phone phone = PhoneFactory.getPhone(slotIndex);
3877 if (phone != null) {
3878 return phone.getIccCard().hasIccCard();
3879 } else {
3880 return false;
3881 }
3882 } finally {
3883 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003885 }
3886
3887 /**
3888 * Return if the current radio is LTE on CDMA. This
3889 * is a tri-state return value as for a period of time
3890 * the mode may be unknown.
3891 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003892 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003893 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003894 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003895 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003896 @Override
3897 public int getLteOnCdmaMode(String callingPackage) {
3898 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003899 }
3900
Sanket Padawe356d7632015-06-22 14:03:32 -07003901 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003902 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003904 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003905 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3906 }
3907
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908 final long identity = Binder.clearCallingIdentity();
3909 try {
3910 final Phone phone = getPhone(subId);
3911 if (phone == null) {
3912 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3913 } else {
3914 return phone.getLteOnCdmaMode();
3915 }
3916 } finally {
3917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003918 }
Wink Saville36469e72014-06-11 15:17:00 -07003919 }
3920
Wink Saville36469e72014-06-11 15:17:00 -07003921 /**
3922 * {@hide}
3923 * Returns Default subId, 0 in the case of single standby.
3924 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003925 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003926 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003927 }
3928
Shishir Agrawala9f32182016-04-12 12:00:16 -07003929 private int getSlotForDefaultSubscription() {
3930 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3931 }
3932
Wink Savilleb564aae2014-10-23 10:18:09 -07003933 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003934 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003935 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003936
Pengquan Menge92a50d2018-09-21 15:54:48 -07003937 private boolean isActiveSubscription(int subId) {
3938 return mSubscriptionController.isActiveSubId(subId);
3939 }
3940
Ihab Awadf2177b72013-11-25 13:33:23 -08003941 /**
3942 * @see android.telephony.TelephonyManager.WifiCallingChoices
3943 */
3944 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003945 final long identity = Binder.clearCallingIdentity();
3946 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003947 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003948 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3949 getWhenToMakeWifiCallsDefaultPreference());
3950 } finally {
3951 Binder.restoreCallingIdentity(identity);
3952 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003953 }
3954
3955 /**
3956 * @see android.telephony.TelephonyManager.WifiCallingChoices
3957 */
3958 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003959 final long identity = Binder.clearCallingIdentity();
3960 try {
3961 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003962 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003963 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
3966 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003967 }
3968
Sailesh Nepald1e68152013-12-12 19:08:02 -08003969 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003970 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003971 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003972 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003973
Jordan Liu4c733742019-02-28 12:03:40 -08003974 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3975 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3976 if (phoneId == -1) {
3977 throw new IllegalArgumentException("Given slot index: " + slotIndex
3978 + " does not correspond to an active phone");
3979 }
3980 return PhoneFactory.getPhone(phoneId);
3981 }
3982
Shishir Agrawal566b7612013-10-28 14:41:00 -07003983 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003984 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3985 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3987 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003988 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003989 if (DBG) {
3990 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3991 }
3992 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3993 p2);
3994 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003995
Jordan Liu4c733742019-02-28 12:03:40 -08003996
3997 @Override
3998 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3999 int slotIndex, String callingPackage, String aid, int p2) {
4000 enforceModifyPermission();
4001 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4002 if (DBG) {
4003 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4004 }
4005 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4006 callingPackage, aid, p2);
4007 }
4008
4009 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4010 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004011 final long identity = Binder.clearCallingIdentity();
4012 try {
4013 if (TextUtils.equals(ISDR_AID, aid)) {
4014 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004015 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4016 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 if (bestComponent == null
4018 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4019 loge("The calling package is not allowed to access ISD-R.");
4020 throw new SecurityException(
4021 "The calling package is not allowed to access ISD-R.");
4022 }
Derek Tan740e1672017-06-27 14:56:27 -07004023 }
Derek Tan740e1672017-06-27 14:56:27 -07004024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004025 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004026 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4027 null /* workSource */);
4028 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004029 return response;
4030 } finally {
4031 Binder.restoreCallingIdentity(identity);
4032 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004033 }
4034
4035 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004036 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4038 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004039 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4040 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4041 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004042
Jordan Liu4c733742019-02-28 12:03:40 -08004043 @Override
4044 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4045 enforceModifyPermission();
4046 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4047 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4048 channel);
4049 }
4050
4051 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 final long identity = Binder.clearCallingIdentity();
4053 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004054 if (channel < 0) {
4055 return false;
4056 }
Jordan Liu4c733742019-02-28 12:03:40 -08004057 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4058 null /* workSource */);
4059 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004060 return success;
4061 } finally {
4062 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004063 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004064 }
4065
4066 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004067 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004068 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4070 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004071 if (DBG) {
4072 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4073 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4074 + p3 + " data=" + data);
4075 }
4076 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4077 command, p1, p2, p3, data);
4078 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004079
Jordan Liu4c733742019-02-28 12:03:40 -08004080 @Override
4081 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4082 int command, int p1, int p2, int p3, String data) {
4083 enforceModifyPermission();
4084 if (DBG) {
4085 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4086 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4087 + p3 + " data=" + data);
4088 }
4089 return iccTransmitApduLogicalChannelWithPermission(
4090 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4091 data);
4092 }
4093
4094 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4095 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096 final long identity = Binder.clearCallingIdentity();
4097 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004098 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004099 return "";
4100 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004102 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004103 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4104 null /* workSource */);
4105 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004107 // Append the returned status code to the end of the response payload.
4108 String s = Integer.toHexString(
4109 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4110 if (response.payload != null) {
4111 s = IccUtils.bytesToHexString(response.payload) + s;
4112 }
4113 return s;
4114 } finally {
4115 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004116 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004117 }
Jake Hambye994d462014-02-03 13:10:13 -08004118
Evan Charltonc66da362014-05-16 14:06:40 -07004119 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004120 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4121 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4123 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004125 if (DBG) {
4126 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4127 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4128 }
4129 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4130 cla, command, p1, p2, p3, data);
4131 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004132
Jordan Liu4c733742019-02-28 12:03:40 -08004133 @Override
4134 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4135 int command, int p1, int p2, int p3, String data) {
4136 enforceModifyPermission();
4137 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4138 if (DBG) {
4139 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4140 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4141 + " data=" + data);
4142 }
4143
4144 return iccTransmitApduBasicChannelWithPermission(
4145 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4146 p2, p3, data);
4147 }
4148
4149 // open APDU basic channel assuming the caller has sufficient permissions
4150 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4151 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4155 && TextUtils.equals(ISDR_AID, data)) {
4156 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004157 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4158 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004159 if (bestComponent == null
4160 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4161 loge("The calling package is not allowed to select ISD-R.");
4162 throw new SecurityException(
4163 "The calling package is not allowed to select ISD-R.");
4164 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004165 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004166
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004167 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004168 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4169 null /* workSource */);
4170 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004172 // Append the returned status code to the end of the response payload.
4173 String s = Integer.toHexString(
4174 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4175 if (response.payload != null) {
4176 s = IccUtils.bytesToHexString(response.payload) + s;
4177 }
4178 return s;
4179 } finally {
4180 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004181 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004182 }
4183
4184 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004185 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004186 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4188 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004190 final long identity = Binder.clearCallingIdentity();
4191 try {
4192 if (DBG) {
4193 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4194 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4195 }
4196
4197 IccIoResult response =
4198 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4199 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4200 subId);
4201
4202 if (DBG) {
4203 log("Exchange SIM_IO [R]" + response);
4204 }
4205
4206 byte[] result = null;
4207 int length = 2;
4208 if (response.payload != null) {
4209 length = 2 + response.payload.length;
4210 result = new byte[length];
4211 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4212 } else {
4213 result = new byte[length];
4214 }
4215
4216 result[length - 1] = (byte) response.sw2;
4217 result[length - 2] = (byte) response.sw1;
4218 return result;
4219 } finally {
4220 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004221 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004222 }
4223
Nathan Haroldb3014052017-01-25 15:57:32 -08004224 /**
4225 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4226 * on a particular subscription
4227 */
sqianb6e41952018-03-12 14:54:01 -07004228 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4230 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4231 return null;
4232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004233
4234 final long identity = Binder.clearCallingIdentity();
4235 try {
4236 if (appType != TelephonyManager.APPTYPE_USIM
4237 && appType != TelephonyManager.APPTYPE_SIM) {
4238 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4239 return null;
4240 }
4241 Object response = sendRequest(
4242 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4243 if (response instanceof String[]) {
4244 return (String[]) response;
4245 }
yincheng zhaod698b842019-09-06 17:06:54 -07004246 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004247 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004248 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004249 } finally {
4250 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004251 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004252 }
4253
yincheng zhaod698b842019-09-06 17:06:54 -07004254 /**
4255 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4256 * subscription.
4257 *
4258 * @param subId the id of the subscription.
4259 * @param appType the uicc app type, must be USIM or SIM.
4260 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4261 * @param callingPackage the op Package name.
4262 * @return number of fplmns that is successfully written to the SIM.
4263 */
4264 public int setForbiddenPlmns(
4265 int subId, int appType, List<String> fplmns, String callingPackage) {
4266 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4267 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4268 if (DBG) logv("no permissions for setForbiddenplmns");
4269 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4270 }
4271 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4272 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4273 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4274 }
4275 if (fplmns == null) {
4276 throw new IllegalArgumentException("Fplmn List provided is null");
4277 }
4278 for (String fplmn : fplmns) {
4279 if (!CellIdentity.isValidPlmn(fplmn)) {
4280 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4281 }
4282 }
4283 final long identity = Binder.clearCallingIdentity();
4284 try {
4285 Object response = sendRequest(
4286 CMD_SET_FORBIDDEN_PLMNS,
4287 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4288 subId);
4289 return (int) response;
4290 } finally {
4291 Binder.restoreCallingIdentity(identity);
4292 }
4293 }
4294
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004295 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004296 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4298 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004300 final long identity = Binder.clearCallingIdentity();
4301 try {
4302 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4303 if (response.payload == null) {
4304 return "";
4305 }
Evan Charltonc66da362014-05-16 14:06:40 -07004306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307 // Append the returned status code to the end of the response payload.
4308 String s = Integer.toHexString(
4309 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4310 s = IccUtils.bytesToHexString(response.payload) + s;
4311 return s;
4312 } finally {
4313 Binder.restoreCallingIdentity(identity);
4314 }
Evan Charltonc66da362014-05-16 14:06:40 -07004315 }
4316
Jake Hambye994d462014-02-03 13:10:13 -08004317 /**
4318 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4319 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4320 *
4321 * @param itemID the ID of the item to read
4322 * @return the NV item as a String, or null on error.
4323 */
4324 @Override
4325 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004326 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4328 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004329
4330 final long identity = Binder.clearCallingIdentity();
4331 try {
4332 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004333 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4335 return value;
4336 } finally {
4337 Binder.restoreCallingIdentity(identity);
4338 }
Jake Hambye994d462014-02-03 13:10:13 -08004339 }
4340
4341 /**
4342 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4343 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4344 *
4345 * @param itemID the ID of the item to read
4346 * @param itemValue the value to write, as a String
4347 * @return true on success; false on any failure
4348 */
4349 @Override
4350 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004351 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4353 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004354
4355 final long identity = Binder.clearCallingIdentity();
4356 try {
4357 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4358 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004359 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004360 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4361 return success;
4362 } finally {
4363 Binder.restoreCallingIdentity(identity);
4364 }
Jake Hambye994d462014-02-03 13:10:13 -08004365 }
4366
4367 /**
4368 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4369 * Used for device configuration by some CDMA operators.
4370 *
4371 * @param preferredRoamingList byte array containing the new PRL
4372 * @return true on success; false on any failure
4373 */
4374 @Override
4375 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4377 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004378
4379 final long identity = Binder.clearCallingIdentity();
4380 try {
4381 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4382 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4383 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4384 return success;
4385 } finally {
4386 Binder.restoreCallingIdentity(identity);
4387 }
Jake Hambye994d462014-02-03 13:10:13 -08004388 }
4389
4390 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004391 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004392 * Used for device configuration by some CDMA operators.
4393 *
chen xu6dac5ab2018-10-26 17:39:23 -07004394 * @param slotIndex - device slot.
4395 *
Jake Hambye994d462014-02-03 13:10:13 -08004396 * @return true on success; false on any failure
4397 */
4398 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004399 public boolean resetModemConfig(int slotIndex) {
4400 Phone phone = PhoneFactory.getPhone(slotIndex);
4401 if (phone != null) {
4402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4403 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404
chen xu6dac5ab2018-10-26 17:39:23 -07004405 final long identity = Binder.clearCallingIdentity();
4406 try {
4407 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4408 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4409 return success;
4410 } finally {
4411 Binder.restoreCallingIdentity(identity);
4412 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004413 }
chen xu6dac5ab2018-10-26 17:39:23 -07004414 return false;
4415 }
4416
4417 /**
4418 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4419 *
4420 * @param slotIndex - device slot.
4421 *
4422 * @return true on success; false on any failure
4423 */
4424 @Override
4425 public boolean rebootModem(int slotIndex) {
4426 Phone phone = PhoneFactory.getPhone(slotIndex);
4427 if (phone != null) {
4428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4429 mApp, phone.getSubId(), "rebootModem");
4430
4431 final long identity = Binder.clearCallingIdentity();
4432 try {
4433 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4434 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4435 return success;
4436 } finally {
4437 Binder.restoreCallingIdentity(identity);
4438 }
4439 }
4440 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004441 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004442
Svet Ganovb320e182015-04-16 12:30:10 -07004443 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004444 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004446 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004447 return new String[0];
4448 }
4449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450 final long identity = Binder.clearCallingIdentity();
4451 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004452 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004453 } finally {
4454 Binder.restoreCallingIdentity(identity);
4455 }
Wink Saville36469e72014-06-11 15:17:00 -07004456 }
4457
Brad Ebinger51f743a2017-01-23 13:50:20 -08004458 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004459 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4460 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004461 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004462 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004463 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004464
4465 final long identity = Binder.clearCallingIdentity();
4466 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004467 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004468 // may happen if the device does not support IMS.
4469 return;
4470 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004471 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 } finally {
4473 Binder.restoreCallingIdentity(identity);
4474 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004475 }
4476
4477 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004478 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4479 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004480 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004481 public void disableIms(int slotId) {
4482 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004483
4484 final long identity = Binder.clearCallingIdentity();
4485 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004486 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004487 // may happen if the device does not support IMS.
4488 return;
4489 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004490 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491 } finally {
4492 Binder.restoreCallingIdentity(identity);
4493 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004494 }
4495
4496 /**
4497 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4498 * feature or {@link null} if the service is not available. If the feature is available, the
4499 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4500 */
4501 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004502 IImsServiceFeatureCallback callback) {
4503 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004504
4505 final long identity = Binder.clearCallingIdentity();
4506 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004507 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004508 // may happen if the device does not support IMS.
4509 return null;
4510 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004511 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004512 } finally {
4513 Binder.restoreCallingIdentity(identity);
4514 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004515 }
4516
4517 /**
4518 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4519 * feature during emergency calling or {@link null} if the service is not available. If the
4520 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4521 * listener for feature updates.
4522 */
4523 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4524 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004525
4526 final long identity = Binder.clearCallingIdentity();
4527 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004528 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004529 // may happen if the device does not support IMS.
4530 return null;
4531 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004532 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533 } finally {
4534 Binder.restoreCallingIdentity(identity);
4535 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004536 }
4537
Brad Ebinger5f64b052017-12-14 14:26:15 -08004538 /**
4539 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004540 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004541 */
4542 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4543 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004544
4545 final long identity = Binder.clearCallingIdentity();
4546 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004547 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004548 // may happen if the device does not support IMS.
4549 return null;
4550 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004551 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004552 } finally {
4553 Binder.restoreCallingIdentity(identity);
4554 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004555 }
4556
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004557 /**
4558 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004559 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004560 */
4561 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4562 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004563
4564 final long identity = Binder.clearCallingIdentity();
4565 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004566 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004567 // may happen if the device does not support IMS.
4568 return null;
4569 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004570 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 } finally {
4572 Binder.restoreCallingIdentity(identity);
4573 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004574 }
4575
Brad Ebinger884c07b2018-02-15 16:17:40 -08004576 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004577 * Sets the ImsService Package Name that Telephony will bind to.
4578 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004579 * @param slotIndex the slot ID that the ImsService should bind for.
4580 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004581 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004582 * @param featureTypes An integer array of feature types associated with a packageName.
4583 * @param packageName The name of the package that the current configuration will be replaced
4584 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004585 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004586 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004587 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4588 int[] featureTypes, String packageName) {
4589 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4590 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4592 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004593 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 final long identity = Binder.clearCallingIdentity();
4596 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004597 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004598 // may happen if the device does not support IMS.
4599 return false;
4600 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004601 Map<Integer, String> featureConfig = new HashMap<>();
4602 for (int featureType : featureTypes) {
4603 featureConfig.put(featureType, packageName);
4604 }
4605 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4606 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004607 } finally {
4608 Binder.restoreCallingIdentity(identity);
4609 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004610 }
4611
4612 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08004613 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004614 *
4615 * @param slotId The slot that the ImsService is associated with.
4616 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4617 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004618 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004619 * @return the package name of the ImsService configuration.
4620 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004621 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4622 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004623 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08004624 TelephonyPermissions
4625 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4626 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4627 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629 final long identity = Binder.clearCallingIdentity();
4630 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004631 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004632 // may happen if the device does not support IMS.
4633 return "";
4634 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004635 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004636 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4637 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004638 } finally {
4639 Binder.restoreCallingIdentity(identity);
4640 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004641 }
4642
Brad Ebinger77b832e2019-10-17 17:03:22 -07004643 /**
4644 * Get the MmTelFeature state associated with the requested subscription id.
4645 * @param subId The subscription that the MmTelFeature is associated with.
4646 * @param callback A callback with an integer containing the
4647 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4648 */
4649 @Override
4650 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4651 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4652 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4653 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4654 "IMS not available on device.");
4655 }
4656 final long token = Binder.clearCallingIdentity();
4657 try {
4658 int slotId = getSlotIndex(subId);
4659 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4660 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4661 + subId + "'");
4662 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4663 }
4664 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4665 try {
4666 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4667 } catch (RemoteException e) {
4668 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4669 + "Ignore");
4670 }
4671 });
4672 } finally {
4673 Binder.restoreCallingIdentity(token);
4674 }
4675 }
4676
Wink Saville36469e72014-06-11 15:17:00 -07004677 public void setImsRegistrationState(boolean registered) {
4678 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004679
4680 final long identity = Binder.clearCallingIdentity();
4681 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004682 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683 } finally {
4684 Binder.restoreCallingIdentity(identity);
4685 }
Wink Saville36469e72014-06-11 15:17:00 -07004686 }
4687
4688 /**
Stuart Scott54788802015-03-30 13:18:01 -07004689 * Set the network selection mode to automatic.
4690 *
4691 */
4692 @Override
4693 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4695 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004696
Pengquan Menge92a50d2018-09-21 15:54:48 -07004697 if (!isActiveSubscription(subId)) {
4698 return;
4699 }
4700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004701 final long identity = Binder.clearCallingIdentity();
4702 try {
4703 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4704 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4705 } finally {
4706 Binder.restoreCallingIdentity(identity);
4707 }
Stuart Scott54788802015-03-30 13:18:01 -07004708 }
4709
Pengquan Mengea84e042018-09-20 14:57:26 -07004710 /**
4711 * Ask the radio to connect to the input network and change selection mode to manual.
4712 *
4713 * @param subId the id of the subscription.
4714 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4715 * the operator to attach to.
4716 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4717 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4718 * normal network selection next time.
4719 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004720 */
4721 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004722 public boolean setNetworkSelectionModeManual(
4723 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4725 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004726
4727 if (!isActiveSubscription(subId)) {
4728 return false;
4729 }
4730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731 final long identity = Binder.clearCallingIdentity();
4732 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004733 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004734 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004735 if (DBG) {
4736 log("setNetworkSelectionModeManual: subId: " + subId
4737 + " operator: " + operatorInfo);
4738 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004739 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4740 } finally {
4741 Binder.restoreCallingIdentity(identity);
4742 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004743 }
4744
4745 /**
4746 * Scans for available networks.
4747 */
4748 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004749 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4751 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004752 LocationAccessPolicy.LocationPermissionResult locationResult =
4753 LocationAccessPolicy.checkLocationPermission(mApp,
4754 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4755 .setCallingPackage(callingPackage)
4756 .setCallingPid(Binder.getCallingPid())
4757 .setCallingUid(Binder.getCallingUid())
4758 .setMethod("getCellNetworkScanResults")
4759 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4760 .build());
4761 switch (locationResult) {
4762 case DENIED_HARD:
4763 throw new SecurityException("Not allowed to access scan results -- location");
4764 case DENIED_SOFT:
4765 return null;
4766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004767
Pengquan Menga1bb6272018-09-06 09:59:22 -07004768 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769 try {
4770 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004771 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004772 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773 } finally {
4774 Binder.restoreCallingIdentity(identity);
4775 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004776 }
4777
4778 /**
yinxub1bed742017-04-17 11:45:04 -07004779 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004780 *
yinxub1bed742017-04-17 11:45:04 -07004781 * @param subId id of the subscription
4782 * @param request contains the radio access networks with bands/channels to scan
4783 * @param messenger callback messenger for scan results or errors
4784 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004785 * @return the id of the requested scan which can be used to stop the scan.
4786 */
4787 @Override
4788 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004789 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4791 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004792 LocationAccessPolicy.LocationPermissionResult locationResult =
4793 LocationAccessPolicy.checkLocationPermission(mApp,
4794 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4795 .setCallingPackage(callingPackage)
4796 .setCallingPid(Binder.getCallingPid())
4797 .setCallingUid(Binder.getCallingUid())
4798 .setMethod("requestNetworkScan")
4799 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4800 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004801 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004802 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004803 if (e != null) {
4804 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4805 throw e;
4806 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004807 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004808 return TelephonyScanManager.INVALID_SCAN_ID;
4809 }
4810 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004811 }
Hall Liu912dfd32019-04-25 14:02:26 -07004812 int callingUid = Binder.getCallingUid();
4813 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004814 final long identity = Binder.clearCallingIdentity();
4815 try {
4816 return mNetworkScanRequestTracker.startNetworkScan(
4817 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004818 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004819 } finally {
4820 Binder.restoreCallingIdentity(identity);
4821 }
yinxu504e1392017-04-12 16:03:22 -07004822 }
4823
Hall Liub2ac8ef2019-02-28 15:56:23 -08004824 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004825 NetworkScanRequest request, int subId) {
4826 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4827 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4828 boolean hasNetworkScanPermission =
4829 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4830 == PERMISSION_GRANTED;
4831
4832 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4833 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4834 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004835 }
4836
4837 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4838 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004839 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4840 return new SecurityException("Specific channels must not be"
4841 + " scanned without location access.");
4842 }
4843 }
4844 }
4845
Hall Liub2ac8ef2019-02-28 15:56:23 -08004846 return null;
4847 }
4848
yinxu504e1392017-04-12 16:03:22 -07004849 /**
4850 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004851 *
4852 * @param subId id of the subscription
4853 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004854 */
4855 @Override
4856 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4858 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859
Hall Liu912dfd32019-04-25 14:02:26 -07004860 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004861 final long identity = Binder.clearCallingIdentity();
4862 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004863 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004864 } finally {
4865 Binder.restoreCallingIdentity(identity);
4866 }
yinxu504e1392017-04-12 16:03:22 -07004867 }
4868
4869 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004870 * Get the calculated preferred network type.
4871 * Used for debugging incorrect network type.
4872 *
4873 * @return the preferred network type, defined in RILConstants.java.
4874 */
4875 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004876 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004877 final Phone defaultPhone = getDefaultPhone();
4878 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4879 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004880 return RILConstants.PREFERRED_NETWORK_MODE;
4881 }
4882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004883 final long identity = Binder.clearCallingIdentity();
4884 try {
4885 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004886 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004887 } finally {
4888 Binder.restoreCallingIdentity(identity);
4889 }
Junda Liu84d15a22014-07-02 11:21:04 -07004890 }
4891
4892 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004893 * Get the preferred network type.
4894 * Used for device configuration by some CDMA operators.
4895 *
4896 * @return the preferred network type, defined in RILConstants.java.
4897 */
4898 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004899 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004900 TelephonyPermissions
4901 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4902 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903
4904 final long identity = Binder.clearCallingIdentity();
4905 try {
4906 if (DBG) log("getPreferredNetworkType");
4907 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4908 int networkType = (result != null ? result[0] : -1);
4909 if (DBG) log("getPreferredNetworkType: " + networkType);
4910 return networkType;
4911 } finally {
4912 Binder.restoreCallingIdentity(identity);
4913 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004914 }
4915
4916 /**
4917 * Set the preferred network type.
4918 * Used for device configuration by some CDMA operators.
4919 *
4920 * @param networkType the preferred network type, defined in RILConstants.java.
4921 * @return true on success; false on any failure.
4922 */
4923 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004924 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4926 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004927
4928 final long identity = Binder.clearCallingIdentity();
4929 try {
4930 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4931 Boolean success = (Boolean) sendRequest(
4932 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4933 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4934 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004935 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4937 }
4938 return success;
4939 } finally {
4940 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004941 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004942 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004943
4944 /**
Miaoa84611c2019-03-15 09:21:10 +08004945 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004946 *
Miaoa84611c2019-03-15 09:21:10 +08004947 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004948 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004949 * @hide
4950 */
4951 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004952 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004953 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004955 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004956 try {
Miaoa84611c2019-03-15 09:21:10 +08004957 if (phone != null) {
4958 return phone.hasMatchedTetherApnSetting();
4959 } else {
4960 return false;
4961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962 } finally {
4963 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004964 }
Junda Liu475951f2014-11-07 16:45:03 -08004965 }
4966
4967 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004968 * Set mobile data enabled
4969 * Used by the user through settings etc to turn on/off mobile data
4970 *
4971 * @param enable {@code true} turn turn data on, else {@code false}
4972 */
4973 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004974 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4976 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977
4978 final long identity = Binder.clearCallingIdentity();
4979 try {
4980 int phoneId = mSubscriptionController.getPhoneId(subId);
4981 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4982 Phone phone = PhoneFactory.getPhone(phoneId);
4983 if (phone != null) {
4984 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004985 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004987 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988 }
4989 } finally {
4990 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004991 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004992 }
4993
4994 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004995 * Get the user enabled state of Mobile Data.
4996 *
4997 * TODO: remove and use isUserDataEnabled.
4998 * This can't be removed now because some vendor codes
4999 * calls through ITelephony directly while they should
5000 * use TelephonyManager.
5001 *
5002 * @return true on enabled
5003 */
5004 @Override
5005 public boolean getDataEnabled(int subId) {
5006 return isUserDataEnabled(subId);
5007 }
5008
5009 /**
5010 * Get whether mobile data is enabled per user setting.
5011 *
5012 * There are other factors deciding whether mobile data is actually enabled, but they are
5013 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005014 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005015 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005016 *
5017 * @return {@code true} if data is enabled else {@code false}
5018 */
5019 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005020 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005021 try {
5022 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5023 null);
5024 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5026 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005027 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028
5029 final long identity = Binder.clearCallingIdentity();
5030 try {
5031 int phoneId = mSubscriptionController.getPhoneId(subId);
5032 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5033 Phone phone = PhoneFactory.getPhone(phoneId);
5034 if (phone != null) {
5035 boolean retVal = phone.isUserDataEnabled();
5036 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5037 return retVal;
5038 } else {
5039 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5040 return false;
5041 }
5042 } finally {
5043 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005044 }
5045 }
5046
5047 /**
5048 * Get whether mobile data is enabled.
5049 *
5050 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5051 * whether mobile data is actually enabled.
5052 *
5053 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5054 *
5055 * @return {@code true} if data is enabled else {@code false}
5056 */
5057 @Override
5058 public boolean isDataEnabled(int subId) {
5059 try {
5060 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5061 null);
5062 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5064 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005065 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066
5067 final long identity = Binder.clearCallingIdentity();
5068 try {
5069 int phoneId = mSubscriptionController.getPhoneId(subId);
5070 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5071 Phone phone = PhoneFactory.getPhone(phoneId);
5072 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005073 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5075 return retVal;
5076 } else {
5077 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5078 return false;
5079 }
5080 } finally {
5081 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005082 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005083 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005084
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005085 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5086 Phone phone) {
5087 //load access rules from carrier configs, and check those as well: b/139133814
5088 SubscriptionController subController = SubscriptionController.getInstance();
5089 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5090 || subController == null) return privilegeFromSim;
5091
5092 int uid = Binder.getCallingUid();
5093 PackageManager pkgMgr = phone.getContext().getPackageManager();
5094 String[] packages = pkgMgr.getPackagesForUid(uid);
5095
5096 final long identity = Binder.clearCallingIdentity();
5097 try {
5098 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5099 SubscriptionManager subManager = (SubscriptionManager)
5100 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5101 for (String pkg : packages) {
5102 if (subManager.canManageSubscription(subInfo, pkg)) {
5103 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5104 }
5105 }
5106 return privilegeFromSim;
5107 } finally {
5108 Binder.restoreCallingIdentity(identity);
5109 }
5110 }
5111
5112 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5113 String pkgName) {
5114 //load access rules from carrier configs, and check those as well: b/139133814
5115 SubscriptionController subController = SubscriptionController.getInstance();
5116 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5117 || subController == null) return privilegeFromSim;
5118
5119 final long identity = Binder.clearCallingIdentity();
5120 try {
5121 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5122 SubscriptionManager subManager = (SubscriptionManager)
5123 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5124 return subManager.canManageSubscription(subInfo, pkgName)
5125 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5126 } finally {
5127 Binder.restoreCallingIdentity(identity);
5128 }
5129 }
5130
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005131 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005132 public int getCarrierPrivilegeStatus(int subId) {
5133 final Phone phone = getPhone(subId);
5134 if (phone == null) {
5135 loge("getCarrierPrivilegeStatus: Invalid subId");
5136 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5137 }
5138 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005139 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005140 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005141 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5142 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005143
5144 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5145 card.getCarrierPrivilegeStatusForCurrentTransaction(
5146 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005147 }
Junda Liu29340342014-07-10 15:23:27 -07005148
5149 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005150 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5151 final Phone phone = getPhone(subId);
5152 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005153 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005154 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5155 }
5156 UiccProfile profile =
5157 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5158 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005159 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005160 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5161 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005162 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5163 profile.getCarrierPrivilegeStatusForUid(
5164 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005165 }
5166
5167 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005168 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5169 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005170 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005171 }
5172
5173 int phoneId = SubscriptionManager.getPhoneId(subId);
5174 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005175 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005176 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005177 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5178 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005179 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5180 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5181 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005182 }
5183
5184 @Override
5185 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005186 if (TextUtils.isEmpty(pkgName))
5187 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005188 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5189 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5190 UiccCard card = UiccController.getInstance().getUiccCard(i);
5191 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005192 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005193 continue;
5194 }
5195
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005196 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5197 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5198 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005199 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5200 break;
5201 }
5202 }
5203
5204 return result;
Junda Liu29340342014-07-10 15:23:27 -07005205 }
Derek Tan89e89d42014-07-08 17:00:10 -07005206
5207 @Override
Junda Liue64de782015-04-16 17:19:16 -07005208 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5209 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5210 loge("phoneId " + phoneId + " is not valid.");
5211 return null;
5212 }
5213 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005214 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005215 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005216 return null ;
5217 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005218 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005219 }
5220
Amith Yamasani6e118872016-02-19 12:53:51 -08005221 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005222 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005223 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005224 List<String> privilegedPackages = new ArrayList<>();
5225 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005226 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5227 // has UICC in that slot.
5228 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005229 if (card.hasCarrierPrivilegeRules()) {
5230 if (packages == null) {
5231 // Only check packages in user 0 for now
5232 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005233 PackageManager.MATCH_DISABLED_COMPONENTS
5234 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005235 | PackageManager.GET_SIGNING_CERTIFICATES,
5236 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005237 }
5238 for (int p = packages.size() - 1; p >= 0; p--) {
5239 PackageInfo pkgInfo = packages.get(p);
5240 if (pkgInfo != null && pkgInfo.packageName != null
5241 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005242 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005243 privilegedPackages.add(pkgInfo.packageName);
5244 }
5245 }
5246 }
5247 }
5248 return privilegedPackages;
5249 }
5250
chen xuf7e9fe82019-05-09 19:31:02 -07005251 @Override
5252 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005253 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5254
5255 final long identity = Binder.clearCallingIdentity();
5256
chen xuf7e9fe82019-05-09 19:31:02 -07005257 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005258 try {
5259 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5260 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5261 }
5262 } finally {
5263 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005264 }
5265 return privilegedPackages;
5266 }
5267
Wink Savilleb564aae2014-10-23 10:18:09 -07005268 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005269 final Phone phone = getPhone(subId);
5270 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005271 if (card == null) {
5272 loge("getIccId: No UICC");
5273 return null;
5274 }
5275 String iccId = card.getIccId();
5276 if (TextUtils.isEmpty(iccId)) {
5277 loge("getIccId: ICC ID is null or empty.");
5278 return null;
5279 }
5280 return iccId;
5281 }
5282
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005283 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005284 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5285 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005286 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5287 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 final long identity = Binder.clearCallingIdentity();
5290 try {
5291 final String iccId = getIccId(subId);
5292 final Phone phone = getPhone(subId);
5293 if (phone == null) {
5294 return false;
5295 }
5296 final String subscriberId = phone.getSubscriberId();
5297
5298 if (DBG_MERGE) {
5299 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5300 + subscriberId + " to " + number);
5301 }
5302
5303 if (TextUtils.isEmpty(iccId)) {
5304 return false;
5305 }
5306
5307 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5308
5309 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5310 if (alphaTag == null) {
5311 editor.remove(alphaTagPrefKey);
5312 } else {
5313 editor.putString(alphaTagPrefKey, alphaTag);
5314 }
5315
5316 // Record both the line number and IMSI for this ICCID, since we need to
5317 // track all merged IMSIs based on line number
5318 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5319 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5320 if (number == null) {
5321 editor.remove(numberPrefKey);
5322 editor.remove(subscriberPrefKey);
5323 } else {
5324 editor.putString(numberPrefKey, number);
5325 editor.putString(subscriberPrefKey, subscriberId);
5326 }
5327
5328 editor.commit();
5329 return true;
5330 } finally {
5331 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005332 }
Derek Tan7226c842014-07-02 17:42:23 -07005333 }
5334
5335 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005336 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005337 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005338 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005339 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005340 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005341 return null;
5342 }
Derek Tan97ebb422014-09-05 16:55:38 -07005343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005344 final long identity = Binder.clearCallingIdentity();
5345 try {
5346 String iccId = getIccId(subId);
5347 if (iccId != null) {
5348 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5349 if (DBG_MERGE) {
5350 log("getLine1NumberForDisplay returning "
5351 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5352 }
5353 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005354 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5356 return null;
5357 } finally {
5358 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005359 }
Derek Tan7226c842014-07-02 17:42:23 -07005360 }
5361
5362 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005363 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005364 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005365 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005366 return null;
5367 }
Derek Tan97ebb422014-09-05 16:55:38 -07005368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 final long identity = Binder.clearCallingIdentity();
5370 try {
5371 String iccId = getIccId(subId);
5372 if (iccId != null) {
5373 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5374 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5375 }
5376 return null;
5377 } finally {
5378 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005379 }
Derek Tan7226c842014-07-02 17:42:23 -07005380 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005381
5382 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005383 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005384 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5385 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005387 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5388 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005389 return null;
5390 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005391
Jordan Liub49b04b2019-05-06 14:45:15 -07005392 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5393 // the process, where TelephonyManager was instantiated.
5394 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005395 final long identity = Binder.clearCallingIdentity();
5396 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005397 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 final TelephonyManager tele = TelephonyManager.from(context);
5399 final SubscriptionManager sub = SubscriptionManager.from(context);
5400
5401 // Figure out what subscribers are currently active
5402 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403
Jordan Liub49b04b2019-05-06 14:45:15 -07005404 // Only consider subs which match the current subId
5405 // This logic can be simplified. See b/131189269 for progress.
5406 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005407 activeSubscriberIds.add(tele.getSubscriberId(subId));
5408 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005409
5410 // First pass, find a number override for an active subscriber
5411 String mergeNumber = null;
5412 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5413 for (String key : prefs.keySet()) {
5414 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5415 final String subscriberId = (String) prefs.get(key);
5416 if (activeSubscriberIds.contains(subscriberId)) {
5417 final String iccId = key.substring(
5418 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5419 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5420 mergeNumber = (String) prefs.get(numberKey);
5421 if (DBG_MERGE) {
5422 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5423 + " for active subscriber " + subscriberId);
5424 }
5425 if (!TextUtils.isEmpty(mergeNumber)) {
5426 break;
5427 }
5428 }
5429 }
5430 }
5431
5432 // Shortcut when no active merged subscribers
5433 if (TextUtils.isEmpty(mergeNumber)) {
5434 return null;
5435 }
5436
5437 // Second pass, find all subscribers under that line override
5438 final ArraySet<String> result = new ArraySet<>();
5439 for (String key : prefs.keySet()) {
5440 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5441 final String number = (String) prefs.get(key);
5442 if (mergeNumber.equals(number)) {
5443 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5444 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5445 final String subscriberId = (String) prefs.get(subscriberKey);
5446 if (!TextUtils.isEmpty(subscriberId)) {
5447 result.add(subscriberId);
5448 }
5449 }
5450 }
5451 }
5452
5453 final String[] resultArray = result.toArray(new String[result.size()]);
5454 Arrays.sort(resultArray);
5455 if (DBG_MERGE) {
5456 Slog.d(LOG_TAG,
5457 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5458 }
5459 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005460 } finally {
5461 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005462 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005463 }
5464
5465 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005466 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5467 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5468
5469 final long identity = Binder.clearCallingIdentity();
5470 try {
5471 final TelephonyManager telephonyManager = mApp.getSystemService(
5472 TelephonyManager.class);
5473 String subscriberId = telephonyManager.getSubscriberId(subId);
5474 if (subscriberId == null) {
5475 if (DBG) {
5476 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5477 + subId);
5478 }
5479 return null;
5480 }
5481
5482 final SubscriptionInfo info = SubscriptionController.getInstance()
5483 .getSubscriptionInfo(subId);
5484 final ParcelUuid groupUuid = info.getGroupUuid();
5485 // If it doesn't belong to any group, return just subscriberId of itself.
5486 if (groupUuid == null) {
5487 return new String[]{subscriberId};
5488 }
5489
5490 // Get all subscriberIds from the group.
5491 final List<String> mergedSubscriberIds = new ArrayList<>();
5492 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5493 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5494 for (SubscriptionInfo subInfo : groupInfos) {
5495 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5496 if (subscriberId != null) {
5497 mergedSubscriberIds.add(subscriberId);
5498 }
5499 }
5500
5501 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5502 } finally {
5503 Binder.restoreCallingIdentity(identity);
5504
5505 }
5506 }
5507
5508 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005509 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005510 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5511 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512
5513 final long identity = Binder.clearCallingIdentity();
5514 try {
5515 final Phone phone = getPhone(subId);
5516 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5517 } finally {
5518 Binder.restoreCallingIdentity(identity);
5519 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005520 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005521
5522 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005523 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005524 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5525 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005526 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527
5528 final long identity = Binder.clearCallingIdentity();
5529 try {
5530 final Phone phone = getPhone(subId);
5531 if (phone == null) {
5532 return false;
5533 }
5534 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5535 cdmaNonRoamingList);
5536 } finally {
5537 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005538 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005539 }
5540
5541 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005542 @Deprecated
5543 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5544 enforceModifyPermission();
5545
5546 int returnValue = 0;
5547 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005548 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005549 if(result.exception == null) {
5550 if (result.result != null) {
5551 byte[] responseData = (byte[])(result.result);
5552 if(responseData.length > oemResp.length) {
5553 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5554 responseData.length + "bytes. Buffer Size is " +
5555 oemResp.length + "bytes.");
5556 }
5557 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5558 returnValue = responseData.length;
5559 }
5560 } else {
5561 CommandException ex = (CommandException) result.exception;
5562 returnValue = ex.getCommandError().ordinal();
5563 if(returnValue > 0) returnValue *= -1;
5564 }
5565 } catch (RuntimeException e) {
5566 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5567 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5568 if(returnValue > 0) returnValue *= -1;
5569 }
5570
5571 return returnValue;
5572 }
5573
5574 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005575 public void setRadioCapability(RadioAccessFamily[] rafs) {
5576 try {
5577 ProxyController.getInstance().setRadioCapability(rafs);
5578 } catch (RuntimeException e) {
5579 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5580 }
5581 }
5582
5583 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005584 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005585 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005586 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005587 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005588 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590 final long identity = Binder.clearCallingIdentity();
5591 try {
chen xub97461a2018-10-26 14:17:57 -07005592 TelephonyPermissions
5593 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5594 mApp, phone.getSubId(), "getRadioAccessFamily");
5595 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 } finally {
5597 Binder.restoreCallingIdentity(identity);
5598 }
chen xub97461a2018-10-26 14:17:57 -07005599 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005600 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005601
5602 @Override
5603 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005604 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005605 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606
5607 final long identity = Binder.clearCallingIdentity();
5608 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005609 ImsManager.getInstance(defaultPhone.getContext(),
5610 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 } finally {
5612 Binder.restoreCallingIdentity(identity);
5613 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005614 }
5615
5616 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005617 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005618 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005619 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005620 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005621 return false;
5622 }
Svet Ganovb320e182015-04-16 12:30:10 -07005623
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 final long identity = Binder.clearCallingIdentity();
5625 try {
5626 // Check the user preference and the system-level IMS setting. Even if the user has
5627 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5628 // In the long run, we may instead need to check if there exists a connection service
5629 // which can support video calling.
5630 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005631 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005632 return imsManager.isVtEnabledByPlatform()
5633 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5634 && imsManager.isVtEnabledByUser();
5635 } finally {
5636 Binder.restoreCallingIdentity(identity);
5637 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005638 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005639
Andrew Leea1239f22015-03-02 17:44:07 -08005640 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5642 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5643 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5644 return false;
5645 }
5646
5647 final long identity = Binder.clearCallingIdentity();
5648 try {
5649 CarrierConfigManager configManager =
5650 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005651 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005652 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5653 } finally {
5654 Binder.restoreCallingIdentity(identity);
5655 }
Andrew Leea1239f22015-03-02 17:44:07 -08005656 }
5657
5658 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659 public boolean isWorldPhone(int subId, String callingPackage) {
5660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5661 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5662 return false;
5663 }
5664
5665 final long identity = Binder.clearCallingIdentity();
5666 try {
5667 CarrierConfigManager configManager =
5668 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005669 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5671 } finally {
5672 Binder.restoreCallingIdentity(identity);
5673 }
Andrew Leea1239f22015-03-02 17:44:07 -08005674 }
5675
Andrew Lee9431b832015-03-09 18:46:45 -07005676 @Override
5677 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005678 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005679 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005680 }
5681
5682 @Override
5683 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 final long identity = Binder.clearCallingIdentity();
5685 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005686 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 } finally {
5688 Binder.restoreCallingIdentity(identity);
5689 }
Andrew Lee9431b832015-03-09 18:46:45 -07005690 }
5691
Hall Liuf6668912018-10-31 17:05:23 -07005692 /**
5693 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5694 * support for the feature and device firmware support.
5695 *
5696 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5697 */
5698 @Override
5699 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005701 final Phone phone = getPhone(subscriptionId);
5702 if (phone == null) {
5703 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5704 return false;
5705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005707 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5709 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005710 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711 return isCarrierSupported && isDeviceSupported;
5712 } finally {
5713 Binder.restoreCallingIdentity(identity);
5714 }
Hall Liu98187582018-01-22 19:15:32 -08005715 }
5716
Hall Liuf6668912018-10-31 17:05:23 -07005717 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005718 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5719 * RTT setting, will return true if the device and carrier both support RTT.
5720 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005721 */
5722 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 final long identity = Binder.clearCallingIdentity();
5724 try {
Hall Liu81eb08c2019-10-29 16:50:20 -07005725 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 } finally {
5727 Binder.restoreCallingIdentity(identity);
5728 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005729 }
5730
Sanket Padawe7310cc72015-01-14 09:53:20 -08005731 /**
5732 * Returns the unique device ID of phone, for example, the IMEI for
5733 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5734 *
5735 * <p>Requires Permission:
5736 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5737 */
5738 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005739 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005740 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005741 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005742 return null;
5743 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005744 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005745 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5746 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005747 return null;
5748 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005749
5750 final long identity = Binder.clearCallingIdentity();
5751 try {
5752 return phone.getDeviceId();
5753 } finally {
5754 Binder.restoreCallingIdentity(identity);
5755 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005756 }
5757
Ping Sunc67b7c22016-03-02 19:16:45 +08005758 /**
5759 * {@hide}
5760 * Returns the IMS Registration Status on a particular subid
5761 *
5762 * @param subId
5763 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005764 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005765 Phone phone = getPhone(subId);
5766 if (phone != null) {
5767 return phone.isImsRegistered();
5768 } else {
5769 return false;
5770 }
5771 }
5772
Santos Cordon7a1885b2015-02-03 11:15:19 -08005773 @Override
5774 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 final long identity = Binder.clearCallingIdentity();
5776 try {
5777 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5778 } finally {
5779 Binder.restoreCallingIdentity(identity);
5780 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005781 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005782
Tyler Gunnf70ed162019-04-03 15:28:53 -07005783 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005784 public int getSubIdForPhoneAccountHandle(
5785 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5786 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5787 callingPackage, "getSubIdForPhoneAccountHandle")) {
5788 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5789 }
5790 final long identity = Binder.clearCallingIdentity();
5791 try {
5792 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5793 } finally {
5794 Binder.restoreCallingIdentity(identity);
5795 }
5796 }
5797
5798 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005799 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5800 final long identity = Binder.clearCallingIdentity();
5801 try {
5802 Phone phone = getPhone(subscriptionId);
5803 if (phone == null) {
5804 return null;
5805 }
5806 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5807 } finally {
5808 Binder.restoreCallingIdentity(identity);
5809 }
5810 }
5811
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005812 /**
5813 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005814 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005815 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816 final long identity = Binder.clearCallingIdentity();
5817 try {
5818 Phone phone = getPhone(subId);
5819 if (phone != null) {
5820 return phone.isWifiCallingEnabled();
5821 } else {
5822 return false;
5823 }
5824 } finally {
5825 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005826 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005827 }
5828
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005829 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005830 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005831 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005832 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833 final long identity = Binder.clearCallingIdentity();
5834 try {
5835 Phone phone = getPhone(subId);
5836 if (phone != null) {
5837 return phone.isVideoEnabled();
5838 } else {
5839 return false;
5840 }
5841 } finally {
5842 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005843 }
5844 }
5845
5846 /**
5847 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5848 * defined in {@link ImsRegistrationImplBase}.
5849 */
5850 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851 final long identity = Binder.clearCallingIdentity();
5852 try {
5853 Phone phone = getPhone(subId);
5854 if (phone != null) {
5855 return phone.getImsRegistrationTech();
5856 } else {
5857 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5858 }
5859 } finally {
5860 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005861 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005862 }
5863
Stuart Scott8eef64f2015-04-08 15:13:54 -07005864 @Override
5865 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08005866 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005867 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5868 return;
5869 }
5870
Svet Ganovcc087f82015-05-12 20:35:54 -07005871 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005872
Svet Ganovcc087f82015-05-12 20:35:54 -07005873 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005874 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5875 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005876 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005877 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005878 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005879 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5880 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005881 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005882 // There has been issues when Sms raw table somehow stores orphan
5883 // fragments. They lead to garbled message when new fragments come
5884 // in and combined with those stale ones. In case this happens again,
5885 // user can reset all network settings which will clean up this table.
5886 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005887 // Clean up IMS settings as well here.
5888 int slotId = getSlotIndex(subId);
5889 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5890 ImsManager.getInstance(mApp, slotId).factoryReset();
5891 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07005892
5893 // Erase modem config if erase modem on network setting is enabled.
5894 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5895 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5896 if (configValue != null && Boolean.parseBoolean(configValue)) {
5897 sendEraseModemConfig(getDefaultPhone());
5898 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005899 } finally {
5900 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005901 }
5902 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005903
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005904 private void cleanUpSmsRawTable(Context context) {
5905 ContentResolver resolver = context.getContentResolver();
5906 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5907 resolver.delete(uri, null, null);
5908 }
5909
Narayan Kamath1c496c22015-04-16 14:40:19 +01005910 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005911 public String getSimLocaleForSubscriber(int subId) {
5912 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5913 final Phone phone = getPhone(subId);
5914 if (phone == null) {
5915 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005916 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005917 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 final long identity = Binder.clearCallingIdentity();
5919 try {
chen xu5d3637b2019-01-21 23:31:38 -08005920 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5921 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005922 if (info == null) {
5923 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5924 return null;
5925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926 // Try and fetch the locale from the carrier properties or from the SIM language
5927 // preferences (EF-PL and EF-LI)...
5928 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005930 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5931 if (localeFromDefaultSim != null) {
5932 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5933 if (DBG) log("Using locale from subId: " + subId + " locale: "
5934 + localeFromDefaultSim);
5935 return localeFromDefaultSim.toLanguageTag();
5936 } else {
5937 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005938 }
5939 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005940
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 // The SIM language preferences only store a language (e.g. fr = French), not an
5942 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5943 // the SIM and carrier preferences does not include a country we add the country
5944 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005945 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005947 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 return mccLocale.toLanguageTag();
5949 }
5950
5951 if (DBG) log("No locale found - returning null");
5952 return null;
5953 } finally {
5954 Binder.restoreCallingIdentity(identity);
5955 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005956 }
5957
5958 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005959 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005960 }
5961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 /**
5963 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5964 */
5965 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005966 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005967 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005968
Chenjie Yu1ba97252018-01-11 18:16:20 -08005969 private final ModemActivityInfo mLastModemActivityInfo =
5970 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5971
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005972 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005973 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5974 * representing the state of the modem.
5975 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005976 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5977 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005978 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005979 */
5980 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005981 public void requestModemActivityInfo(ResultReceiver result) {
5982 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005983 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984
5985 final long identity = Binder.clearCallingIdentity();
5986 try {
5987 ModemActivityInfo ret = null;
5988 synchronized (mLastModemActivityInfo) {
5989 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5990 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005991 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005992 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5994 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005995 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5996 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 }
5998 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005999 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6000 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 mLastModemActivityInfo.setIdleTimeMillis(
6002 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
6003 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
6004 mLastModemActivityInfo.setRxTimeMillis(
6005 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
6006 mLastModemActivityInfo.setEnergyUsed(
6007 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6010 mLastModemActivityInfo.getSleepTimeMillis(),
6011 mLastModemActivityInfo.getIdleTimeMillis(),
6012 mLastModemActivityInfo.getTxTimeMillis(),
6013 mLastModemActivityInfo.getRxTimeMillis(),
6014 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006015 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 Bundle bundle = new Bundle();
6017 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6018 result.send(0, bundle);
6019 } finally {
6020 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006021 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006022 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006023
Siddharth Rayb8114062018-06-17 15:02:38 -07006024 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6025 // less than total activity duration.
6026 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6027 if (info == null) {
6028 return false;
6029 }
6030 int activityDurationMs =
6031 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6032 int totalTxTimeMs = 0;
6033 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
6034 totalTxTimeMs += info.getTxTimeMillis()[i];
6035 }
6036 return (info.isValid()
6037 && (info.getSleepTimeMillis() <= activityDurationMs)
6038 && (info.getIdleTimeMillis() <= activityDurationMs)
6039 && (info.getRxTimeMillis() <= activityDurationMs)
6040 && (totalTxTimeMs <= activityDurationMs));
6041 }
6042
Jack Yu85bd38a2015-11-09 11:34:32 -08006043 /**
6044 * {@hide}
6045 * Returns the service state information on specified subscription.
6046 */
6047 @Override
6048 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006050 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006051 return null;
6052 }
6053
Hall Liuf19c44f2018-11-27 14:38:17 -08006054 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6055 LocationAccessPolicy.checkLocationPermission(mApp,
6056 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6057 .setCallingPackage(callingPackage)
6058 .setCallingPid(Binder.getCallingPid())
6059 .setCallingUid(Binder.getCallingUid())
6060 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006061 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006062 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6063 .build());
6064
6065 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6066 LocationAccessPolicy.checkLocationPermission(mApp,
6067 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6068 .setCallingPackage(callingPackage)
6069 .setCallingPid(Binder.getCallingPid())
6070 .setCallingUid(Binder.getCallingUid())
6071 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006072 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006073 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6074 .build());
6075 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6076 boolean hasFinePermission =
6077 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6078 boolean hasCoarsePermission =
6079 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 final long identity = Binder.clearCallingIdentity();
6082 try {
6083 final Phone phone = getPhone(subId);
6084 if (phone == null) {
6085 return null;
6086 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006087
Hall Liuf19c44f2018-11-27 14:38:17 -08006088 ServiceState ss = phone.getServiceState();
6089
6090 // Scrub out the location info in ServiceState depending on what level of access
6091 // the caller has.
6092 if (hasFinePermission) return ss;
6093 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6094 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006095 } finally {
6096 Binder.restoreCallingIdentity(identity);
6097 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006098 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006099
6100 /**
6101 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6102 *
6103 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6104 * voicemail ringtone.
6105 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6106 * PhoneAccount.
6107 */
6108 @Override
6109 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110 final long identity = Binder.clearCallingIdentity();
6111 try {
6112 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6113 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006114 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6118 } finally {
6119 Binder.restoreCallingIdentity(identity);
6120 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006121 }
6122
6123 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006124 * Sets the per-account voicemail ringtone.
6125 *
6126 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6127 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6128 *
6129 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6130 * voicemail ringtone.
6131 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6132 * PhoneAccount.
6133 */
6134 @Override
6135 public void setVoicemailRingtoneUri(String callingPackage,
6136 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006137 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006138 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006139 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6140 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6142 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6143 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006144 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006145
6146 final long identity = Binder.clearCallingIdentity();
6147 try {
6148 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6149 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006150 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 }
6152 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6153 } finally {
6154 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006155 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006156 }
6157
6158 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006159 * Returns whether vibration is set for voicemail notification in Phone settings.
6160 *
6161 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6162 * voicemail vibration setting.
6163 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6164 */
6165 @Override
6166 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006167 final long identity = Binder.clearCallingIdentity();
6168 try {
6169 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6170 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006171 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006173
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006174 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6175 } finally {
6176 Binder.restoreCallingIdentity(identity);
6177 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006178 }
6179
Youhan Wange64578a2016-05-02 15:32:42 -07006180 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006181 * Sets the per-account voicemail vibration.
6182 *
6183 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6184 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6185 *
6186 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6187 * voicemail vibration setting.
6188 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6189 * specific PhoneAccount.
6190 */
6191 @Override
6192 public void setVoicemailVibrationEnabled(String callingPackage,
6193 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006194 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006195 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006196 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6197 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6199 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6200 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006201 }
6202
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006203 final long identity = Binder.clearCallingIdentity();
6204 try {
6205 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6206 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006207 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208 }
6209 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6210 } finally {
6211 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006212 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006213 }
6214
6215 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006216 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6217 *
6218 * @throws SecurityException if the caller does not have the required permission
6219 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006220 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006221 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006222 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006223 }
6224
6225 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006226 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6227 * permission.
6228 *
6229 * @throws SecurityException if the caller does not have the required permission
6230 */
6231 private void enforceSendSmsPermission() {
6232 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6233 }
6234
6235 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006236 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006237 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006238 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006239 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006240 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 final long identity = Binder.clearCallingIdentity();
6242 try {
6243 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006244 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006245 if (componentName == null) {
6246 throw new SecurityException(
6247 "Caller not current active visual voicemail package[null]");
6248 }
6249 String vvmPackage = componentName.getPackageName();
6250 if (!callingPackage.equals(vvmPackage)) {
6251 throw new SecurityException("Caller not current active visual voicemail package["
6252 + vvmPackage + "]");
6253 }
6254 } finally {
6255 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006256 }
6257 }
6258
6259 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006260 * Return the application ID for the app type.
6261 *
6262 * @param subId the subscription ID that this request applies to.
6263 * @param appType the uicc app type.
6264 * @return Application ID for specificied app type, or null if no uicc.
6265 */
6266 @Override
6267 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006268 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006269 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270
6271 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006272 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006273 if (phone == null) {
6274 return null;
6275 }
6276 String aid = null;
6277 try {
6278 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6279 .getApplicationByType(appType).getAid();
6280 } catch (Exception e) {
6281 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6282 }
6283 return aid;
6284 } finally {
6285 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006286 }
Youhan Wange64578a2016-05-02 15:32:42 -07006287 }
6288
Youhan Wang4001d252016-05-11 10:29:41 -07006289 /**
6290 * Return the Electronic Serial Number.
6291 *
6292 * @param subId the subscription ID that this request applies to.
6293 * @return ESN or null if error.
6294 */
6295 @Override
6296 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006297 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006298 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299
6300 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006301 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006302 if (phone == null) {
6303 return null;
6304 }
6305 String esn = null;
6306 try {
6307 esn = phone.getEsn();
6308 } catch (Exception e) {
6309 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6310 }
6311 return esn;
6312 } finally {
6313 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006314 }
Youhan Wang4001d252016-05-11 10:29:41 -07006315 }
6316
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006317 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006318 * Return the Preferred Roaming List Version.
6319 *
6320 * @param subId the subscription ID that this request applies to.
6321 * @return PRLVersion or null if error.
6322 */
6323 @Override
6324 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006325 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006326 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327
6328 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006329 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006330 if (phone == null) {
6331 return null;
6332 }
6333 String cdmaPrlVersion = null;
6334 try {
6335 cdmaPrlVersion = phone.getCdmaPrlVersion();
6336 } catch (Exception e) {
6337 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6338 }
6339 return cdmaPrlVersion;
6340 } finally {
6341 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006342 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006343 }
6344
6345 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006346 * Get snapshot of Telephony histograms
6347 * @return List of Telephony histograms
6348 * @hide
6349 */
6350 @Override
6351 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6353 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354
6355 final long identity = Binder.clearCallingIdentity();
6356 try {
6357 return RIL.getTelephonyRILTimingHistograms();
6358 } finally {
6359 Binder.restoreCallingIdentity(identity);
6360 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006361 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006362
6363 /**
6364 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006365 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6366 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006367 * Require system privileges. In the future we may add this to carrier APIs.
6368 *
Michele Berionne482f8202018-11-27 18:57:59 -08006369 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006370 */
6371 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006372 @TelephonyManager.SetCarrierRestrictionResult
6373 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006374 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006375 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006376
Michele Berionne482f8202018-11-27 18:57:59 -08006377 if (carrierRestrictionRules == null) {
6378 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006379 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381 final long identity = Binder.clearCallingIdentity();
6382 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006383 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006384 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 } finally {
6386 Binder.restoreCallingIdentity(identity);
6387 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006388 }
6389
6390 /**
6391 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006392 * Get the allowed carrier list and the excluded carrier list, including the priority between
6393 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006394 * Require system privileges. In the future we may add this to carrier APIs.
6395 *
Michele Berionne482f8202018-11-27 18:57:59 -08006396 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006397 */
6398 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006399 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006400 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006401 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402
6403 final long identity = Binder.clearCallingIdentity();
6404 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006405 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6406 if (response instanceof CarrierRestrictionRules) {
6407 return (CarrierRestrictionRules) response;
6408 }
6409 // Response is an Exception of some kind,
6410 // which is signalled to the user as a NULL retval
6411 return null;
6412 } catch (Exception e) {
6413 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6414 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415 } finally {
6416 Binder.restoreCallingIdentity(identity);
6417 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006418 }
6419
fionaxu59545b42016-05-25 15:53:37 -07006420 /**
6421 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6422 * @param subId the subscription ID that this action applies to.
6423 * @param enabled control enable or disable metered apns.
6424 * {@hide}
6425 */
6426 @Override
6427 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6428 enforceModifyPermission();
6429 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006430
6431 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006432 if (phone == null) {
6433 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6434 return;
6435 }
6436 try {
6437 phone.carrierActionSetMeteredApnsEnabled(enabled);
6438 } catch (Exception e) {
6439 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440 } finally {
6441 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006442 }
6443 }
6444
6445 /**
6446 * Action set from carrier signalling broadcast receivers to enable/disable radio
6447 * @param subId the subscription ID that this action applies to.
6448 * @param enabled control enable or disable radio.
6449 * {@hide}
6450 */
6451 @Override
6452 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6453 enforceModifyPermission();
6454 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006455
6456 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006457 if (phone == null) {
6458 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6459 return;
6460 }
6461 try {
6462 phone.carrierActionSetRadioEnabled(enabled);
6463 } catch (Exception e) {
6464 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006465 } finally {
6466 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006467 }
6468 }
6469
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006470 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006471 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6472 * network status based on which carrier apps could apply actions accordingly,
6473 * enable/disable default url handler for example.
6474 *
6475 * @param subId the subscription ID that this action applies to.
6476 * @param report control start/stop reporting the default network status.
6477 * {@hide}
6478 */
6479 @Override
6480 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6481 enforceModifyPermission();
6482 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006483
6484 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006485 if (phone == null) {
6486 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6487 return;
6488 }
6489 try {
6490 phone.carrierActionReportDefaultNetworkStatus(report);
6491 } catch (Exception e) {
6492 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006493 } finally {
6494 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006495 }
6496 }
6497
6498 /**
fionaxud9622282017-07-17 17:51:30 -07006499 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6500 * @param subId the subscription ID that this action applies to.
6501 * {@hide}
6502 */
6503 @Override
6504 public void carrierActionResetAll(int subId) {
6505 enforceModifyPermission();
6506 final Phone phone = getPhone(subId);
6507 if (phone == null) {
6508 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6509 return;
6510 }
6511 try {
6512 phone.carrierActionResetAll();
6513 } catch (Exception e) {
6514 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6515 }
6516 }
6517
6518 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006519 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6520 * bug report is being generated.
6521 */
6522 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006523 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006524 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6525 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006526 writer.println("Permission Denial: can't dump Phone from pid="
6527 + Binder.getCallingPid()
6528 + ", uid=" + Binder.getCallingUid()
6529 + "without permission "
6530 + android.Manifest.permission.DUMP);
6531 return;
6532 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006533 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006534 }
Jack Yueb89b242016-06-22 13:27:47 -07006535
Brad Ebingerdac2f002018-04-03 15:17:52 -07006536 @Override
6537 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6538 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6539 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006540 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6541 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006542 }
6543
Jack Yueb89b242016-06-22 13:27:47 -07006544 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006545 * Get aggregated video call data usage since boot.
6546 *
6547 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6548 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006549 * {@hide}
6550 */
6551 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006552 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006553 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6554 null);
6555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556 final long identity = Binder.clearCallingIdentity();
6557 try {
6558 // NetworkStatsService keeps tracking the active network interface and identity. It
6559 // records the delta with the corresponding network identity.
6560 // We just return the total video call data usage snapshot since boot.
6561 Phone phone = getPhone(subId);
6562 if (phone != null) {
6563 return phone.getVtDataUsage(perUidStats);
6564 }
6565 return null;
6566 } finally {
6567 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006568 }
Jack Yueb89b242016-06-22 13:27:47 -07006569 }
Jack Yu75ab2952016-07-08 14:29:33 -07006570
6571 /**
6572 * Policy control of data connection. Usually used when data limit is passed.
6573 * @param enabled True if enabling the data, otherwise disabling.
6574 * @param subId Subscription index
6575 * {@hide}
6576 */
6577 @Override
6578 public void setPolicyDataEnabled(boolean enabled, int subId) {
6579 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580
6581 final long identity = Binder.clearCallingIdentity();
6582 try {
6583 Phone phone = getPhone(subId);
6584 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006585 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586 }
6587 } finally {
6588 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006589 }
6590 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006591
6592 /**
6593 * Get Client request stats
6594 * @return List of Client Request Stats
6595 * @hide
6596 */
6597 @Override
6598 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006600 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006601 return null;
6602 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006603 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605 final long identity = Binder.clearCallingIdentity();
6606 try {
6607 if (phone != null) {
6608 return phone.getClientRequestStats();
6609 }
6610
6611 return null;
6612 } finally {
6613 Binder.restoreCallingIdentity(identity);
6614 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006615 }
6616
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006617 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006618 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006619 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006620 }
Jack Yueb4124c2017-02-16 15:32:43 -08006621
6622 /**
Grace Chen70990072017-03-24 17:21:30 -07006623 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006624 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006625 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006626 * @param state State of SIM (power down, power up, pass through)
6627 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6628 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6629 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006630 *
6631 **/
6632 @Override
Grace Chen70990072017-03-24 17:21:30 -07006633 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006634 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006635 Phone phone = PhoneFactory.getPhone(slotIndex);
6636
vagdeviaf9a5b92018-08-15 16:01:53 -07006637 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 final long identity = Binder.clearCallingIdentity();
6640 try {
6641 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006642 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643 }
6644 } finally {
6645 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006646 }
6647 }
Shuo Qiandd210312017-04-12 22:11:33 +00006648
Tyler Gunn65d45c22017-06-05 11:22:26 -07006649 private boolean isUssdApiAllowed(int subId) {
6650 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006651 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006652 if (configManager == null) {
6653 return false;
6654 }
6655 PersistableBundle pb = configManager.getConfigForSubId(subId);
6656 if (pb == null) {
6657 return false;
6658 }
6659 return pb.getBoolean(
6660 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6661 }
6662
Shuo Qiandd210312017-04-12 22:11:33 +00006663 /**
6664 * Check if phone is in emergency callback mode
6665 * @return true if phone is in emergency callback mode
6666 * @param subId sub id
6667 */
goneil9c5f4872017-12-05 14:07:56 -08006668 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006669 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006670 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006671 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006672
6673 final long identity = Binder.clearCallingIdentity();
6674 try {
6675 if (phone != null) {
6676 return phone.isInEcm();
6677 } else {
6678 return false;
6679 }
6680 } finally {
6681 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006682 }
6683 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006684
6685 /**
6686 * Get the current signal strength information for the given subscription.
6687 * Because this information is not updated when the device is in a low power state
6688 * it should not be relied-upon to be current.
6689 * @param subId Subscription index
6690 * @return the most recent cached signal strength info from the modem
6691 */
6692 @Override
6693 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 final long identity = Binder.clearCallingIdentity();
6695 try {
6696 Phone p = getPhone(subId);
6697 if (p == null) {
6698 return null;
6699 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701 return p.getSignalStrength();
6702 } finally {
6703 Binder.restoreCallingIdentity(identity);
6704 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006705 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006706
Pengquan Meng77b7f132018-08-22 14:49:57 -07006707 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006708 * Get the current modem radio state for the given slot.
6709 * @param slotIndex slot index.
6710 * @param callingPackage the name of the package making the call.
6711 * @return the current radio power state from the modem
6712 */
6713 @Override
6714 public int getRadioPowerState(int slotIndex, String callingPackage) {
6715 Phone phone = PhoneFactory.getPhone(slotIndex);
6716 if (phone != null) {
6717 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6718 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6719 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6720 }
6721
6722 final long identity = Binder.clearCallingIdentity();
6723 try {
6724 return phone.getRadioPowerState();
6725 } finally {
6726 Binder.restoreCallingIdentity(identity);
6727 }
6728 }
6729 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6730 }
6731
6732 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006733 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6734 *
6735 * <p>Requires one of the following permissions:
6736 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6737 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6738 * privileges.
6739 *
6740 * @param subId subscription id
6741 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6742 * {@code false}.
6743 */
6744 @Override
6745 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006746 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6747 null /* message */);
6748
Pengquan Menga1bb6272018-09-06 09:59:22 -07006749 boolean isEnabled = false;
6750 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006751 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006752 Phone phone = getPhone(subId);
6753 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006754 } catch (Exception e) {
6755 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6756 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006757 } finally {
6758 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006759 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006760 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006761 }
6762
6763
6764 /**
6765 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6766 *
6767 * <p> Requires permission:
6768 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6769 * privileges.
6770 *
6771 * @param subId subscription id
6772 * @param isEnabled {@code true} means enable, {@code false} means disable.
6773 */
6774 @Override
6775 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6777 mApp, subId, "setDataRoamingEnabled");
6778
Pengquan Menga1bb6272018-09-06 09:59:22 -07006779 final long identity = Binder.clearCallingIdentity();
6780 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006781 Phone phone = getPhone(subId);
6782 if (phone != null) {
6783 phone.setDataRoamingEnabled(isEnabled);
6784 }
6785 } finally {
6786 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006787 }
6788 }
6789
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006790 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006791 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006792 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6793 mApp, subId, "isManualNetworkSelectionAllowed");
6794
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006795 boolean isAllowed = true;
6796 final long identity = Binder.clearCallingIdentity();
6797 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006798 Phone phone = getPhone(subId);
6799 if (phone != null) {
6800 isAllowed = phone.isCspPlmnEnabled();
6801 }
6802 } finally {
6803 Binder.restoreCallingIdentity(identity);
6804 }
6805 return isAllowed;
6806 }
6807
6808 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006809 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006810 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006811 try {
6812 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006813 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006814 } catch (SecurityException e) {
6815 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6816 // has carrier privileges on an active UICC
6817 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6818 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006819 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006820 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006821 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006822
6823 final long identity = Binder.clearCallingIdentity();
6824 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006825 UiccController uiccController = UiccController.getInstance();
6826 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006827 if (hasReadPermission) {
6828 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006829 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006830
6831 // Remove private info if the caller doesn't have access
6832 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6833 for (UiccCardInfo cardInfo : cardInfos) {
6834 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6835 // is available
6836 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6837 if (card == null || card.getUiccProfile() == null) {
6838 // assume no access if the card or profile is unavailable
6839 filteredInfos.add(cardInfo.getUnprivileged());
6840 continue;
6841 }
6842 UiccProfile profile = card.getUiccProfile();
6843 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6844 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6845 filteredInfos.add(cardInfo);
6846 } else {
6847 filteredInfos.add(cardInfo.getUnprivileged());
6848 }
6849 }
6850 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006851 } finally {
6852 Binder.restoreCallingIdentity(identity);
6853 }
6854 }
6855
6856 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006857 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006858 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006860 final long identity = Binder.clearCallingIdentity();
6861 try {
6862 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6863 if (slots == null) {
6864 Rlog.i(LOG_TAG, "slots is null.");
6865 return null;
6866 }
6867
6868 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6869 for (int i = 0; i < slots.length; i++) {
6870 UiccSlot slot = slots[i];
6871 if (slot == null) {
6872 continue;
6873 }
6874
Jordan Liu7be7e652019-05-06 18:55:02 +00006875 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006876 UiccCard card = slot.getUiccCard();
6877 if (card != null) {
6878 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006879 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006880 cardId = slot.getEid();
6881 if (TextUtils.isEmpty(cardId)) {
6882 cardId = slot.getIccId();
6883 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006884 }
6885
Jordan Liu857451f2019-05-09 16:35:35 -07006886 if (cardId != null) {
6887 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6888 // if cardId is an EID, it's all digits so this is fine
6889 cardId = IccUtils.stripTrailingFs(cardId);
6890 }
6891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006892 int cardState = 0;
6893 switch (slot.getCardState()) {
6894 case CARDSTATE_ABSENT:
6895 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6896 break;
6897 case CARDSTATE_PRESENT:
6898 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6899 break;
6900 case CARDSTATE_ERROR:
6901 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6902 break;
6903 case CARDSTATE_RESTRICTED:
6904 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6905 break;
6906 default:
6907 break;
6908
6909 }
6910
6911 infos[i] = new UiccSlotInfo(
6912 slot.isActive(),
6913 slot.isEuicc(),
6914 cardId,
6915 cardState,
6916 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006917 slot.isExtendedApduSupported(),
6918 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006919 }
6920 return infos;
6921 } finally {
6922 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006923 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006924 }
6925
6926 @Override
6927 public boolean switchSlots(int[] physicalSlots) {
6928 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006929
6930 final long identity = Binder.clearCallingIdentity();
6931 try {
6932 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6933 } finally {
6934 Binder.restoreCallingIdentity(identity);
6935 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006936 }
Jack Yu4c988042018-02-27 15:30:01 -08006937
6938 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006939 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006940 final long identity = Binder.clearCallingIdentity();
6941 try {
6942 return UiccController.getInstance().getCardIdForDefaultEuicc();
6943 } finally {
6944 Binder.restoreCallingIdentity(identity);
6945 }
6946 }
6947
6948 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006949 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6950 enforceModifyPermission();
6951 final Phone phone = getPhone(subId);
6952 if (phone == null) {
6953 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6954 return;
6955 }
6956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006957 final long identity = Binder.clearCallingIdentity();
6958 try {
6959 phone.setRadioIndicationUpdateMode(filters, mode);
6960 } finally {
6961 Binder.restoreCallingIdentity(identity);
6962 }
Jack Yu4c988042018-02-27 15:30:01 -08006963 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006964
6965 /**
goneil47ffb6e2018-04-06 15:40:58 -07006966 * A test API to reload the UICC profile.
6967 *
6968 * <p>Requires that the calling app has permission
6969 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6970 * @hide
6971 */
6972 @Override
6973 public void refreshUiccProfile(int subId) {
6974 enforceModifyPermission();
6975
6976 final long identity = Binder.clearCallingIdentity();
6977 try {
6978 Phone phone = getPhone(subId);
6979 if (phone == null) {
6980 return;
6981 }
6982 UiccCard uiccCard = phone.getUiccCard();
6983 if (uiccCard == null) {
6984 return;
6985 }
6986 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6987 if (uiccProfile == null) {
6988 return;
6989 }
6990 uiccProfile.refresh();
6991 } finally {
6992 Binder.restoreCallingIdentity(identity);
6993 }
6994 }
6995
6996 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006997 * Returns false if the mobile data is disabled by default, otherwise return true.
6998 */
6999 private boolean getDefaultDataEnabled() {
7000 return "true".equalsIgnoreCase(
7001 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
7002 }
7003
7004 /**
7005 * Returns true if the data roaming is enabled by default, i.e the system property
7006 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7007 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7008 */
7009 private boolean getDefaultDataRoamingEnabled(int subId) {
7010 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007011 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007012 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
7013 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
7014 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7015 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7016 return isDataRoamingEnabled;
7017 }
7018
7019 /**
7020 * Returns the default network type for the given {@code subId}, if the default network type is
7021 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7022 */
7023 private int getDefaultNetworkType(int subId) {
7024 return Integer.parseInt(
7025 TelephonyManager.getTelephonyProperty(
7026 mSubscriptionController.getPhoneId(subId),
7027 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
7028 String.valueOf(Phone.PREFERRED_NT_MODE)));
7029 }
fionaxua13278b2018-03-21 00:08:13 -07007030
7031 @Override
7032 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007033 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007034 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035
7036 final long identity = Binder.clearCallingIdentity();
7037 try {
7038 final Phone phone = getPhone(subId);
7039 if (phone == null) {
7040 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7041 return;
7042 }
chen xueaba88a2019-03-15 13:15:10 -07007043 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7044 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007045 } finally {
7046 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007047 }
fionaxua13278b2018-03-21 00:08:13 -07007048 }
7049
7050 @Override
7051 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007052 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053
7054 final long identity = Binder.clearCallingIdentity();
7055 try {
7056 final Phone phone = getPhone(subId);
7057 if (phone == null) {
7058 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7059 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7060 }
7061 return phone.getCarrierIdListVersion();
7062 } finally {
7063 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007064 }
fionaxua13278b2018-03-21 00:08:13 -07007065 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007066
7067 @Override
7068 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
7069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7070 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
7071 return -1;
7072 }
7073
7074 final long identity = Binder.clearCallingIdentity();
7075 try {
7076 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7077 } finally {
7078 Binder.restoreCallingIdentity(identity);
7079 }
7080 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007081
7082 @Override
7083 public int getCdmaRoamingMode(int subId) {
7084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7085 mApp, subId, "getCdmaRoamingMode");
7086
7087 final long identity = Binder.clearCallingIdentity();
7088 try {
7089 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7090 } finally {
7091 Binder.restoreCallingIdentity(identity);
7092 }
7093 }
7094
7095 @Override
7096 public boolean setCdmaRoamingMode(int subId, int mode) {
7097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7098 mApp, subId, "setCdmaRoamingMode");
7099
7100 final long identity = Binder.clearCallingIdentity();
7101 try {
7102 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7103 } finally {
7104 Binder.restoreCallingIdentity(identity);
7105 }
7106 }
7107
7108 @Override
7109 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7111 mApp, subId, "setCdmaSubscriptionMode");
7112
7113 final long identity = Binder.clearCallingIdentity();
7114 try {
7115 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7116 } finally {
7117 Binder.restoreCallingIdentity(identity);
7118 }
7119 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007120
sqianc5eccab2018-10-19 18:46:41 -07007121 @Override
sqian8c685422019-02-22 15:55:18 -08007122 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007123 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007124 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007125 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007126 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7127 }
7128 final long identity = Binder.clearCallingIdentity();
7129 try {
sqian854d44b2018-12-12 16:48:18 -08007130 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7131 for (Phone phone: PhoneFactory.getPhones()) {
7132 if (phone.getEmergencyNumberTracker() != null
7133 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7134 emergencyNumberListInternal.put(
7135 phone.getSubId(),
7136 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7137 }
sqian11b7a0e2018-12-05 18:48:28 -08007138 }
sqian854d44b2018-12-12 16:48:18 -08007139 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007140 } finally {
7141 Binder.restoreCallingIdentity(identity);
7142 }
sqianc5eccab2018-10-19 18:46:41 -07007143 }
7144
7145 @Override
sqian8c685422019-02-22 15:55:18 -08007146 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007147 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007148 if (!exactMatch) {
7149 TelephonyPermissions
7150 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007151 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007152 }
7153 final long identity = Binder.clearCallingIdentity();
7154 try {
sqian854d44b2018-12-12 16:48:18 -08007155 for (Phone phone: PhoneFactory.getPhones()) {
7156 if (phone.getEmergencyNumberTracker() != null
7157 && phone.getEmergencyNumberTracker() != null) {
7158 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7159 number, exactMatch)) {
7160 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007161 }
7162 }
sqian11b7a0e2018-12-05 18:48:28 -08007163 }
7164 return false;
7165 } finally {
7166 Binder.restoreCallingIdentity(identity);
7167 }
7168 }
7169
sqianf4ca7ed2019-01-15 18:32:07 -08007170 /**
7171 * Update emergency number list for test mode.
7172 */
7173 @Override
7174 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7175 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7176 "updateEmergencyNumberListTestMode");
7177
7178 final long identity = Binder.clearCallingIdentity();
7179 try {
7180 for (Phone phone: PhoneFactory.getPhones()) {
7181 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7182 if (tracker != null) {
7183 tracker.executeEmergencyNumberTestModeCommand(action, num);
7184 }
7185 }
7186 } finally {
7187 Binder.restoreCallingIdentity(identity);
7188 }
7189 }
7190
7191 /**
7192 * Get the full emergency number list for test mode.
7193 */
7194 @Override
7195 public List<String> getEmergencyNumberListTestMode() {
7196 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7197 "getEmergencyNumberListTestMode");
7198
7199 final long identity = Binder.clearCallingIdentity();
7200 try {
7201 Set<String> emergencyNumbers = new HashSet<>();
7202 for (Phone phone: PhoneFactory.getPhones()) {
7203 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7204 if (tracker != null) {
7205 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7206 emergencyNumbers.add(num.getNumber());
7207 }
7208 }
7209 }
7210 return new ArrayList<>(emergencyNumbers);
7211 } finally {
7212 Binder.restoreCallingIdentity(identity);
7213 }
7214 }
7215
chen xud6b45bd2018-10-30 22:27:10 -07007216 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007217 public int getEmergencyNumberDbVersion(int subId) {
7218 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7219
7220 final long identity = Binder.clearCallingIdentity();
7221 try {
7222 final Phone phone = getPhone(subId);
7223 if (phone == null) {
7224 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7225 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7226 }
7227 return phone.getEmergencyNumberDbVersion();
7228 } finally {
7229 Binder.restoreCallingIdentity(identity);
7230 }
7231 }
7232
7233 @Override
7234 public void notifyOtaEmergencyNumberDbInstalled() {
7235 enforceModifyPermission();
7236
7237 final long identity = Binder.clearCallingIdentity();
7238 try {
7239 for (Phone phone: PhoneFactory.getPhones()) {
7240 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7241 if (tracker != null) {
7242 tracker.updateOtaEmergencyNumberDatabase();
7243 }
7244 }
7245 } finally {
7246 Binder.restoreCallingIdentity(identity);
7247 }
7248 }
7249
7250 @Override
7251 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7252 enforceActiveEmergencySessionPermission();
7253
7254 final long identity = Binder.clearCallingIdentity();
7255 try {
7256 for (Phone phone: PhoneFactory.getPhones()) {
7257 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7258 if (tracker != null) {
7259 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7260 }
7261 }
7262 } finally {
7263 Binder.restoreCallingIdentity(identity);
7264 }
7265 }
7266
7267 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007268 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7269 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7270 Phone phone = getPhone(subId);
7271 if (phone == null) {
7272 return null;
7273 }
7274 final long identity = Binder.clearCallingIdentity();
7275 try {
7276 UiccProfile profile = UiccController.getInstance()
7277 .getUiccProfileForPhone(phone.getPhoneId());
7278 if (profile != null) {
7279 return profile.getCertsFromCarrierPrivilegeAccessRules();
7280 }
7281 } finally {
7282 Binder.restoreCallingIdentity(identity);
7283 }
7284 return null;
7285 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007286
7287 /**
7288 * Enable or disable a modem stack.
7289 */
7290 @Override
7291 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7292 enforceModifyPermission();
7293
7294 final long identity = Binder.clearCallingIdentity();
7295 try {
7296 Phone phone = PhoneFactory.getPhone(slotIndex);
7297 if (phone == null) {
7298 return false;
7299 } else {
7300 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7301 }
7302 } finally {
7303 Binder.restoreCallingIdentity(identity);
7304 }
7305 }
Michelecea4cf22018-12-21 15:00:11 -08007306
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007307 /**
7308 * Whether a modem stack is enabled or not.
7309 */
7310 @Override
7311 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7312 Phone phone = PhoneFactory.getPhone(slotIndex);
7313 if (phone == null) return false;
7314
7315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7316 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7317 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7318 }
7319
7320 final long identity = Binder.clearCallingIdentity();
7321 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007322 try {
7323 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7324 } catch (NoSuchElementException ex) {
7325 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7326 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007327 } finally {
7328 Binder.restoreCallingIdentity(identity);
7329 }
7330 }
7331
Michelecea4cf22018-12-21 15:00:11 -08007332 @Override
Michele0ea7d782019-03-19 14:58:42 -07007333 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007334 enforceModifyPermission();
7335
7336 final long identity = Binder.clearCallingIdentity();
7337 try {
7338 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007339 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007340 .commit();
7341 } finally {
7342 Binder.restoreCallingIdentity(identity);
7343 }
7344 }
7345
7346 @Override
Michele0ea7d782019-03-19 14:58:42 -07007347 @TelephonyManager.IsMultiSimSupportedResult
7348 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007349 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007350 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7351 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007352 }
Michelecea4cf22018-12-21 15:00:11 -08007353
7354 final long identity = Binder.clearCallingIdentity();
7355 try {
Michele0ea7d782019-03-19 14:58:42 -07007356 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007357 } finally {
7358 Binder.restoreCallingIdentity(identity);
7359 }
7360 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007361
Michele0ea7d782019-03-19 14:58:42 -07007362 @TelephonyManager.IsMultiSimSupportedResult
7363 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007364 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7365 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7366 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007367 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7368 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007369 }
7370 // Check if the hardware supports multisim functionality. If usage of multisim is not
7371 // supported by the modem, indicate that it is restricted.
7372 PhoneCapability staticCapability =
7373 mPhoneConfigurationManager.getStaticPhoneCapability();
7374 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007375 loge("isMultiSimSupportedInternal: no static configuration available");
7376 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007377 }
7378 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007379 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7380 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007381 }
7382 // Check if support of multiple SIMs is restricted by carrier
7383 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007384 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007385 }
7386
Michele0ea7d782019-03-19 14:58:42 -07007387 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007388 }
7389
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007390 /**
7391 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007392 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7393 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7394 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007395 * @param numOfSims number of active sims we want to switch to
7396 */
7397 @Override
7398 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007399 if (numOfSims == 1) {
7400 enforceModifyPermission();
7401 } else {
7402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7403 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7404 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007405 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007406
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007407 try {
Michele30b57b22019-03-01 12:01:14 -08007408 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007409 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007410 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7411 return;
7412 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007413 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7414 } finally {
7415 Binder.restoreCallingIdentity(identity);
7416 }
7417 }
7418
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007419 @Override
7420 public boolean isApplicationOnUicc(int subId, int appType) {
7421 enforceReadPrivilegedPermission("isApplicationOnUicc");
7422 Phone phone = getPhone(subId);
7423 if (phone == null) {
7424 return false;
7425 }
7426 final long identity = Binder.clearCallingIdentity();
7427 try {
7428 UiccCard uiccCard = phone.getUiccCard();
7429 if (uiccCard == null) {
7430 return false;
7431 }
7432 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7433 if (uiccProfile == null) {
7434 return false;
7435 }
7436 if (TelephonyManager.APPTYPE_SIM <= appType
7437 && appType <= TelephonyManager.APPTYPE_ISIM) {
7438 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7439 }
7440 return false;
7441 } finally {
7442 Binder.restoreCallingIdentity(identity);
7443 }
7444 }
7445
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007446 /**
chen xub4baa772019-04-03 10:23:41 -07007447 * Get whether making changes to modem configurations will trigger reboot.
7448 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007449 */
7450 @Override
chen xub4baa772019-04-03 10:23:41 -07007451 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7452 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7453 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7454 return false;
7455 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007456 final long identity = Binder.clearCallingIdentity();
7457 try {
7458 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7459 } finally {
7460 Binder.restoreCallingIdentity(identity);
7461 }
7462 }
7463
Nathan Harold29f5f052019-02-15 13:41:57 -08007464 private void updateModemStateMetrics() {
7465 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7466 // TODO: check the state for each modem if the api is ready.
7467 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7468 }
7469
Pengquan Meng3889a572019-01-23 11:16:29 -08007470 @Override
7471 public int[] getSlotsMapping() {
7472 enforceReadPrivilegedPermission("getSlotsMapping");
7473
7474 final long identity = Binder.clearCallingIdentity();
7475 try {
7476 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7477 // All logical slots should have a mapping to a physical slot.
7478 int[] logicalSlotsMapping = new int[phoneCount];
7479 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7480 for (int i = 0; i < slotInfos.length; i++) {
7481 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7482 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7483 }
7484 }
7485 return logicalSlotsMapping;
7486 } finally {
7487 Binder.restoreCallingIdentity(identity);
7488 }
7489 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007490
7491 /**
7492 * Get the IRadio HAL Version
7493 */
7494 @Override
7495 public int getRadioHalVersion() {
7496 Phone phone = getDefaultPhone();
7497 if (phone == null) return -1;
7498 HalVersion hv = phone.getHalVersion();
7499 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7500 return hv.major * 100 + hv.minor;
7501 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007502
7503 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007504 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7505 * corresponding network requests on a subId.
7506 *
7507 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007508 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007509 * 2) APN is un-metered for this subscription, or
7510 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7511 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7512 *
7513 * @return whether data is allowed for a apn type.
7514 *
7515 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007516 */
7517 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007518 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007519 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7520 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007521
7522 // Now that all security checks passes, perform the operation as ourselves.
7523 final long identity = Binder.clearCallingIdentity();
7524 try {
7525 Phone phone = getPhone(subId);
7526 if (phone == null) return false;
7527
Jack Yu41407ee2019-05-13 16:54:09 -07007528 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007529 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7530 } finally {
7531 Binder.restoreCallingIdentity(identity);
7532 }
7533 }
7534
7535 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007536 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007537 enforceReadPrivilegedPermission("isApnMetered");
7538
7539 // Now that all security checks passes, perform the operation as ourselves.
7540 final long identity = Binder.clearCallingIdentity();
7541 try {
7542 Phone phone = getPhone(subId);
7543 if (phone == null) return true; // By default return true.
7544
Jack Yu41407ee2019-05-13 16:54:09 -07007545 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007546 } finally {
7547 Binder.restoreCallingIdentity(identity);
7548 }
7549 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007550
7551 @Override
7552 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7553 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7554 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7555 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7556 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7557 }
7558 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7559 Intent intent = new Intent();
7560 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7561 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7562 // Bring up choose default SMS subscription dialog right now
7563 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7564 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7565 mApp.startActivity(intent);
7566 }
chen xud5ca2d52019-05-28 15:20:57 -07007567
7568 @Override
7569 public String getMmsUAProfUrl(int subId) {
7570 //TODO investigate if this API should require proper permission check in R b/133791609
7571 final long identity = Binder.clearCallingIdentity();
7572 try {
7573 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7574 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7575 } finally {
7576 Binder.restoreCallingIdentity(identity);
7577 }
7578 }
7579
7580 @Override
7581 public String getMmsUserAgent(int subId) {
7582 //TODO investigate if this API should require proper permission check in R b/133791609
7583 final long identity = Binder.clearCallingIdentity();
7584 try {
7585 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7586 .getString(com.android.internal.R.string.config_mms_user_agent);
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
7589 }
7590 }
Jack Yub07d4972019-05-28 16:12:25 -07007591
7592 @Override
7593 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7594 enforceModifyPermission();
7595
7596 // Now that all security checks passes, perform the operation as ourselves.
7597 final long identity = Binder.clearCallingIdentity();
7598 try {
7599 Phone phone = getPhone(subId);
7600 if (phone == null) return false;
7601
7602 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7603 } finally {
7604 Binder.restoreCallingIdentity(identity);
7605 }
7606 }
7607
7608 @Override
7609 public boolean isDataAllowedInVoiceCall(int subId) {
7610 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7611
7612 // Now that all security checks passes, perform the operation as ourselves.
7613 final long identity = Binder.clearCallingIdentity();
7614 try {
7615 Phone phone = getPhone(subId);
7616 if (phone == null) return false;
7617
7618 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7619 } finally {
7620 Binder.restoreCallingIdentity(identity);
7621 }
7622 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007623
7624 /**
7625 * Updates whether conference event pacakge handling is enabled.
7626 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7627 * otherwise.
7628 */
7629 @Override
7630 public void setCepEnabled(boolean isCepEnabled) {
7631 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7632
7633 final long identity = Binder.clearCallingIdentity();
7634 try {
7635 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7636 for (Phone phone : PhoneFactory.getPhones()) {
7637 Phone defaultPhone = phone.getImsPhone();
7638 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7639 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7640 ImsPhoneCallTracker imsPhoneCallTracker =
7641 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7642 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7643 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7644 + imsPhone.getMsisdn());
7645 }
7646 }
7647 } finally {
7648 Binder.restoreCallingIdentity(identity);
7649 }
7650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007651}