blob: 17067ec35200199f9e9eb7244ed3cfec9b6fa5d8 [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
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Tyler Gunn327a9722019-04-03 15:28:53 -070024import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080026import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070027import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070028import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.content.Context;
30import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070031import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070032import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070033import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080034import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070035import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070036import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070047import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080048import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070049import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070051import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070052import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070053import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070055import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070057import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080058import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070059import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080060import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080061import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070062import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070063import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080064import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070066import android.telephony.CellInfoGsm;
67import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070068import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070069import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070070import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070071import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080072import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070073import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080074import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070075import android.telephony.NetworkScanRequest;
Michelebcb01bc2019-02-04 11:36:23 -080076import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080077import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070078import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080079import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070080import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080082import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080083import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070085import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070086import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080088import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000089import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070090import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070092import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080093import android.telephony.data.ApnSetting;
Jack Yu40306fc2019-05-13 16:54:09 -070094import android.telephony.data.ApnSetting.ApnType;
calvinpaneed9ae82018-11-01 19:43:06 +080095import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070096import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070097import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080098import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070099import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800100import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700101import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800102import android.telephony.ims.aidl.IImsMmTelFeature;
103import android.telephony.ims.aidl.IImsRcsFeature;
104import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -0700105import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800106import android.telephony.ims.feature.MmTelFeature;
107import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800108import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800110import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800112import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800113import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800114
Andrew Lee312e8172014-10-23 17:01:36 -0700115import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800116import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700117import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700118import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700119import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800120import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700121import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800124import com.android.internal.telephony.HalVersion;
Brad Ebinger5ff97f62019-04-23 16:31:13 -0700125import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800126import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800128import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700129import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100130import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700131import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700132import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700134import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800135import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700136import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700137import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700138import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700139import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700140import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700141import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800142import com.android.internal.telephony.SmsApplication;
143import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajan716e76c2019-05-13 13:48:32 -0700144import com.android.internal.telephony.SmsController;
Brad Ebinger5ff97f62019-04-23 16:31:13 -0700145import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800146import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800147import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chen460810d2019-04-10 18:25:07 -0700148import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqian9d4df8b2019-01-15 18:32:07 -0800149import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700150import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebingereb160e22019-01-23 15:06:19 -0800151import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800152import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.uicc.IccIoResult;
154import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800155import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700156import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800157import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800159import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000160import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700161import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800162import com.android.internal.util.HexDump;
Brad Ebinger5ff97f62019-04-23 16:31:13 -0700163import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700164import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800165import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700166import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700167import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800168
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700169import java.io.FileDescriptor;
170import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800172import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800173import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800174import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800175import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800176import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100177import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800178import java.util.Map;
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -0700179import java.util.NoSuchElementException;
sqian9d4df8b2019-01-15 18:32:07 -0800180import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181
182/**
183 * Implementation of the ITelephony interface.
184 */
Santos Cordon117fee72014-05-16 17:56:12 -0700185public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186 private static final String LOG_TAG = "PhoneInterfaceManager";
187 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
188 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800189 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190
191 // Message codes used with mMainThreadHandler
192 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700193 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
194 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195 private static final int CMD_OPEN_CHANNEL = 9;
196 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
197 private static final int CMD_CLOSE_CHANNEL = 11;
198 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800199 private static final int CMD_NV_READ_ITEM = 13;
200 private static final int EVENT_NV_READ_ITEM_DONE = 14;
201 private static final int CMD_NV_WRITE_ITEM = 15;
202 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
203 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
204 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700205 private static final int CMD_RESET_MODEM_CONFIG = 19;
206 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800207 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
208 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
209 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
210 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800211 private static final int CMD_SEND_ENVELOPE = 25;
212 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000213 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
214 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700215 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
216 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
217 private static final int CMD_EXCHANGE_SIM_IO = 31;
218 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800219 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
220 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700221 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
222 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700223 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
224 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700225 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
226 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
227 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
228 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700229 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
230 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
231 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
232 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700233 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800234 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
235 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000236 private static final int CMD_SWITCH_SLOTS = 50;
237 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700238 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
239 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
240 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
241 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
242 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
243 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
244 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
245 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700246 private static final int CMD_GET_ALL_CELL_INFO = 60;
247 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
248 private static final int CMD_GET_CELL_LOCATION = 62;
249 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700250 private static final int CMD_MODEM_REBOOT = 64;
251 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700252 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
253 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800254 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
255 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -0700256 private static final int CMD_GET_MODEM_STATUS = 70;
257 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800259 // Parameters of select command.
260 private static final int SELECT_COMMAND = 0xA4;
261 private static final int SELECT_P1 = 0x04;
262 private static final int SELECT_P2 = 0;
263 private static final int SELECT_P3 = 0x10;
264
Pengquan Meng85728fb2018-03-12 16:31:21 -0700265 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
266 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
267 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
268
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269 /** The singleton instance. */
270 private static PhoneInterfaceManager sInstance;
271
Wink Saville3ab207e2014-11-20 13:07:20 -0800272 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800273 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700274 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800275 private AppOpsManager mAppOps;
276 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800277 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700279 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280
Derek Tan97ebb422014-09-05 16:55:38 -0700281 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
282 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800283 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800284 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700285
Micheled3107c52018-12-21 15:00:11 -0800286 // String to store multi SIM allowed
287 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
288
Derek Tan740e1672017-06-27 14:56:27 -0700289 // The AID of ISD-R.
290 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
291
yinxub1bed742017-04-17 11:45:04 -0700292 private NetworkScanRequestTracker mNetworkScanRequestTracker;
293
David Kelly5e06a7f2018-03-12 14:10:59 +0000294 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
295 private static final int MANUFACTURER_CODE_LENGTH = 8;
296
Derek Tan89e89d42014-07-08 17:00:10 -0700297 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700298 * A request object to use for transmitting data to an ICC.
299 */
300 private static final class IccAPDUArgument {
301 public int channel, cla, command, p1, p2, p3;
302 public String data;
303
304 public IccAPDUArgument(int channel, int cla, int command,
305 int p1, int p2, int p3, String data) {
306 this.channel = channel;
307 this.cla = cla;
308 this.command = command;
309 this.p1 = p1;
310 this.p2 = p2;
311 this.p3 = p3;
312 this.data = data;
313 }
314 }
315
316 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700317 * A request object to use for transmitting data to an ICC.
318 */
319 private static final class ManualNetworkSelectionArgument {
320 public OperatorInfo operatorInfo;
321 public boolean persistSelection;
322
323 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
324 this.operatorInfo = operatorInfo;
325 this.persistSelection = persistSelection;
326 }
327 }
328
329 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
331 * request after sending. The main thread will notify the request when it is complete.
332 */
333 private static final class MainThreadRequest {
334 /** The argument to use for the request */
335 public Object argument;
336 /** The result of the request that is run on the main thread */
337 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800338 // The subscriber id that this request applies to. Defaults to
339 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
340 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341
Nathan Harold92bed182018-10-12 18:16:49 -0700342 // In cases where subId is unavailable, the caller needs to specify the phone.
343 public Phone phone;
344
vagdevie435a3e2018-08-15 16:01:53 -0700345 public WorkSource workSource;
346
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347 public MainThreadRequest(Object argument) {
348 this.argument = argument;
349 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800350
Nathan Harold92bed182018-10-12 18:16:49 -0700351 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
352 this.argument = argument;
353 if (phone != null) {
354 this.phone = phone;
355 }
356 this.workSource = workSource;
357 }
358
vagdevie435a3e2018-08-15 16:01:53 -0700359 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800360 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800361 if (subId != null) {
362 this.subId = subId;
363 }
vagdevie435a3e2018-08-15 16:01:53 -0700364 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 }
367
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800368 private static final class IncomingThirdPartyCallArgs {
369 public final ComponentName component;
370 public final String callId;
371 public final String callerDisplayName;
372
373 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
374 String callerDisplayName) {
375 this.component = component;
376 this.callId = callId;
377 this.callerDisplayName = callerDisplayName;
378 }
379 }
380
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 /**
382 * A handler that processes messages on the main thread in the phone process. Since many
383 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
384 * inbound binder threads to the main thread in the phone process. The Binder thread
385 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
386 * on, which will be notified when the operation completes and will contain the result of the
387 * request.
388 *
389 * <p>If a MainThreadRequest object is provided in the msg.obj field,
390 * note that request.result must be set to something non-null for the calling thread to
391 * unblock.
392 */
393 private final class MainThreadHandler extends Handler {
394 @Override
395 public void handleMessage(Message msg) {
396 MainThreadRequest request;
397 Message onCompleted;
398 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800399 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700400 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800401 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402
403 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700404 case CMD_HANDLE_USSD_REQUEST: {
405 request = (MainThreadRequest) msg.obj;
406 final Phone phone = getPhoneFromRequest(request);
407 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
408 String ussdRequest = ussdObject.first;
409 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700410
Pengquan Meng0c05b502018-09-06 09:59:22 -0700411 if (!isUssdApiAllowed(request.subId)) {
412 // Carrier does not support use of this API, return failure.
413 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
414 UssdResponse response = new UssdResponse(ussdRequest, null);
415 Bundle returnData = new Bundle();
416 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
417 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700418
Pengquan Meng0c05b502018-09-06 09:59:22 -0700419 request.result = true;
420 notifyRequester(request);
421 return;
422 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700423
Pengquan Meng0c05b502018-09-06 09:59:22 -0700424 try {
425 request.result = phone != null
426 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
427 } catch (CallStateException cse) {
428 request.result = false;
429 }
430 // Wake up the requesting thread
431 notifyRequester(request);
432 break;
pkanwar32d516d2016-10-14 19:37:38 -0700433 }
434
Yorke Lee716f67e2015-06-17 15:39:16 -0700435 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700437 final Phone phone = getPhoneFromRequest(request);
438 request.result = phone != null ?
439 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
440 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700442 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800449 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700450 if (uiccCard == null) {
451 loge("iccTransmitApduLogicalChannel: No UICC");
452 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700453 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700454 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
456 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 iccArgument.channel, iccArgument.cla, iccArgument.command,
459 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700461 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 break;
463
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 ar = (AsyncResult) msg.obj;
466 request = (MainThreadRequest) ar.userObj;
467 if (ar.exception == null && ar.result != null) {
468 request.result = ar.result;
469 } else {
470 request.result = new IccIoResult(0x6F, 0, (byte[])null);
471 if (ar.result == null) {
472 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800473 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800475 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 } else {
477 loge("iccTransmitApduLogicalChannel: Unknown exception");
478 }
479 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700480 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 break;
482
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
484 request = (MainThreadRequest) msg.obj;
485 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800486 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 if (uiccCard == null) {
488 loge("iccTransmitApduBasicChannel: No UICC");
489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700490 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 } else {
492 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
493 request);
494 uiccCard.iccTransmitApduBasicChannel(
495 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
496 iccArgument.p3, iccArgument.data, onCompleted);
497 }
498 break;
499
500 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result;
505 } else {
506 request.result = new IccIoResult(0x6F, 0, (byte[])null);
507 if (ar.result == null) {
508 loge("iccTransmitApduBasicChannel: Empty response");
509 } else if (ar.exception instanceof CommandException) {
510 loge("iccTransmitApduBasicChannel: CommandException: " +
511 ar.exception);
512 } else {
513 loge("iccTransmitApduBasicChannel: Unknown exception");
514 }
515 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700516 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700517 break;
518
519 case CMD_EXCHANGE_SIM_IO:
520 request = (MainThreadRequest) msg.obj;
521 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800522 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 if (uiccCard == null) {
524 loge("iccExchangeSimIO: No UICC");
525 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700526 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 } else {
528 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
529 request);
530 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
531 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
532 iccArgument.data, onCompleted);
533 }
534 break;
535
536 case EVENT_EXCHANGE_SIM_IO_DONE:
537 ar = (AsyncResult) msg.obj;
538 request = (MainThreadRequest) ar.userObj;
539 if (ar.exception == null && ar.result != null) {
540 request.result = ar.result;
541 } else {
542 request.result = new IccIoResult(0x6f, 0, (byte[])null);
543 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700544 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700545 break;
546
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 case CMD_SEND_ENVELOPE:
548 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800549 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 if (uiccCard == null) {
551 loge("sendEnvelopeWithStatus: No UICC");
552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700553 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 } else {
555 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
556 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
557 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800558 break;
559
560 case EVENT_SEND_ENVELOPE_DONE:
561 ar = (AsyncResult) msg.obj;
562 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700563 if (ar.exception == null && ar.result != null) {
564 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
567 if (ar.result == null) {
568 loge("sendEnvelopeWithStatus: Empty response");
569 } else if (ar.exception instanceof CommandException) {
570 loge("sendEnvelopeWithStatus: CommandException: " +
571 ar.exception);
572 } else {
573 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
574 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800575 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700576 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 break;
578
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 case CMD_OPEN_CHANNEL:
580 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800581 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800582 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 if (uiccCard == null) {
584 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800585 request.result = new IccOpenLogicalChannelResponse(-1,
586 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 } else {
589 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800590 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
591 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 break;
594
595 case EVENT_OPEN_CHANNEL_DONE:
596 ar = (AsyncResult) msg.obj;
597 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 int[] result = (int[]) ar.result;
601 int channelId = result[0];
602 byte[] selectResponse = null;
603 if (result.length > 1) {
604 selectResponse = new byte[result.length - 1];
605 for (int i = 1; i < result.length; ++i) {
606 selectResponse[i - 1] = (byte) result[i];
607 }
608 }
609 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 if (ar.result == null) {
613 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 if (ar.exception != null) {
616 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
617 }
618
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700619 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700620 if (ar.exception instanceof CommandException) {
621 CommandException.Error error =
622 ((CommandException) (ar.exception)).getCommandError();
623 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700624 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700625 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 }
628 }
629 openChannelResp = new IccOpenLogicalChannelResponse(
630 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700632 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case CMD_CLOSE_CHANNEL:
637 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800638 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 if (uiccCard == null) {
640 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900641 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 } else {
644 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
645 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
646 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
649 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800650 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
651 break;
652
653 case CMD_NV_READ_ITEM:
654 request = (MainThreadRequest) msg.obj;
655 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800656 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
657 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800658 break;
659
660 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 ar = (AsyncResult) msg.obj;
662 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800663 if (ar.exception == null && ar.result != null) {
664 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800666 request.result = "";
667 if (ar.result == null) {
668 loge("nvReadItem: Empty response");
669 } else if (ar.exception instanceof CommandException) {
670 loge("nvReadItem: CommandException: " +
671 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800673 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 }
675 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
Jake Hambye994d462014-02-03 13:10:13 -0800679 case CMD_NV_WRITE_ITEM:
680 request = (MainThreadRequest) msg.obj;
681 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
682 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800683 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700684 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800685 break;
686
687 case EVENT_NV_WRITE_ITEM_DONE:
688 handleNullReturnEvent(msg, "nvWriteItem");
689 break;
690
691 case CMD_NV_WRITE_CDMA_PRL:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800694 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800695 break;
696
697 case EVENT_NV_WRITE_CDMA_PRL_DONE:
698 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
699 break;
700
chen xu1cc0abe2018-10-26 17:39:23 -0700701 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800702 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700703 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800704 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800705 break;
706
chen xu1cc0abe2018-10-26 17:39:23 -0700707 case EVENT_RESET_MODEM_CONFIG_DONE:
708 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800709 break;
710
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 case CMD_GET_PREFERRED_NETWORK_TYPE:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700714 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800715 break;
716
717 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
718 ar = (AsyncResult) msg.obj;
719 request = (MainThreadRequest) ar.userObj;
720 if (ar.exception == null && ar.result != null) {
721 request.result = ar.result; // Integer
722 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800723 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 if (ar.result == null) {
725 loge("getPreferredNetworkType: Empty response");
726 } else if (ar.exception instanceof CommandException) {
727 loge("getPreferredNetworkType: CommandException: " +
728 ar.exception);
729 } else {
730 loge("getPreferredNetworkType: Unknown exception");
731 }
732 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700733 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800734 break;
735
736 case CMD_SET_PREFERRED_NETWORK_TYPE:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
739 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700740 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800741 break;
742
743 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
744 handleNullReturnEvent(msg, "setPreferredNetworkType");
745 break;
746
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000747 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
748 request = (MainThreadRequest)msg.obj;
749 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800750 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000751 break;
752
753 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
754 ar = (AsyncResult)msg.obj;
755 request = (MainThreadRequest)ar.userObj;
756 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700757 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000758 break;
759
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800760 case CMD_SET_VOICEMAIL_NUMBER:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
763 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800764 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
765 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800766 break;
767
768 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
769 handleNullReturnEvent(msg, "setVoicemailNumber");
770 break;
771
Stuart Scott54788802015-03-30 13:18:01 -0700772 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
775 request);
776 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
777 break;
778
779 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
780 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
781 break;
782
Shishir Agrawal302c8692015-06-19 13:49:39 -0700783 case CMD_PERFORM_NETWORK_SCAN:
784 request = (MainThreadRequest) msg.obj;
785 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
786 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
787 break;
788
789 case EVENT_PERFORM_NETWORK_SCAN_DONE:
790 ar = (AsyncResult) msg.obj;
791 request = (MainThreadRequest) ar.userObj;
792 CellNetworkScanResult cellScanResult;
793 if (ar.exception == null && ar.result != null) {
794 cellScanResult = new CellNetworkScanResult(
795 CellNetworkScanResult.STATUS_SUCCESS,
796 (List<OperatorInfo>) ar.result);
797 } else {
798 if (ar.result == null) {
799 loge("getCellNetworkScanResults: Empty response");
800 }
801 if (ar.exception != null) {
802 loge("getCellNetworkScanResults: Exception: " + ar.exception);
803 }
804 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
805 if (ar.exception instanceof CommandException) {
806 CommandException.Error error =
807 ((CommandException) (ar.exception)).getCommandError();
808 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
809 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
810 } else if (error == CommandException.Error.GENERIC_FAILURE) {
811 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
812 }
813 }
814 cellScanResult = new CellNetworkScanResult(errorCode, null);
815 }
816 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700817 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700818 break;
819
820 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
821 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700822 ManualNetworkSelectionArgument selArg =
823 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
825 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700826 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
827 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700828 break;
829
830 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700831 ar = (AsyncResult) msg.obj;
832 request = (MainThreadRequest) ar.userObj;
833 if (ar.exception == null) {
834 request.result = true;
835 } else {
836 request.result = false;
837 loge("setNetworkSelectionModeManual " + ar.exception);
838 }
839 notifyRequester(request);
840 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700841 break;
842
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700843 case CMD_GET_MODEM_ACTIVITY_INFO:
844 request = (MainThreadRequest) msg.obj;
845 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisc56281c2019-04-03 14:18:34 -0700846 if (defaultPhone != null) {
847 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
848 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700849 break;
850
851 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null && ar.result != null) {
855 request.result = ar.result;
856 } else {
857 if (ar.result == null) {
858 loge("queryModemActivityInfo: Empty response");
859 } else if (ar.exception instanceof CommandException) {
860 loge("queryModemActivityInfo: CommandException: " +
861 ar.exception);
862 } else {
863 loge("queryModemActivityInfo: Unknown exception");
864 }
865 }
Amit Mahajand4766222016-01-28 15:28:28 -0800866 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
867 if (request.result == null) {
868 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
869 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700870 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700871 break;
872
Meng Wang1a7c35a2016-05-05 20:56:15 -0700873 case CMD_SET_ALLOWED_CARRIERS:
874 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800875 CarrierRestrictionRules argument =
876 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700877 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800878 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700879 break;
880
881 case EVENT_SET_ALLOWED_CARRIERS_DONE:
882 ar = (AsyncResult) msg.obj;
883 request = (MainThreadRequest) ar.userObj;
884 if (ar.exception == null && ar.result != null) {
885 request.result = ar.result;
886 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800887 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
888 if (ar.exception instanceof CommandException) {
889 loge("setAllowedCarriers: CommandException: " + ar.exception);
890 CommandException.Error error =
891 ((CommandException) (ar.exception)).getCommandError();
892 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
893 request.result =
894 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
895 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700896 } else {
897 loge("setAllowedCarriers: Unknown exception");
898 }
899 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700900 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700901 break;
902
903 case CMD_GET_ALLOWED_CARRIERS:
904 request = (MainThreadRequest) msg.obj;
905 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800906 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700907 break;
908
909 case EVENT_GET_ALLOWED_CARRIERS_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result;
914 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800915 request.result = new IllegalStateException(
916 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700917 if (ar.result == null) {
918 loge("getAllowedCarriers: Empty response");
919 } else if (ar.exception instanceof CommandException) {
920 loge("getAllowedCarriers: CommandException: " +
921 ar.exception);
922 } else {
923 loge("getAllowedCarriers: Unknown exception");
924 }
925 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700926 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700927 break;
928
Nathan Haroldb3014052017-01-25 15:57:32 -0800929 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
930 ar = (AsyncResult) msg.obj;
931 request = (MainThreadRequest) ar.userObj;
932 if (ar.exception == null && ar.result != null) {
933 request.result = ar.result;
934 } else {
935 request.result = new IllegalArgumentException(
936 "Failed to retrieve Forbidden Plmns");
937 if (ar.result == null) {
938 loge("getForbiddenPlmns: Empty response");
939 } else {
940 loge("getForbiddenPlmns: Unknown exception");
941 }
942 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700943 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800944 break;
945
946 case CMD_GET_FORBIDDEN_PLMNS:
947 request = (MainThreadRequest) msg.obj;
948 uiccCard = getUiccCardFromRequest(request);
949 if (uiccCard == null) {
950 loge("getForbiddenPlmns() UiccCard is null");
951 request.result = new IllegalArgumentException(
952 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700953 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800954 break;
955 }
956 Integer appType = (Integer) request.argument;
957 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
958 if (uiccApp == null) {
959 loge("getForbiddenPlmns() no app with specified type -- "
960 + appType);
961 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700962 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800963 break;
964 } else {
965 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
966 + " specified type -- " + appType);
967 }
968 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
969 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
970 onCompleted);
971 break;
972
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000973 case CMD_SWITCH_SLOTS:
974 request = (MainThreadRequest) msg.obj;
975 int[] physicalSlots = (int[]) request.argument;
976 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
977 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
978 break;
979
980 case EVENT_SWITCH_SLOTS_DONE:
981 ar = (AsyncResult) msg.obj;
982 request = (MainThreadRequest) ar.userObj;
983 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700984 notifyRequester(request);
985 break;
986 case CMD_GET_NETWORK_SELECTION_MODE:
987 request = (MainThreadRequest) msg.obj;
988 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
989 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
990 break;
991
992 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 if (ar.exception != null) {
996 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
997 } else {
998 int mode = ((int[]) ar.result)[0];
999 if (mode == 0) {
1000 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1001 } else {
1002 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1003 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001004 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001005 notifyRequester(request);
1006 break;
1007 case CMD_GET_CDMA_ROAMING_MODE:
1008 request = (MainThreadRequest) msg.obj;
1009 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1010 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1011 break;
1012 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 if (ar.exception != null) {
1016 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1017 } else {
1018 request.result = ((int[]) ar.result)[0];
1019 }
1020 notifyRequester(request);
1021 break;
1022 case CMD_SET_CDMA_ROAMING_MODE:
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1025 int mode = (int) request.argument;
1026 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1027 break;
1028 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 request.result = ar.exception == null;
1032 notifyRequester(request);
1033 break;
1034 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1037 int subscriptionMode = (int) request.argument;
1038 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1039 break;
1040 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 request.result = ar.exception == null;
1044 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001045 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001046 case CMD_GET_ALL_CELL_INFO:
1047 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001048 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001049 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001050 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 case EVENT_GET_ALL_CELL_INFO_DONE:
1052 ar = (AsyncResult) msg.obj;
1053 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001054 // If a timeout occurs, the response will be null
1055 request.result = (ar.exception == null && ar.result != null)
1056 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 synchronized (request) {
1058 request.notifyAll();
1059 }
1060 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 case CMD_REQUEST_CELL_INFO_UPDATE:
1062 request = (MainThreadRequest) msg.obj;
1063 request.phone.requestCellInfoUpdate(request.workSource,
1064 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1065 break;
1066 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
1069 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1070 try {
1071 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001072 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001073 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1074 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001077 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001078 } else {
1079 // use the result as returned
1080 cb.onCellInfo((List<CellInfo>) ar.result);
1081 }
1082 } catch (RemoteException re) {
1083 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1084 }
1085 break;
1086 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001087 request = (MainThreadRequest) msg.obj;
1088 WorkSource ws = (WorkSource) request.argument;
1089 Phone phone = getPhoneFromRequest(request);
1090 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1091 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001093 ar = (AsyncResult) msg.obj;
1094 request = (MainThreadRequest) ar.userObj;
1095 if (ar.exception == null) {
1096 request.result = ar.result;
1097 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001098 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001099 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1100 ? new CdmaCellLocation() : new GsmCellLocation();
1101 }
1102
1103 synchronized (request) {
1104 request.notifyAll();
1105 }
1106 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001107 case CMD_MODEM_REBOOT:
1108 request = (MainThreadRequest) msg.obj;
1109 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001110 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001111 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001112 case EVENT_CMD_MODEM_REBOOT_DONE:
1113 handleNullReturnEvent(msg, "rebootModem");
1114 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001115 case CMD_REQUEST_ENABLE_MODEM:
1116 request = (MainThreadRequest) msg.obj;
1117 boolean enable = (boolean) request.argument;
1118 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001119 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001120 PhoneConfigurationManager.getInstance()
1121 .enablePhone(request.phone, enable, onCompleted);
1122 break;
1123 case EVENT_ENABLE_MODEM_DONE:
1124 ar = (AsyncResult) msg.obj;
1125 request = (MainThreadRequest) ar.userObj;
1126 request.result = (ar.exception == null);
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07001127 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001128 //update the cache as modem status has changed
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07001129 if ((boolean) request.result) {
1130 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1131 updateModemStateMetrics();
1132 } else {
1133 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1134 + ar.exception);
1135 }
1136 notifyRequester(request);
1137 break;
1138 case CMD_GET_MODEM_STATUS:
1139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1141 PhoneConfigurationManager.getInstance()
1142 .getPhoneStatusFromModem(request.phone, onCompleted);
1143 break;
1144 case EVENT_GET_MODEM_STATUS_DONE:
1145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
1147 int id = request.phone.getPhoneId();
1148 if (ar.exception == null && ar.result != null) {
1149 request.result = ar.result;
1150 //update the cache as modem status has changed
1151 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1152 (boolean) request.result);
1153 } else {
1154 // Return true if modem status cannot be retrieved. For most cases,
1155 // modem status is on. And for older version modems, GET_MODEM_STATUS
1156 // and disable modem are not supported. Modem is always on.
1157 // TODO: this should be fixed in R to support a third
1158 // status UNKNOWN b/131631629
1159 request.result = true;
1160 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1161 + ar.exception);
1162 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08001163 notifyRequester(request);
1164 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001165 default:
1166 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1167 break;
1168 }
1169 }
Jake Hambye994d462014-02-03 13:10:13 -08001170
Pengquan Meng0c05b502018-09-06 09:59:22 -07001171 private void notifyRequester(MainThreadRequest request) {
1172 synchronized (request) {
1173 request.notifyAll();
1174 }
1175 }
1176
Jake Hambye994d462014-02-03 13:10:13 -08001177 private void handleNullReturnEvent(Message msg, String command) {
1178 AsyncResult ar = (AsyncResult) msg.obj;
1179 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1180 if (ar.exception == null) {
1181 request.result = true;
1182 } else {
1183 request.result = false;
1184 if (ar.exception instanceof CommandException) {
1185 loge(command + ": CommandException: " + ar.exception);
1186 } else {
1187 loge(command + ": Unknown exception");
1188 }
1189 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001190 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 }
1193
1194 /**
1195 * Posts the specified command to be executed on the main thread,
1196 * waits for the request to complete, and returns the result.
1197 * @see #sendRequestAsync
1198 */
1199 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001200 return sendRequest(
1201 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001202 }
1203
1204 /**
1205 * Posts the specified command to be executed on the main thread,
1206 * waits for the request to complete, and returns the result.
1207 * @see #sendRequestAsync
1208 */
1209 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1210 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001211 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001212 }
1213
1214 /**
1215 * Posts the specified command to be executed on the main thread,
1216 * waits for the request to complete, and returns the result.
1217 * @see #sendRequestAsync
1218 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001219 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001220 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001221 }
1222
1223 /**
1224 * Posts the specified command to be executed on the main thread,
1225 * waits for the request to complete, and returns the result.
1226 * @see #sendRequestAsync
1227 */
Nathan Harold92bed182018-10-12 18:16:49 -07001228 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1229 return sendRequest(command, argument, subId, null, workSource);
1230 }
1231
1232 /**
1233 * Posts the specified command to be executed on the main thread,
1234 * waits for the request to complete, and returns the result.
1235 * @see #sendRequestAsync
1236 */
1237 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1238 return sendRequest(
1239 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1240 }
1241
1242 /**
1243 * Posts the specified command to be executed on the main thread,
1244 * waits for the request to complete, and returns the result.
1245 * @see #sendRequestAsync
1246 */
1247 private Object sendRequest(
1248 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1250 throw new RuntimeException("This method will deadlock if called from the main thread.");
1251 }
1252
Nathan Harold92bed182018-10-12 18:16:49 -07001253 MainThreadRequest request = null;
1254 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1255 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1256 } else if (phone != null) {
1257 request = new MainThreadRequest(argument, phone, workSource);
1258 } else {
1259 request = new MainThreadRequest(argument, subId, workSource);
1260 }
1261
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 Message msg = mMainThreadHandler.obtainMessage(command, request);
1263 msg.sendToTarget();
1264
1265 // Wait for the request to complete
1266 synchronized (request) {
1267 while (request.result == null) {
1268 try {
1269 request.wait();
1270 } catch (InterruptedException e) {
1271 // Do nothing, go back and wait until the request is complete
1272 }
1273 }
1274 }
1275 return request.result;
1276 }
1277
1278 /**
1279 * Asynchronous ("fire and forget") version of sendRequest():
1280 * Posts the specified command to be executed on the main thread, and
1281 * returns immediately.
1282 * @see #sendRequest
1283 */
1284 private void sendRequestAsync(int command) {
1285 mMainThreadHandler.sendEmptyMessage(command);
1286 }
1287
1288 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001289 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001290 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001291 */
1292 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001293 sendRequestAsync(command, argument, null, null);
1294 }
1295
1296 /**
1297 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1298 * @see {@link #sendRequest(int,Object)}
1299 */
1300 private void sendRequestAsync(
1301 int command, Object argument, Phone phone, WorkSource workSource) {
1302 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001303 Message msg = mMainThreadHandler.obtainMessage(command, request);
1304 msg.sendToTarget();
1305 }
1306
1307 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 * Initialize the singleton PhoneInterfaceManager instance.
1309 * This is only done once, at startup, from PhoneApp.onCreate().
1310 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001311 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 synchronized (PhoneInterfaceManager.class) {
1313 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001314 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 } else {
1316 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1317 }
1318 return sInstance;
1319 }
1320 }
1321
1322 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001323 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001325 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001326 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1328 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001329 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001330 mTelephonySharedPreferences =
1331 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001332 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001333 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001334
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335 publish();
1336 }
1337
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001338 private Phone getDefaultPhone() {
1339 Phone thePhone = getPhone(getDefaultSubscription());
1340 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1341 }
1342
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 private void publish() {
1344 if (DBG) log("publish: " + this);
1345
1346 ServiceManager.addService("phone", this);
1347 }
1348
Stuart Scott584921c2015-01-15 17:10:34 -08001349 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu73b078d2019-02-28 12:03:40 -08001350 if (request.phone != null) {
1351 return request.phone;
1352 } else {
1353 return getPhoneFromSubId(request.subId);
1354 }
1355 }
1356
1357 private Phone getPhoneFromSubId(int subId) {
1358 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1359 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001360 }
1361
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001362 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1363 Phone phone = getPhoneFromRequest(request);
1364 return phone == null ? null :
1365 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1366 }
1367
Wink Saville36469e72014-06-11 15:17:00 -07001368 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001369 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001370 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372
1373 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001374 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001375 }
1376
Wink Savilleb564aae2014-10-23 10:18:09 -07001377 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 if (DBG) log("dial: " + number);
1379 // No permission check needed here: This is just a wrapper around the
1380 // ACTION_DIAL intent, which is available to any app since it puts up
1381 // the UI before it does anything.
1382
Malcolm Chend965c8b2018-02-28 15:00:40 -08001383 final long identity = Binder.clearCallingIdentity();
1384 try {
1385 String url = createTelUrl(number);
1386 if (url == null) {
1387 return;
1388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001389
Malcolm Chend965c8b2018-02-28 15:00:40 -08001390 // PENDING: should we just silently fail if phone is offhook or ringing?
1391 PhoneConstants.State state = mCM.getState(subId);
1392 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1393 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1394 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1395 mApp.startActivity(intent);
1396 }
1397 } finally {
1398 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001399 }
1400 }
1401
1402 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001403 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001404 }
1405
Wink Savilleb564aae2014-10-23 10:18:09 -07001406 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 if (DBG) log("call: " + number);
1408
1409 // This is just a wrapper around the ACTION_CALL intent, but we still
1410 // need to do a permission check since we're calling startActivity()
1411 // from the context of the phone app.
1412 enforceCallPermission();
1413
Jordan Liu1617b712019-07-10 15:06:26 -07001414 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415 != AppOpsManager.MODE_ALLOWED) {
1416 return;
1417 }
1418
Malcolm Chend965c8b2018-02-28 15:00:40 -08001419 final long identity = Binder.clearCallingIdentity();
1420 try {
1421 String url = createTelUrl(number);
1422 if (url == null) {
1423 return;
1424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425
Malcolm Chend965c8b2018-02-28 15:00:40 -08001426 boolean isValid = false;
1427 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1428 if (slist != null) {
1429 for (SubscriptionInfo subInfoRecord : slist) {
1430 if (subInfoRecord.getSubscriptionId() == subId) {
1431 isValid = true;
1432 break;
1433 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001434 }
Wink Saville08874612014-08-31 19:19:58 -07001435 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001436 if (!isValid) {
1437 return;
1438 }
Wink Saville08874612014-08-31 19:19:58 -07001439
Malcolm Chend965c8b2018-02-28 15:00:40 -08001440 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1441 intent.putExtra(SUBSCRIPTION_KEY, subId);
1442 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1443 mApp.startActivity(intent);
1444 } finally {
1445 Binder.restoreCallingIdentity(identity);
1446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001447 }
1448
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001450 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001451 }
1452
Wink Savilleb564aae2014-10-23 10:18:09 -07001453 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001455 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1456 }
1457
1458 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001459 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001460 }
1461
Wink Savilleb564aae2014-10-23 10:18:09 -07001462 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001463 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001464 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1465 }
1466
1467 /** {@hide} */
1468 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001469 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001470 }
1471
Wink Savilleb564aae2014-10-23 10:18:09 -07001472 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001474
1475 final long identity = Binder.clearCallingIdentity();
1476 try {
1477 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1478 checkSimPin.start();
1479 return checkSimPin.unlockSim(null, pin);
1480 } finally {
1481 Binder.restoreCallingIdentity(identity);
1482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484
Wink Saville9de0f752013-10-22 19:04:03 -07001485 /** {@hide} */
1486 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001487 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001488 }
1489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001492
1493 final long identity = Binder.clearCallingIdentity();
1494 try {
1495 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1496 checkSimPuk.start();
1497 return checkSimPuk.unlockSim(puk, pin);
1498 } finally {
1499 Binder.restoreCallingIdentity(identity);
1500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 }
1502
1503 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001504 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505 * a synchronous one.
1506 */
1507 private static class UnlockSim extends Thread {
1508
1509 private final IccCard mSimCard;
1510
1511 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001512 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1513 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001514
1515 // For replies from SimCard interface
1516 private Handler mHandler;
1517
1518 // For async handler to identify request type
1519 private static final int SUPPLY_PIN_COMPLETE = 100;
1520
1521 public UnlockSim(IccCard simCard) {
1522 mSimCard = simCard;
1523 }
1524
1525 @Override
1526 public void run() {
1527 Looper.prepare();
1528 synchronized (UnlockSim.this) {
1529 mHandler = new Handler() {
1530 @Override
1531 public void handleMessage(Message msg) {
1532 AsyncResult ar = (AsyncResult) msg.obj;
1533 switch (msg.what) {
1534 case SUPPLY_PIN_COMPLETE:
1535 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1536 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001537 mRetryCount = msg.arg1;
1538 if (ar.exception != null) {
1539 if (ar.exception instanceof CommandException &&
1540 ((CommandException)(ar.exception)).getCommandError()
1541 == CommandException.Error.PASSWORD_INCORRECT) {
1542 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1543 } else {
1544 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1545 }
1546 } else {
1547 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001549 mDone = true;
1550 UnlockSim.this.notifyAll();
1551 }
1552 break;
1553 }
1554 }
1555 };
1556 UnlockSim.this.notifyAll();
1557 }
1558 Looper.loop();
1559 }
1560
1561 /*
1562 * Use PIN or PUK to unlock SIM card
1563 *
1564 * If PUK is null, unlock SIM card with PIN
1565 *
1566 * If PUK is not null, unlock SIM card with PUK and set PIN code
1567 */
Wink Saville9de0f752013-10-22 19:04:03 -07001568 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569
1570 while (mHandler == null) {
1571 try {
1572 wait();
1573 } catch (InterruptedException e) {
1574 Thread.currentThread().interrupt();
1575 }
1576 }
1577 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1578
1579 if (puk == null) {
1580 mSimCard.supplyPin(pin, callback);
1581 } else {
1582 mSimCard.supplyPuk(puk, pin, callback);
1583 }
1584
1585 while (!mDone) {
1586 try {
1587 Log.d(LOG_TAG, "wait for done");
1588 wait();
1589 } catch (InterruptedException e) {
1590 // Restore the interrupted status
1591 Thread.currentThread().interrupt();
1592 }
1593 }
1594 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001595 int[] resultArray = new int[2];
1596 resultArray[0] = mResult;
1597 resultArray[1] = mRetryCount;
1598 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 }
1600 }
1601
1602 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001603 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001604
1605 }
1606
Wink Savilleb564aae2014-10-23 10:18:09 -07001607 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 // No permission check needed here: this call is harmless, and it's
1609 // needed for the ServiceState.requestStateUpdate() call (which is
1610 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001611 final long identity = Binder.clearCallingIdentity();
1612 try {
1613 final Phone phone = getPhone(subId);
1614 if (phone != null) {
1615 phone.updateServiceLocation();
1616 }
1617 } finally {
1618 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 }
1621
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001622 @Override
1623 public boolean isRadioOn(String callingPackage) {
1624 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001625 }
1626
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001627 @Override
1628 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001630 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001631 return false;
1632 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001633
1634 final long identity = Binder.clearCallingIdentity();
1635 try {
1636 return isRadioOnForSubscriber(subId);
1637 } finally {
1638 Binder.restoreCallingIdentity(identity);
1639 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001640 }
1641
1642 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001643 final long identity = Binder.clearCallingIdentity();
1644 try {
1645 final Phone phone = getPhone(subId);
1646 if (phone != null) {
1647 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1648 } else {
1649 return false;
1650 }
1651 } finally {
1652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 }
1655
1656 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001657 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
Wink Saville36469e72014-06-11 15:17:00 -07001659
Wink Savilleb564aae2014-10-23 10:18:09 -07001660 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001662
1663 final long identity = Binder.clearCallingIdentity();
1664 try {
1665 final Phone phone = getPhone(subId);
1666 if (phone != null) {
1667 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1668 }
1669 } finally {
1670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001671 }
Wink Saville36469e72014-06-11 15:17:00 -07001672 }
1673
1674 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001675 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001676 }
1677
Wink Savilleb564aae2014-10-23 10:18:09 -07001678 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001679 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001680
1681 final long identity = Binder.clearCallingIdentity();
1682 try {
1683 final Phone phone = getPhone(subId);
1684 if (phone == null) {
1685 return false;
1686 }
1687 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1688 toggleRadioOnOffForSubscriber(subId);
1689 }
1690 return true;
1691 } finally {
1692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 }
Wink Saville36469e72014-06-11 15:17:00 -07001695
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001696 public boolean needMobileRadioShutdown() {
1697 /*
1698 * If any of the Radios are available, it will need to be
1699 * shutdown. So return true if any Radio is available.
1700 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001701 final long identity = Binder.clearCallingIdentity();
1702 try {
1703 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1704 Phone phone = PhoneFactory.getPhone(i);
1705 if (phone != null && phone.isRadioAvailable()) return true;
1706 }
1707 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1708 return false;
1709 } finally {
1710 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001711 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001712 }
1713
Malcolm Chend965c8b2018-02-28 15:00:40 -08001714 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001715 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001716 enforceModifyPermission();
1717
1718 final long identity = Binder.clearCallingIdentity();
1719 try {
1720 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1721 logv("Shutting down Phone " + i);
1722 shutdownRadioUsingPhoneId(i);
1723 }
1724 } finally {
1725 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001726 }
1727 }
1728
1729 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001730 Phone phone = PhoneFactory.getPhone(phoneId);
1731 if (phone != null && phone.isRadioAvailable()) {
1732 phone.shutdownRadio();
1733 }
1734 }
1735
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001737 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001738
1739 final long identity = Binder.clearCallingIdentity();
1740 try {
1741 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1742 if (defaultPhone != null) {
1743 defaultPhone.setRadioPower(turnOn);
1744 return true;
1745 } else {
1746 loge("There's no default phone.");
1747 return false;
1748 }
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001751 }
Wink Saville36469e72014-06-11 15:17:00 -07001752 }
1753
Wink Savilleb564aae2014-10-23 10:18:09 -07001754 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001756
1757 final long identity = Binder.clearCallingIdentity();
1758 try {
1759 final Phone phone = getPhone(subId);
1760 if (phone != null) {
1761 phone.setRadioPower(turnOn);
1762 return true;
1763 } else {
1764 return false;
1765 }
1766 } finally {
1767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
1770
Wink Saville36469e72014-06-11 15:17:00 -07001771 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001772 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 public boolean enableDataConnectivity() {
1774 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001775
1776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 int subId = mSubscriptionController.getDefaultDataSubId();
1779 final Phone phone = getPhone(subId);
1780 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001781 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001782 return true;
1783 } else {
1784 return false;
1785 }
1786 } finally {
1787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
1790
Wink Saville36469e72014-06-11 15:17:00 -07001791 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001792 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 public boolean disableDataConnectivity() {
1794 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001795
1796 final long identity = Binder.clearCallingIdentity();
1797 try {
1798 int subId = mSubscriptionController.getDefaultDataSubId();
1799 final Phone phone = getPhone(subId);
1800 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001801 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001802 return true;
1803 } else {
1804 return false;
1805 }
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
Sanket Padawe356d7632015-06-22 14:03:32 -07001811 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001812 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001813 final long identity = Binder.clearCallingIdentity();
1814 try {
1815 final Phone phone = getPhone(subId);
1816 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001817 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001818 } else {
1819 return false;
1820 }
1821 } finally {
1822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
1825
1826 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001827 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001828 }
1829
pkanwarae03a6b2016-11-06 20:37:09 -08001830 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001831 enforceCallPermission();
1832
1833 final long identity = Binder.clearCallingIdentity();
1834 try {
1835 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1836 return;
1837 }
1838 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1839 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1840 } finally {
1841 Binder.restoreCallingIdentity(identity);
1842 }
pkanwar32d516d2016-10-14 19:37:38 -07001843 };
1844
Wink Savilleb564aae2014-10-23 10:18:09 -07001845 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001847
1848 final long identity = Binder.clearCallingIdentity();
1849 try {
1850 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1851 return false;
1852 }
1853 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1854 } finally {
1855 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 }
1858
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001860 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001861 }
1862
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001863 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001864 final long identity = Binder.clearCallingIdentity();
1865 try {
1866 Phone phone = PhoneFactory.getPhone(slotIndex);
1867 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1868 PhoneConstantConversions.convertCallState(phone.getState());
1869 } finally {
1870 Binder.restoreCallingIdentity(identity);
1871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 }
1873
Sanket Padawe356d7632015-06-22 14:03:32 -07001874 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001875 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001876 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1877 }
1878
1879 @Override
1880 public int getDataStateForSubId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001881 final long identity = Binder.clearCallingIdentity();
1882 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001883 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001884 if (phone != null) {
1885 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1886 } else {
1887 return PhoneConstantConversions.convertDataState(
1888 PhoneConstants.DataState.DISCONNECTED);
1889 }
1890 } finally {
1891 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 }
1894
Sanket Padawe356d7632015-06-22 14:03:32 -07001895 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001896 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001897 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1898 }
1899
1900 @Override
1901 public int getDataActivityForSubId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001902 final long identity = Binder.clearCallingIdentity();
1903 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001904 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001905 if (phone != null) {
1906 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1907 } else {
1908 return TelephonyManager.DATA_ACTIVITY_NONE;
1909 }
1910 } finally {
1911 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 }
1914
1915 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001916 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001917 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001918 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001919
1920 LocationAccessPolicy.LocationPermissionResult locationResult =
1921 LocationAccessPolicy.checkLocationPermission(mApp,
1922 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1923 .setCallingPackage(callingPackage)
1924 .setCallingPid(Binder.getCallingPid())
1925 .setCallingUid(Binder.getCallingUid())
1926 .setMethod("getCellLocation")
1927 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1928 .build());
1929 switch (locationResult) {
1930 case DENIED_HARD:
1931 throw new SecurityException("Not allowed to access cell location");
1932 case DENIED_SOFT:
1933 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 }
1935
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001936 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001937 final long identity = Binder.clearCallingIdentity();
1938 try {
1939 if (DBG_LOC) log("getCellLocation: is active user");
1940 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001941 int subId = mSubscriptionController.getDefaultDataSubId();
1942 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1943 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001944 return data;
1945 } finally {
1946 Binder.restoreCallingIdentity(identity);
1947 }
Svetoslav64fad262015-04-14 14:35:21 -07001948 }
1949
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001951 public String getNetworkCountryIsoForPhone(int phoneId) {
1952 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1953 // registered cell info, so return a NULL country instead.
1954 final long identity = Binder.clearCallingIdentity();
1955 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001956 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1957 // Get default phone in this case.
1958 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1959 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001960 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001961 // Todo: fix this when we can get the actual cellular network info when the device
1962 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001963 if (TelephonyManager.NETWORK_TYPE_IWLAN
1964 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1965 return "";
1966 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001967 Phone phone = PhoneFactory.getPhone(phoneId);
1968 if (phone != null) {
1969 ServiceStateTracker sst = phone.getServiceStateTracker();
1970 if (sst != null) {
1971 LocaleTracker lt = sst.getLocaleTracker();
1972 if (lt != null) {
1973 return lt.getCurrentCountry();
1974 }
1975 }
1976 }
1977 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001978 } finally {
1979 Binder.restoreCallingIdentity(identity);
1980 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001981 }
1982
1983 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001985 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001986 }
1987
Sanket Padawe356d7632015-06-22 14:03:32 -07001988 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001989 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990 mApp.enforceCallingOrSelfPermission(
1991 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001992
1993 final long identity = Binder.clearCallingIdentity();
1994 try {
1995 final Phone phone = getPhone(subId);
1996 if (phone != null) {
1997 phone.enableLocationUpdates();
1998 }
1999 } finally {
2000 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002 }
2003
2004 @Override
2005 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002006 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002007 }
2008
Sanket Padawe356d7632015-06-22 14:03:32 -07002009 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002010 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 mApp.enforceCallingOrSelfPermission(
2012 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002013
2014 final long identity = Binder.clearCallingIdentity();
2015 try {
2016 final Phone phone = getPhone(subId);
2017 if (phone != null) {
2018 phone.disableLocationUpdates();
2019 }
2020 } finally {
2021 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002022 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002023 }
2024
Nathan Harold31d7ff32018-10-15 20:20:30 -07002025 /**
2026 * Returns the target SDK version number for a given package name.
2027 *
Nathan Haroldec184742019-07-10 17:04:16 -07002028 * This call MUST be invoked before clearing the calling UID.
2029 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002030 * @return target SDK if the package is found or INT_MAX.
2031 */
2032 private int getTargetSdk(String packageName) {
2033 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002034 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
2035 packageName, 0, UserHandle.getUserId(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002036 if (ai != null) return ai.targetSdkVersion;
2037 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002038 loge("Failed to get package info for pkg="
2039 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002040 }
2041 return Integer.MAX_VALUE;
2042 }
2043
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044 @Override
2045 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002046 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2047 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002048 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2049 throw new SecurityException(
2050 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2051 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002052
Jordan Liu1617b712019-07-10 15:06:26 -07002053 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002054 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2055 return null;
2056 }
Svetoslav64fad262015-04-14 14:35:21 -07002057
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002058 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002059
Nathan Haroldf180aac2018-06-01 18:43:55 -07002060 List<CellInfo> info = getAllCellInfo(callingPackage);
2061 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002062
Nathan Haroldf180aac2018-06-01 18:43:55 -07002063 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2064 for (CellInfo ci : info) {
2065 if (ci instanceof CellInfoGsm) {
2066 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2067 } else if (ci instanceof CellInfoWcdma) {
2068 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2069 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002070 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002071 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 }
2073
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002074 private List<CellInfo> getCachedCellInfo() {
2075 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2076 for (Phone phone : PhoneFactory.getPhones()) {
2077 List<CellInfo> info = phone.getAllCellInfo();
2078 if (info != null) cellInfos.addAll(info);
2079 }
2080 return cellInfos;
2081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082
2083 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002084 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002085 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002086 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002087
2088 LocationAccessPolicy.LocationPermissionResult locationResult =
2089 LocationAccessPolicy.checkLocationPermission(mApp,
2090 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2091 .setCallingPackage(callingPackage)
2092 .setCallingPid(Binder.getCallingPid())
2093 .setCallingUid(Binder.getCallingUid())
2094 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002095 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002096 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2097 .build());
2098 switch (locationResult) {
2099 case DENIED_HARD:
2100 throw new SecurityException("Not allowed to access cell info");
2101 case DENIED_SOFT:
2102 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103 }
2104
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002105 final int targetSdk = getTargetSdk(callingPackage);
2106 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2107 return getCachedCellInfo();
2108 }
2109
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002110 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002111 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002112 final long identity = Binder.clearCallingIdentity();
2113 try {
2114 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2115 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002116 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002117 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002118 if (info != null) cellInfos.addAll(info);
2119 }
2120 return cellInfos;
2121 } finally {
2122 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 }
2124 }
2125
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002126 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002127 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2128 requestCellInfoUpdateInternal(
2129 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2130 }
2131
2132 @Override
2133 public void requestCellInfoUpdateWithWorkSource(
2134 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2135 enforceModifyPermission();
2136 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2137 }
2138
2139 private void requestCellInfoUpdateInternal(
2140 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002141 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002142 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002143
2144 LocationAccessPolicy.LocationPermissionResult locationResult =
2145 LocationAccessPolicy.checkLocationPermission(mApp,
2146 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2147 .setCallingPackage(callingPackage)
2148 .setCallingPid(Binder.getCallingPid())
2149 .setCallingUid(Binder.getCallingUid())
2150 .setMethod("requestCellInfoUpdate")
2151 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2152 .build());
2153 switch (locationResult) {
2154 case DENIED_HARD:
2155 throw new SecurityException("Not allowed to access cell info");
2156 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002157 try {
2158 cb.onCellInfo(new ArrayList<CellInfo>());
2159 } catch (RemoteException re) {
2160 // Drop without consequences
2161 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002162 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002163 }
2164
Nathan Harolda939a962019-05-09 10:13:47 -07002165
2166 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002167 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2168
2169 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2170 }
2171
2172 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002174 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002175 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002176
2177 final long identity = Binder.clearCallingIdentity();
2178 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002179 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002180 } finally {
2181 Binder.restoreCallingIdentity(identity);
2182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 }
2184
Shishir Agrawala9f32182016-04-12 12:00:16 -07002185 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002186 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002187 Phone phone = PhoneFactory.getPhone(slotIndex);
2188 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002189 return null;
2190 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002191 int subId = phone.getSubId();
2192 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2193 mApp, subId, callingPackage, "getImeiForSlot")) {
2194 return null;
2195 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002196
2197 final long identity = Binder.clearCallingIdentity();
2198 try {
2199 return phone.getImei();
2200 } finally {
2201 Binder.restoreCallingIdentity(identity);
2202 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002203 }
2204
2205 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002206 public String getTypeAllocationCodeForSlot(int slotIndex) {
2207 Phone phone = PhoneFactory.getPhone(slotIndex);
2208 String tac = null;
2209 if (phone != null) {
2210 String imei = phone.getImei();
2211 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2212 }
2213 return tac;
2214 }
2215
2216 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002217 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002218 Phone phone = PhoneFactory.getPhone(slotIndex);
2219 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002220 return null;
2221 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002222
Jeff Davidson913390f2018-02-23 17:11:49 -08002223 int subId = phone.getSubId();
2224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2225 mApp, subId, callingPackage, "getMeidForSlot")) {
2226 return null;
2227 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002228
2229 final long identity = Binder.clearCallingIdentity();
2230 try {
2231 return phone.getMeid();
2232 } finally {
2233 Binder.restoreCallingIdentity(identity);
2234 }
Jack Yu2af8d712017-03-15 17:14:14 -07002235 }
2236
2237 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002238 public String getManufacturerCodeForSlot(int slotIndex) {
2239 Phone phone = PhoneFactory.getPhone(slotIndex);
2240 String manufacturerCode = null;
2241 if (phone != null) {
2242 String meid = phone.getMeid();
2243 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2244 }
2245 return manufacturerCode;
2246 }
2247
2248 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002249 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002250 Phone phone = PhoneFactory.getPhone(slotIndex);
2251 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002252 return null;
2253 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002254 int subId = phone.getSubId();
2255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2256 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2257 return null;
2258 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002259
2260 final long identity = Binder.clearCallingIdentity();
2261 try {
2262 return phone.getDeviceSvn();
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
2265 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002266 }
2267
fionaxu43304da2017-11-27 22:51:16 -08002268 @Override
2269 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002270 final long identity = Binder.clearCallingIdentity();
2271 try {
2272 final Phone phone = getPhone(subId);
2273 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2274 } finally {
2275 Binder.restoreCallingIdentity(identity);
2276 }
fionaxu43304da2017-11-27 22:51:16 -08002277 }
2278
2279 @Override
2280 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002281 final long identity = Binder.clearCallingIdentity();
2282 try {
2283 final Phone phone = getPhone(subId);
2284 return phone == null ? null : phone.getCarrierName();
2285 } finally {
2286 Binder.restoreCallingIdentity(identity);
2287 }
fionaxu43304da2017-11-27 22:51:16 -08002288 }
2289
calvinpaneed9ae82018-11-01 19:43:06 +08002290 @Override
chen xua31f22b2019-03-06 15:28:50 -08002291 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002292 final long identity = Binder.clearCallingIdentity();
2293 try {
2294 final Phone phone = getPhone(subId);
2295 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002296 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002297 } finally {
2298 Binder.restoreCallingIdentity(identity);
2299 }
2300 }
2301
2302 @Override
chen xua31f22b2019-03-06 15:28:50 -08002303 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002304 final long identity = Binder.clearCallingIdentity();
2305 try {
2306 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002307 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002308 } finally {
2309 Binder.restoreCallingIdentity(identity);
2310 }
2311 }
2312
chen xu02581692018-11-11 19:03:44 -08002313 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002314 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2315 if (!isSubscriptionMccMnc) {
2316 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2317 }
chen xu02581692018-11-11 19:03:44 -08002318 final Phone phone = PhoneFactory.getPhone(slotIndex);
2319 if (phone == null) {
2320 return TelephonyManager.UNKNOWN_CARRIER_ID;
2321 }
2322 final long identity = Binder.clearCallingIdentity();
2323 try {
2324 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2325 } finally {
2326 Binder.restoreCallingIdentity(identity);
2327 }
2328 }
2329
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 //
2331 // Internal helper methods.
2332 //
2333
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002334 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2336 *
2337 * @throws SecurityException if the caller does not have the required permission
2338 */
2339 private void enforceModifyPermission() {
2340 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2341 }
2342
2343 /**
2344 * Make sure the caller has the CALL_PHONE permission.
2345 *
2346 * @throws SecurityException if the caller does not have the required permission
2347 */
2348 private void enforceCallPermission() {
2349 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2350 }
2351
Stuart Scott8eef64f2015-04-08 15:13:54 -07002352 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002353 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002354 "ConnectivityService");
2355 }
2356
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 private String createTelUrl(String number) {
2358 if (TextUtils.isEmpty(number)) {
2359 return null;
2360 }
2361
Jake Hambye994d462014-02-03 13:10:13 -08002362 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 }
2364
Ihab Awadf9e92732013-12-05 18:02:52 -08002365 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2367 }
2368
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002369 private static void logv(String msg) {
2370 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2371 }
2372
Ihab Awadf9e92732013-12-05 18:02:52 -08002373 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2375 }
2376
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002377 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002379 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002380 }
2381
Sanket Padawe356d7632015-06-22 14:03:32 -07002382 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002383 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002384 final long identity = Binder.clearCallingIdentity();
2385 try {
2386 final Phone phone = PhoneFactory.getPhone(slotIndex);
2387 if (phone == null) {
2388 return PhoneConstants.PHONE_TYPE_NONE;
2389 } else {
2390 return phone.getPhoneType();
2391 }
2392 } finally {
2393 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002394 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 }
2396
2397 /**
2398 * Returns the CDMA ERI icon index to display
2399 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002400 @Override
2401 public int getCdmaEriIconIndex(String callingPackage) {
2402 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002403 }
2404
Sanket Padawe356d7632015-06-22 14:03:32 -07002405 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002406 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002408 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002409 return -1;
2410 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002411
2412 final long identity = Binder.clearCallingIdentity();
2413 try {
2414 final Phone phone = getPhone(subId);
2415 if (phone != null) {
2416 return phone.getCdmaEriIconIndex();
2417 } else {
2418 return -1;
2419 }
2420 } finally {
2421 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 }
2424
2425 /**
2426 * Returns the CDMA ERI icon mode,
2427 * 0 - ON
2428 * 1 - FLASHING
2429 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002430 @Override
2431 public int getCdmaEriIconMode(String callingPackage) {
2432 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002433 }
2434
Sanket Padawe356d7632015-06-22 14:03:32 -07002435 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002436 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002438 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002439 return -1;
2440 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002441
2442 final long identity = Binder.clearCallingIdentity();
2443 try {
2444 final Phone phone = getPhone(subId);
2445 if (phone != null) {
2446 return phone.getCdmaEriIconMode();
2447 } else {
2448 return -1;
2449 }
2450 } finally {
2451 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002452 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 }
2454
2455 /**
2456 * Returns the CDMA ERI text,
2457 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002458 @Override
2459 public String getCdmaEriText(String callingPackage) {
2460 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002461 }
2462
Sanket Padawe356d7632015-06-22 14:03:32 -07002463 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002464 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002466 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002467 return null;
2468 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002469
2470 final long identity = Binder.clearCallingIdentity();
2471 try {
2472 final Phone phone = getPhone(subId);
2473 if (phone != null) {
2474 return phone.getCdmaEriText();
2475 } else {
2476 return null;
2477 }
2478 } finally {
2479 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 }
2482
2483 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002484 * Returns the CDMA MDN.
2485 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002486 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002487 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2489 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002490
2491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002494 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002495 return phone.getLine1Number();
2496 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002497 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002498 return null;
2499 }
2500 } finally {
2501 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002502 }
2503 }
2504
2505 /**
2506 * Returns the CDMA MIN.
2507 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002508 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002509 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2511 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002512
2513 final long identity = Binder.clearCallingIdentity();
2514 try {
2515 final Phone phone = getPhone(subId);
2516 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2517 return phone.getCdmaMin();
2518 } else {
2519 return null;
2520 }
2521 } finally {
2522 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002523 }
2524 }
2525
Hall Liud892bec2018-11-30 14:51:45 -08002526 @Override
2527 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2528 INumberVerificationCallback callback, String callingPackage) {
2529 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2530 != PERMISSION_GRANTED) {
2531 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2532 }
2533 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2534
2535 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2536 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2537 throw new SecurityException("Calling package must be configured in the device config");
2538 }
2539
2540 if (range == null) {
2541 throw new NullPointerException("Range must be non-null");
2542 }
2543
2544 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002545 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002546
2547 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2548 }
2549
Junda Liuca05d5d2014-08-14 22:36:34 -07002550 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002551 * Returns true if CDMA provisioning needs to run.
2552 */
2553 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002554 final long identity = Binder.clearCallingIdentity();
2555 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002556 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002557 } finally {
2558 Binder.restoreCallingIdentity(identity);
2559 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002560 }
2561
2562 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002563 * Sets the voice mail number of a given subId.
2564 */
2565 @Override
2566 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002567 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2572 new Pair<String, String>(alphaTag, number), new Integer(subId));
2573 return success;
2574 } finally {
2575 Binder.restoreCallingIdentity(identity);
2576 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002577 }
2578
Ta-wei Yen87c49842016-05-13 21:19:52 -07002579 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002580 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2581 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002582 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002583 if (!TextUtils.equals(callingPackage, systemDialer)) {
2584 throw new SecurityException("caller must be system dialer");
2585 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002586
2587 final long identity = Binder.clearCallingIdentity();
2588 try {
2589 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2590 if (phoneAccountHandle == null) {
2591 return null;
2592 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002593 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002594 } finally {
2595 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002596 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002597 }
2598
2599 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002600 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002601 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002602 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002603 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002604 return null;
2605 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002606
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002607 final long identity = Binder.clearCallingIdentity();
2608 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002609 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002610 } finally {
2611 Binder.restoreCallingIdentity(identity);
2612 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002613 }
2614
2615 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002616 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2617 VisualVoicemailSmsFilterSettings settings) {
2618 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002619
2620 final long identity = Binder.clearCallingIdentity();
2621 try {
2622 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002623 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002624 } finally {
2625 Binder.restoreCallingIdentity(identity);
2626 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002627 }
2628
2629 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002630 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2631 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002632
2633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002636 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002637 } finally {
2638 Binder.restoreCallingIdentity(identity);
2639 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002640 }
2641
2642 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002643 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2644 String callingPackage, int subId) {
2645 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002646
2647 final long identity = Binder.clearCallingIdentity();
2648 try {
2649 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002650 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002651 } finally {
2652 Binder.restoreCallingIdentity(identity);
2653 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002654 }
2655
2656 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002657 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002658 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002659
2660 final long identity = Binder.clearCallingIdentity();
2661 try {
2662 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002663 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002664 } finally {
2665 Binder.restoreCallingIdentity(identity);
2666 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002667 }
2668
2669 @Override
2670 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2671 String number, int port, String text, PendingIntent sentIntent) {
2672 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002673 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002674 enforceSendSmsPermission();
Amit Mahajan716e76c2019-05-13 13:48:32 -07002675 SmsController smsController = PhoneFactory.getSmsController();
2676 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2677 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002678 }
Amit Mahajan716e76c2019-05-13 13:48:32 -07002679
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002680 /**
fionaxu0152e512016-11-14 13:36:14 -08002681 * Sets the voice activation state of a given subId.
2682 */
2683 @Override
2684 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2686 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002687
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 final Phone phone = getPhone(subId);
2691 if (phone != null) {
2692 phone.setVoiceActivationState(activationState);
2693 } else {
2694 loge("setVoiceActivationState fails with invalid subId: " + subId);
2695 }
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002698 }
2699 }
2700
2701 /**
2702 * Sets the data activation state of a given subId.
2703 */
2704 @Override
2705 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2707 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002708
2709 final long identity = Binder.clearCallingIdentity();
2710 try {
2711 final Phone phone = getPhone(subId);
2712 if (phone != null) {
2713 phone.setDataActivationState(activationState);
2714 } else {
2715 loge("setVoiceActivationState fails with invalid subId: " + subId);
2716 }
2717 } finally {
2718 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002719 }
2720 }
2721
2722 /**
2723 * Returns the voice activation state of a given subId.
2724 */
2725 @Override
2726 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002727 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002728
fionaxu0152e512016-11-14 13:36:14 -08002729 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002730 final long identity = Binder.clearCallingIdentity();
2731 try {
2732 if (phone != null) {
2733 return phone.getVoiceActivationState();
2734 } else {
2735 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2736 }
2737 } finally {
2738 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002739 }
2740 }
2741
2742 /**
2743 * Returns the data activation state of a given subId.
2744 */
2745 @Override
2746 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002747 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002748
fionaxu0152e512016-11-14 13:36:14 -08002749 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 if (phone != null) {
2753 return phone.getDataActivationState();
2754 } else {
2755 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2756 }
2757 } finally {
2758 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002759 }
2760 }
2761
2762 /**
Wink Saville36469e72014-06-11 15:17:00 -07002763 * Returns the unread count of voicemails for a subId
2764 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002765 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002766 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2768 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2769 return 0;
2770 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002771 final long identity = Binder.clearCallingIdentity();
2772 try {
2773 final Phone phone = getPhone(subId);
2774 if (phone != null) {
2775 return phone.getVoiceMessageCount();
2776 } else {
2777 return 0;
2778 }
2779 } finally {
2780 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002781 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002782 }
2783
2784 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002785 * returns true, if the device is in a state where both voice and data
2786 * are supported simultaneously. This can change based on location or network condition.
2787 */
2788 @Override
2789 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002790 final long identity = Binder.clearCallingIdentity();
2791 try {
2792 final Phone phone = getPhone(subId);
2793 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
2796 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002797 }
2798
2799 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002800 * Send the dialer code if called from the current default dialer or the caller has
2801 * carrier privilege.
2802 * @param inputCode The dialer code to send
2803 */
2804 @Override
2805 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002806 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002807 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002808 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2809 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002810 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002811 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2812 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002813 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002814
2815 final long identity = Binder.clearCallingIdentity();
2816 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002817 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002818 } finally {
2819 Binder.restoreCallingIdentity(identity);
2820 }
fionaxu235cc5e2017-03-06 22:25:57 -08002821 }
2822
Pengquan Meng0c05b502018-09-06 09:59:22 -07002823 @Override
2824 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002825 if (!isActiveSubscription(subId)) {
2826 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2827 }
2828
Pengquan Meng0c05b502018-09-06 09:59:22 -07002829 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2830 }
2831
Brad Ebinger4c460712018-10-01 10:40:55 -07002832 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002833 public boolean isInEmergencySmsMode() {
2834 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2835 final long identity = Binder.clearCallingIdentity();
2836 try {
2837 for (Phone phone : PhoneFactory.getPhones()) {
2838 if (phone.isInEmergencySmsMode()) {
2839 return true;
2840 }
2841 }
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
2844 }
2845 return false;
2846 }
2847
2848 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002849 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2850 throws RemoteException {
2851 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002852 final long token = Binder.clearCallingIdentity();
2853 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002855 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002856 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002857 } catch (ImsException e) {
2858 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07002859 } finally {
2860 Binder.restoreCallingIdentity(token);
2861 }
2862 }
2863
2864 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002865 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2866 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002867 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2868 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2869 }
2870 Binder.withCleanCallingIdentity(() -> {
2871 try {
2872 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002873 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002874 .removeRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002875 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002876 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2877 + "is inactive, ignoring unregister.");
2878 // If the subscription is no longer active, just return, since the callback
2879 // will already have been removed internally.
2880 }
2881 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002882 }
2883
2884 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002885 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2886 throws RemoteException {
2887 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002888 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2889 final long token = Binder.clearCallingIdentity();
2890 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002891 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002892 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002893 } catch (ImsException e) {
2894 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07002895 } finally {
2896 Binder.restoreCallingIdentity(token);
2897 }
2898 }
2899
2900 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002901 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2902 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002903
2904 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2905 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2906 }
2907 Binder.withCleanCallingIdentity(() -> {
2908 try {
2909 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002910 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002911 .removeCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002912 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002913 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2914 + "is inactive, ignoring unregister.");
2915 // If the subscription is no longer active, just return, since the callback
2916 // will already have been removed internally.
2917 }
2918 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002919 }
2920
2921 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002922 public boolean isCapable(int subId, int capability, int regTech) {
2923 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002924 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2925 final long token = Binder.clearCallingIdentity();
2926 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002927 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002928 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002929 } catch (com.android.ims.ImsException e) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002930 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2931 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002932 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002933 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2934 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002935 } finally {
2936 Binder.restoreCallingIdentity(token);
2937 }
2938 }
2939
2940 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002941 public boolean isAvailable(int subId, int capability, int regTech) {
2942 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002943 final long token = Binder.clearCallingIdentity();
2944 try {
2945 Phone phone = getPhone(subId);
2946 if (phone == null) return false;
2947 return phone.isImsCapabilityAvailable(capability, regTech);
2948 } finally {
2949 Binder.restoreCallingIdentity(token);
2950 }
2951 }
2952
2953 @Override
2954 public boolean isAdvancedCallingSettingEnabled(int subId) {
2955 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2956 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2957 final long token = Binder.clearCallingIdentity();
2958 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002959 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002960 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002961 } catch (ImsException e) {
2962 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07002963 } finally {
2964 Binder.restoreCallingIdentity(token);
2965 }
2966 }
2967
2968 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002969 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002971 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002975 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002976 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002977 } catch (ImsException e) {
2978 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07002979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002985 public boolean isVtSettingEnabled(int subId) {
2986 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002990 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
2991 } catch (ImsException e) {
2992 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07002993 } finally {
2994 Binder.restoreCallingIdentity(identity);
2995 }
2996 }
2997
2998 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002999 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003001 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003005 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003006 } catch (ImsException e) {
3007 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
3011 }
3012
3013 @Override
3014 public boolean isVoWiFiSettingEnabled(int subId) {
3015 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3016 final long identity = Binder.clearCallingIdentity();
3017 try {
3018 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003019 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003020 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003021 } catch (ImsException e) {
3022 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003023 } finally {
3024 Binder.restoreCallingIdentity(identity);
3025 }
3026 }
3027
3028 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003029 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003031 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003032 final long identity = Binder.clearCallingIdentity();
3033 try {
3034 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003035 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003036 } catch (ImsException e) {
3037 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
3041 }
3042
3043 @Override
3044 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3045 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003049 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003050 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003051 } catch (ImsException e) {
3052 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003053 } finally {
3054 Binder.restoreCallingIdentity(identity);
3055 }
3056 }
3057
3058 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003059 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003061 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003065 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003066 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003067 } catch (ImsException e) {
3068 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
3072 }
3073
3074 @Override
3075 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3077 "setVoWiFiNonPersistent");
3078 final long identity = Binder.clearCallingIdentity();
3079 try {
3080 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003081 ImsManager.getInstance(mApp,
Brad Ebinger2bc95702019-05-07 18:33:46 -07003082 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003083 } catch (ImsException e) {
3084 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003085 } finally {
3086 Binder.restoreCallingIdentity(identity);
3087 }
3088 }
3089
3090 @Override
3091 public int getVoWiFiModeSetting(int subId) {
3092 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3093 final long identity = Binder.clearCallingIdentity();
3094 try {
3095 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003096 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003097 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003098 } catch (ImsException e) {
3099 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003100 } finally {
3101 Binder.restoreCallingIdentity(identity);
3102 }
3103 }
3104
3105 @Override
3106 public void setVoWiFiModeSetting(int subId, int mode) {
3107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3108 "setVoWiFiModeSetting");
3109 final long identity = Binder.clearCallingIdentity();
3110 try {
3111 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003112 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003113 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003114 } catch (ImsException e) {
3115 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003116 } finally {
3117 Binder.restoreCallingIdentity(identity);
3118 }
3119 }
3120
3121 @Override
3122 public int getVoWiFiRoamingModeSetting(int subId) {
3123 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003127 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003128 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003129 } catch (ImsException e) {
3130 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003131 } finally {
3132 Binder.restoreCallingIdentity(identity);
3133 }
3134 }
3135
3136 @Override
3137 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3139 "setVoWiFiRoamingModeSetting");
3140 final long identity = Binder.clearCallingIdentity();
3141 try {
3142 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003143 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003144 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003145 } catch (ImsException e) {
3146 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003147 } finally {
3148 Binder.restoreCallingIdentity(identity);
3149 }
3150 }
3151
3152 @Override
3153 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3155 "setRttCapabilityEnabled");
3156 final long identity = Binder.clearCallingIdentity();
3157 try {
3158 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003159 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3160 } catch (ImsException e) {
3161 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003162 } finally {
3163 Binder.restoreCallingIdentity(identity);
3164 }
3165 }
3166
3167 @Override
3168 public boolean isTtyOverVolteEnabled(int subId) {
3169 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3170 final long identity = Binder.clearCallingIdentity();
3171 try {
3172 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003173 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003174 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003175 } catch (ImsException e) {
3176 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003177 } finally {
3178 Binder.restoreCallingIdentity(identity);
3179 }
3180 }
3181
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003182 @Override
3183 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3184 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003188 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003189 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003190 } catch (ImsException e) {
3191 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003192 } finally {
3193 Binder.restoreCallingIdentity(identity);
3194 }
3195 }
3196
3197 @Override
3198 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3199 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3200 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003201 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3202 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3203 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003204 try {
3205 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003206 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003207 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003208 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003209 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3210 + "is inactive, ignoring unregister.");
3211 // If the subscription is no longer active, just return, since the callback will already
3212 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
3216 }
3217
3218 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003219 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3220 boolean isProvisioned) {
3221 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3222 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3223 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3224 }
3225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3226 "setProvisioningStatusForCapability");
3227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3230 Phone phone = getPhone(subId);
3231 if (phone == null) {
3232 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3233 + subId);
3234 return;
3235 }
3236 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3237 return;
3238 }
3239
3240 // this capability requires provisioning, route to the correct API.
3241 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3242 switch (capability) {
3243 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3244 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3245 ims.setVolteProvisioned(isProvisioned);
3246 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3247 ims.setWfcProvisioned(isProvisioned);
3248 }
3249 break;
3250 }
3251 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3252 // There is currently no difference in VT provisioning type.
3253 ims.setVtProvisioned(isProvisioned);
3254 break;
3255 }
3256 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3257 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3258 // change the capability of the feature instead if needed.
3259 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3260 == isProvisioned) {
3261 // No change in provisioning.
3262 return;
3263 }
3264 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3265 try {
3266 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003267 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003268 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3269 + ", Exception" + e.getMessage());
3270 }
3271 break;
3272 }
3273 default: {
3274 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3275 + capability + "', which does not require provisioning.");
3276 }
3277 }
3278
3279 } finally {
3280 Binder.restoreCallingIdentity(identity);
3281 }
3282 }
3283
3284 @Override
3285 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3286 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3287 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3288 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3289 }
3290 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3291 final long identity = Binder.clearCallingIdentity();
3292 try {
3293 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3294 Phone phone = getPhone(subId);
3295 if (phone == null) {
3296 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3297 + subId);
3298 // We will fail with "true" as the provisioning status because this is the default
3299 // if we do not require provisioning.
3300 return true;
3301 }
3302
3303 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3304 return true;
3305 }
3306
3307 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3308 switch (capability) {
3309 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3310 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3311 return ims.isVolteProvisionedOnDevice();
3312 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3313 return ims.isWfcProvisionedOnDevice();
3314 }
3315 // This should never happen, since we are checking tech above to make sure it
3316 // is either LTE or IWLAN.
3317 throw new IllegalArgumentException("Invalid radio technology for voice "
3318 + "capability.");
3319 }
3320 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3321 // There is currently no difference in VT provisioning type.
3322 return ims.isVtProvisionedOnDevice();
3323 }
3324 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3325 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3326 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3327 }
3328 default: {
3329 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3330 + capability + "', which does not require provisioning.");
3331 }
3332 }
3333
3334 } finally {
3335 Binder.restoreCallingIdentity(identity);
3336 }
3337 }
3338
3339 @Override
3340 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3341 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3342 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3343 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3344 }
3345 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3346 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3347 return (provisionedBits & capability) > 0;
3348 }
3349
3350 @Override
3351 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3352 boolean isProvisioned) {
3353 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3354 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3355 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3356 }
3357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3358 "setProvisioningStatusForCapability");
3359 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3360 // If the current provisioning status for capability already matches isProvisioned,
3361 // do nothing.
3362 if (((provisionedBits & capability) > 0) == isProvisioned) {
3363 return;
3364 }
3365 if (isProvisioned) {
3366 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3367 } else {
3368 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3369 }
3370 }
3371
3372 /**
3373 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3374 * technology. The bitfield should mirror the bitfield defined by
3375 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3376 */
3377 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3378 String key = getMmTelProvisioningKey(subId, tech);
3379 // Default is no capabilities are provisioned.
3380 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3381 }
3382
3383 /**
3384 * Sets the MmTel capability provisioning bitfield (defined by
3385 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3386 * technology specified.
3387 *
3388 * Note: This is a synchronous command and should not be called on UI thread.
3389 */
3390 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3391 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3392 String key = getMmTelProvisioningKey(subId, tech);
3393 editor.putInt(key, newField);
3394 editor.commit();
3395 }
3396
3397 private static String getMmTelProvisioningKey(int subId, int tech) {
3398 // resulting key is provision_ims_mmtel_{subId}_{tech}
3399 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3400 }
3401
3402 /**
3403 * Query CarrierConfig to see if the specified capability requires provisioning for the
3404 * carrier associated with the subscription id.
3405 */
3406 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3407 int capability) {
3408 CarrierConfigManager configManager = new CarrierConfigManager(context);
3409 PersistableBundle c = configManager.getConfigForSubId(subId);
3410 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003411 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003412 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3413 false);
3414 boolean requireVoiceVtProvisioning = c.getBoolean(
3415 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3416
3417 // First check to make sure that the capability requires provisioning.
3418 switch (capability) {
3419 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3420 // intentional fallthrough
3421 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3422 if (requireVoiceVtProvisioning) {
3423 // Voice and Video requires provisioning
3424 return true;
3425 }
3426 break;
3427 }
3428 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3429 if (requireUtProvisioning) {
3430 // UT requires provisioning
3431 return true;
3432 }
3433 break;
3434 }
3435 }
3436 return false;
3437 }
3438
3439 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003440 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003441 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3442 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3443 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003444 enforceReadPrivilegedPermission("getImsProvisioningInt");
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003448 int slotId = getSlotIndex(subId);
3449 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3450 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3451 + subId + "' for key:" + key);
3452 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3453 }
3454 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003455 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003456 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3457 + subId + "' for key:" + key);
3458 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003459 } finally {
3460 Binder.restoreCallingIdentity(identity);
3461 }
3462 }
3463
3464 @Override
3465 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003466 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3467 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3468 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003469 enforceReadPrivilegedPermission("getImsProvisioningString");
3470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003473 int slotId = getSlotIndex(subId);
3474 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3475 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3476 + subId + "' for key:" + key);
3477 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3478 }
3479 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003480 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003481 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3482 + subId + "' for key:" + key);
3483 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003484 } finally {
3485 Binder.restoreCallingIdentity(identity);
3486 }
3487 }
3488
3489 @Override
3490 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003491 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3492 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3493 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3495 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003496 final long identity = Binder.clearCallingIdentity();
3497 try {
3498 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003499 int slotId = getSlotIndex(subId);
3500 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3501 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3502 + subId + "' for key:" + key);
3503 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3504 }
3505 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003506 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003507 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3508 + "' for key:" + key);
3509 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003510 } finally {
3511 Binder.restoreCallingIdentity(identity);
3512 }
3513 }
3514
3515 @Override
3516 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003517 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3518 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3519 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3521 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003522 final long identity = Binder.clearCallingIdentity();
3523 try {
3524 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003525 int slotId = getSlotIndex(subId);
3526 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3527 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3528 + subId + "' for key:" + key);
3529 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3530 }
3531 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003532 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003533 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3534 + "' for key:" + key);
3535 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003536 } finally {
3537 Binder.restoreCallingIdentity(identity);
3538 }
3539 }
3540
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003541 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger4c460712018-10-01 10:40:55 -07003542 int slotId = SubscriptionManager.getSlotIndex(subId);
3543 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003544 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3545 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger4c460712018-10-01 10:40:55 -07003546 }
3547 return slotId;
3548 }
3549
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003550 private int getSlotIndex(int subId) {
3551 int slotId = SubscriptionManager.getSlotIndex(subId);
3552 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3553 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3554 }
3555 return slotId;
3556 }
3557
Wink Saville36469e72014-06-11 15:17:00 -07003558 /**
Nathan Haroldb3a3a802019-05-21 15:51:27 -07003559 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003560 */
3561 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003562 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003563 final int targetSdk = getTargetSdk(callingPackage);
3564 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3565 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3566 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Haroldb3a3a802019-05-21 15:51:27 -07003567 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3568 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003569 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3570 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003571
Malcolm Chend965c8b2018-02-28 15:00:40 -08003572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 final Phone phone = getPhone(subId);
3575 if (phone != null) {
3576 return phone.getServiceState().getDataNetworkType();
3577 } else {
3578 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3579 }
3580 } finally {
3581 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003583 }
3584
3585 /**
3586 * Returns the data network type
3587 */
3588 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003589 public int getDataNetworkType(String callingPackage) {
3590 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003591 }
3592
3593 /**
3594 * Returns the data network type for a subId
3595 */
3596 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003597 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003598 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003599 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003600 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3601 }
3602
Malcolm Chend965c8b2018-02-28 15:00:40 -08003603 final long identity = Binder.clearCallingIdentity();
3604 try {
3605 final Phone phone = getPhone(subId);
3606 if (phone != null) {
3607 return phone.getServiceState().getDataNetworkType();
3608 } else {
3609 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3610 }
3611 } finally {
3612 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003614 }
3615
3616 /**
Wink Saville36469e72014-06-11 15:17:00 -07003617 * Returns the Voice network type for a subId
3618 */
3619 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003620 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003622 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003623 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3624 }
3625
Malcolm Chend965c8b2018-02-28 15:00:40 -08003626 final long identity = Binder.clearCallingIdentity();
3627 try {
3628 final Phone phone = getPhone(subId);
3629 if (phone != null) {
3630 return phone.getServiceState().getVoiceNetworkType();
3631 } else {
3632 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3633 }
3634 } finally {
3635 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003637 }
3638
3639 /**
3640 * @return true if a ICC card is present
3641 */
3642 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003643 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003644 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3645 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003646 }
3647
3648 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003649 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003650 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003651 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003652 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003653 final long identity = Binder.clearCallingIdentity();
3654 try {
3655 final Phone phone = PhoneFactory.getPhone(slotIndex);
3656 if (phone != null) {
3657 return phone.getIccCard().hasIccCard();
3658 } else {
3659 return false;
3660 }
3661 } finally {
3662 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003663 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003664 }
3665
3666 /**
3667 * Return if the current radio is LTE on CDMA. This
3668 * is a tri-state return value as for a period of time
3669 * the mode may be unknown.
3670 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003671 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003672 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003673 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003674 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003675 @Override
3676 public int getLteOnCdmaMode(String callingPackage) {
3677 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003678 }
3679
Sanket Padawe356d7632015-06-22 14:03:32 -07003680 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003681 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003683 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003684 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3685 }
3686
Malcolm Chend965c8b2018-02-28 15:00:40 -08003687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 final Phone phone = getPhone(subId);
3690 if (phone == null) {
3691 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3692 } else {
3693 return phone.getLteOnCdmaMode();
3694 }
3695 } finally {
3696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003697 }
Wink Saville36469e72014-06-11 15:17:00 -07003698 }
3699
Wink Saville36469e72014-06-11 15:17:00 -07003700 /**
3701 * {@hide}
3702 * Returns Default subId, 0 in the case of single standby.
3703 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003704 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003705 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003706 }
3707
Shishir Agrawala9f32182016-04-12 12:00:16 -07003708 private int getSlotForDefaultSubscription() {
3709 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3710 }
3711
Wink Savilleb564aae2014-10-23 10:18:09 -07003712 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003713 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003714 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003715
Pengquan Meng466e2482018-09-21 15:54:48 -07003716 private boolean isActiveSubscription(int subId) {
3717 return mSubscriptionController.isActiveSubId(subId);
3718 }
3719
Ihab Awadf2177b72013-11-25 13:33:23 -08003720 /**
3721 * @see android.telephony.TelephonyManager.WifiCallingChoices
3722 */
3723 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003724 final long identity = Binder.clearCallingIdentity();
3725 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003726 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003727 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3728 getWhenToMakeWifiCallsDefaultPreference());
3729 } finally {
3730 Binder.restoreCallingIdentity(identity);
3731 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003732 }
3733
3734 /**
3735 * @see android.telephony.TelephonyManager.WifiCallingChoices
3736 */
3737 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003738 final long identity = Binder.clearCallingIdentity();
3739 try {
3740 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003741 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003742 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3743 } finally {
3744 Binder.restoreCallingIdentity(identity);
3745 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003746 }
3747
Sailesh Nepald1e68152013-12-12 19:08:02 -08003748 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003749 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003750 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003751 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003752
Jordan Liu73b078d2019-02-28 12:03:40 -08003753 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3754 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3755 if (phoneId == -1) {
3756 throw new IllegalArgumentException("Given slot index: " + slotIndex
3757 + " does not correspond to an active phone");
3758 }
3759 return PhoneFactory.getPhone(phoneId);
3760 }
3761
Shishir Agrawal566b7612013-10-28 14:41:00 -07003762 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003763 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3764 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3766 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003767 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003768 if (DBG) {
3769 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3770 }
3771 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3772 p2);
3773 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003774
Jordan Liu73b078d2019-02-28 12:03:40 -08003775
3776 @Override
3777 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3778 int slotIndex, String callingPackage, String aid, int p2) {
3779 enforceModifyPermission();
3780 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3781 if (DBG) {
3782 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3783 }
3784 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3785 callingPackage, aid, p2);
3786 }
3787
3788 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3789 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003790 final long identity = Binder.clearCallingIdentity();
3791 try {
3792 if (TextUtils.equals(ISDR_AID, aid)) {
3793 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003794 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3795 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003796 if (bestComponent == null
3797 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3798 loge("The calling package is not allowed to access ISD-R.");
3799 throw new SecurityException(
3800 "The calling package is not allowed to access ISD-R.");
3801 }
Derek Tan740e1672017-06-27 14:56:27 -07003802 }
Derek Tan740e1672017-06-27 14:56:27 -07003803
Malcolm Chend965c8b2018-02-28 15:00:40 -08003804 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003805 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3806 null /* workSource */);
3807 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003808 return response;
3809 } finally {
3810 Binder.restoreCallingIdentity(identity);
3811 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003812 }
3813
3814 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003815 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3817 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003818 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3819 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3820 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003821
Jordan Liu73b078d2019-02-28 12:03:40 -08003822 @Override
3823 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3824 enforceModifyPermission();
3825 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3826 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3827 channel);
3828 }
3829
3830 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003831 final long identity = Binder.clearCallingIdentity();
3832 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003833 if (channel < 0) {
3834 return false;
3835 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003836 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3837 null /* workSource */);
3838 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003839 return success;
3840 } finally {
3841 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003842 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003843 }
3844
3845 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003846 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003847 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3849 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003850 if (DBG) {
3851 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3852 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3853 + p3 + " data=" + data);
3854 }
3855 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3856 command, p1, p2, p3, data);
3857 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003858
Jordan Liu73b078d2019-02-28 12:03:40 -08003859 @Override
3860 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3861 int command, int p1, int p2, int p3, String data) {
3862 enforceModifyPermission();
3863 if (DBG) {
3864 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3865 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3866 + p3 + " data=" + data);
3867 }
3868 return iccTransmitApduLogicalChannelWithPermission(
3869 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3870 data);
3871 }
3872
3873 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3874 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003875 final long identity = Binder.clearCallingIdentity();
3876 try {
Hall Liucdcfa292019-05-02 09:16:29 -07003877 if (channel <= 0) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003878 return "";
3879 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003880
Malcolm Chend965c8b2018-02-28 15:00:40 -08003881 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003882 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3883 null /* workSource */);
3884 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003885
Malcolm Chend965c8b2018-02-28 15:00:40 -08003886 // Append the returned status code to the end of the response payload.
3887 String s = Integer.toHexString(
3888 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3889 if (response.payload != null) {
3890 s = IccUtils.bytesToHexString(response.payload) + s;
3891 }
3892 return s;
3893 } finally {
3894 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003895 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003896 }
Jake Hambye994d462014-02-03 13:10:13 -08003897
Evan Charltonc66da362014-05-16 14:06:40 -07003898 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003899 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3900 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3902 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003903 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003904 if (DBG) {
3905 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3906 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3907 }
3908 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3909 cla, command, p1, p2, p3, data);
3910 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003911
Jordan Liu73b078d2019-02-28 12:03:40 -08003912 @Override
3913 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3914 int command, int p1, int p2, int p3, String data) {
3915 enforceModifyPermission();
3916 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3917 if (DBG) {
3918 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3919 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3920 + " data=" + data);
3921 }
3922
3923 return iccTransmitApduBasicChannelWithPermission(
3924 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3925 p2, p3, data);
3926 }
3927
3928 // open APDU basic channel assuming the caller has sufficient permissions
3929 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3930 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003931 final long identity = Binder.clearCallingIdentity();
3932 try {
3933 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3934 && TextUtils.equals(ISDR_AID, data)) {
3935 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003936 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3937 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003938 if (bestComponent == null
3939 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3940 loge("The calling package is not allowed to select ISD-R.");
3941 throw new SecurityException(
3942 "The calling package is not allowed to select ISD-R.");
3943 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003944 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003945
Malcolm Chend965c8b2018-02-28 15:00:40 -08003946 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003947 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3948 null /* workSource */);
3949 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003950
Malcolm Chend965c8b2018-02-28 15:00:40 -08003951 // Append the returned status code to the end of the response payload.
3952 String s = Integer.toHexString(
3953 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3954 if (response.payload != null) {
3955 s = IccUtils.bytesToHexString(response.payload) + s;
3956 }
3957 return s;
3958 } finally {
3959 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003960 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003961 }
3962
3963 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003964 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003965 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3967 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003968
Malcolm Chend965c8b2018-02-28 15:00:40 -08003969 final long identity = Binder.clearCallingIdentity();
3970 try {
3971 if (DBG) {
3972 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3973 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3974 }
3975
3976 IccIoResult response =
3977 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3978 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3979 subId);
3980
3981 if (DBG) {
3982 log("Exchange SIM_IO [R]" + response);
3983 }
3984
3985 byte[] result = null;
3986 int length = 2;
3987 if (response.payload != null) {
3988 length = 2 + response.payload.length;
3989 result = new byte[length];
3990 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3991 } else {
3992 result = new byte[length];
3993 }
3994
3995 result[length - 1] = (byte) response.sw2;
3996 result[length - 2] = (byte) response.sw1;
3997 return result;
3998 } finally {
3999 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004000 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004001 }
4002
Nathan Haroldb3014052017-01-25 15:57:32 -08004003 /**
4004 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4005 * on a particular subscription
4006 */
sqianb6e41952018-03-12 14:54:01 -07004007 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4009 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4010 return null;
4011 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004012
4013 final long identity = Binder.clearCallingIdentity();
4014 try {
4015 if (appType != TelephonyManager.APPTYPE_USIM
4016 && appType != TelephonyManager.APPTYPE_SIM) {
4017 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4018 return null;
4019 }
4020 Object response = sendRequest(
4021 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4022 if (response instanceof String[]) {
4023 return (String[]) response;
4024 }
4025 // Response is an Exception of some kind,
4026 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004027 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004028 } finally {
4029 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004030 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004031 }
4032
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004033 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004034 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4036 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004037
Malcolm Chend965c8b2018-02-28 15:00:40 -08004038 final long identity = Binder.clearCallingIdentity();
4039 try {
4040 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4041 if (response.payload == null) {
4042 return "";
4043 }
Evan Charltonc66da362014-05-16 14:06:40 -07004044
Malcolm Chend965c8b2018-02-28 15:00:40 -08004045 // Append the returned status code to the end of the response payload.
4046 String s = Integer.toHexString(
4047 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4048 s = IccUtils.bytesToHexString(response.payload) + s;
4049 return s;
4050 } finally {
4051 Binder.restoreCallingIdentity(identity);
4052 }
Evan Charltonc66da362014-05-16 14:06:40 -07004053 }
4054
Jake Hambye994d462014-02-03 13:10:13 -08004055 /**
4056 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4057 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4058 *
4059 * @param itemID the ID of the item to read
4060 * @return the NV item as a String, or null on error.
4061 */
4062 @Override
4063 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07004064 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4066 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004067
4068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004071 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004072 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4073 return value;
4074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
Jake Hambye994d462014-02-03 13:10:13 -08004077 }
4078
4079 /**
4080 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4081 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4082 *
4083 * @param itemID the ID of the item to read
4084 * @param itemValue the value to write, as a String
4085 * @return true on success; false on any failure
4086 */
4087 @Override
4088 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004089 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4091 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004092
4093 final long identity = Binder.clearCallingIdentity();
4094 try {
4095 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4096 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004097 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004098 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4099 return success;
4100 } finally {
4101 Binder.restoreCallingIdentity(identity);
4102 }
Jake Hambye994d462014-02-03 13:10:13 -08004103 }
4104
4105 /**
4106 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4107 * Used for device configuration by some CDMA operators.
4108 *
4109 * @param preferredRoamingList byte array containing the new PRL
4110 * @return true on success; false on any failure
4111 */
4112 @Override
4113 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4115 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004116
4117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4120 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4121 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4122 return success;
4123 } finally {
4124 Binder.restoreCallingIdentity(identity);
4125 }
Jake Hambye994d462014-02-03 13:10:13 -08004126 }
4127
4128 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004129 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004130 * Used for device configuration by some CDMA operators.
4131 *
chen xu1cc0abe2018-10-26 17:39:23 -07004132 * @param slotIndex - device slot.
4133 *
Jake Hambye994d462014-02-03 13:10:13 -08004134 * @return true on success; false on any failure
4135 */
4136 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004137 public boolean resetModemConfig(int slotIndex) {
4138 Phone phone = PhoneFactory.getPhone(slotIndex);
4139 if (phone != null) {
4140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4141 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004142
chen xu1cc0abe2018-10-26 17:39:23 -07004143 final long identity = Binder.clearCallingIdentity();
4144 try {
4145 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4146 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4147 return success;
4148 } finally {
4149 Binder.restoreCallingIdentity(identity);
4150 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004151 }
chen xu1cc0abe2018-10-26 17:39:23 -07004152 return false;
4153 }
4154
4155 /**
4156 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4157 *
4158 * @param slotIndex - device slot.
4159 *
4160 * @return true on success; false on any failure
4161 */
4162 @Override
4163 public boolean rebootModem(int slotIndex) {
4164 Phone phone = PhoneFactory.getPhone(slotIndex);
4165 if (phone != null) {
4166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4167 mApp, phone.getSubId(), "rebootModem");
4168
4169 final long identity = Binder.clearCallingIdentity();
4170 try {
4171 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4172 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4173 return success;
4174 } finally {
4175 Binder.restoreCallingIdentity(identity);
4176 }
4177 }
4178 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004179 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004180
Svet Ganovb320e182015-04-16 12:30:10 -07004181 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004182 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004183 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004184 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004185 return new String[0];
4186 }
4187
Malcolm Chend965c8b2018-02-28 15:00:40 -08004188 final long identity = Binder.clearCallingIdentity();
4189 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004190 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004191 } finally {
4192 Binder.restoreCallingIdentity(identity);
4193 }
Wink Saville36469e72014-06-11 15:17:00 -07004194 }
4195
Brad Ebinger51f743a2017-01-23 13:50:20 -08004196 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004197 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4198 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004199 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004200 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004201 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004202
4203 final long identity = Binder.clearCallingIdentity();
4204 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004205 ImsResolver resolver = PhoneFactory.getImsResolver();
4206 if (resolver == null) {
4207 // may happen if the device does not support IMS.
4208 return;
4209 }
4210 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004211 } finally {
4212 Binder.restoreCallingIdentity(identity);
4213 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004214 }
4215
4216 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004217 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4218 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004219 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004220 public void disableIms(int slotId) {
4221 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004222
4223 final long identity = Binder.clearCallingIdentity();
4224 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004225 ImsResolver resolver = PhoneFactory.getImsResolver();
4226 if (resolver == null) {
4227 // may happen if the device does not support IMS.
4228 return;
4229 }
4230 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004231 } finally {
4232 Binder.restoreCallingIdentity(identity);
4233 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004234 }
4235
4236 /**
4237 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4238 * feature or {@link null} if the service is not available. If the feature is available, the
4239 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4240 */
4241 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004242 IImsServiceFeatureCallback callback) {
4243 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004244
4245 final long identity = Binder.clearCallingIdentity();
4246 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004247 ImsResolver resolver = PhoneFactory.getImsResolver();
4248 if (resolver == null) {
4249 // may happen if the device does not support IMS.
4250 return null;
4251 }
4252 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004253 } finally {
4254 Binder.restoreCallingIdentity(identity);
4255 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004256 }
4257
4258 /**
4259 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4260 * feature during emergency calling or {@link null} if the service is not available. If the
4261 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4262 * listener for feature updates.
4263 */
4264 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4265 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004266
4267 final long identity = Binder.clearCallingIdentity();
4268 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004269 ImsResolver resolver = PhoneFactory.getImsResolver();
4270 if (resolver == null) {
4271 // may happen if the device does not support IMS.
4272 return null;
4273 }
4274 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004275 } finally {
4276 Binder.restoreCallingIdentity(identity);
4277 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004278 }
4279
Brad Ebinger5f64b052017-12-14 14:26:15 -08004280 /**
4281 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004282 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004283 */
4284 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4285 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004286
4287 final long identity = Binder.clearCallingIdentity();
4288 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004289 ImsResolver resolver = PhoneFactory.getImsResolver();
4290 if (resolver == null) {
4291 // may happen if the device does not support IMS.
4292 return null;
4293 }
4294 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004295 } finally {
4296 Binder.restoreCallingIdentity(identity);
4297 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004298 }
4299
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004300 /**
4301 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004302 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004303 */
4304 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4305 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004306
4307 final long identity = Binder.clearCallingIdentity();
4308 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004309 ImsResolver resolver = PhoneFactory.getImsResolver();
4310 if (resolver == null) {
4311 // may happen if the device does not support IMS.
4312 return null;
4313 }
4314 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004315 } finally {
4316 Binder.restoreCallingIdentity(identity);
4317 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004318 }
4319
Brad Ebinger884c07b2018-02-15 16:17:40 -08004320 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004321 * Sets the ImsService Package Name that Telephony will bind to.
4322 *
4323 * @param slotId the slot ID that the ImsService should bind for.
4324 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4325 * ImsService is the device default ImsService.
4326 * @param packageName The package name of the application that contains the ImsService to bind
4327 * to.
4328 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4329 * @hide
4330 */
4331 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004332 int[] subIds = SubscriptionManager.getSubId(slotId);
4333 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4334 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4335 "setImsService");
4336
Malcolm Chend965c8b2018-02-28 15:00:40 -08004337 final long identity = Binder.clearCallingIdentity();
4338 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004339 ImsResolver resolver = PhoneFactory.getImsResolver();
4340 if (resolver == null) {
4341 // may happen if the device does not support IMS.
4342 return false;
4343 }
4344 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4345 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004346 } finally {
4347 Binder.restoreCallingIdentity(identity);
4348 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004349 }
4350
4351 /**
4352 * Return the ImsService configuration.
4353 *
4354 * @param slotId The slot that the ImsService is associated with.
4355 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4356 * the device default.
4357 * @return the package name of the ImsService configuration.
4358 */
4359 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004360 int[] subIds = SubscriptionManager.getSubId(slotId);
4361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4362 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4363 "getImsService");
4364
Malcolm Chend965c8b2018-02-28 15:00:40 -08004365 final long identity = Binder.clearCallingIdentity();
4366 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004367 ImsResolver resolver = PhoneFactory.getImsResolver();
4368 if (resolver == null) {
4369 // may happen if the device does not support IMS.
4370 return "";
4371 }
4372 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004373 } finally {
4374 Binder.restoreCallingIdentity(identity);
4375 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004376 }
4377
Wink Saville36469e72014-06-11 15:17:00 -07004378 public void setImsRegistrationState(boolean registered) {
4379 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004380
4381 final long identity = Binder.clearCallingIdentity();
4382 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004383 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004384 } finally {
4385 Binder.restoreCallingIdentity(identity);
4386 }
Wink Saville36469e72014-06-11 15:17:00 -07004387 }
4388
4389 /**
Stuart Scott54788802015-03-30 13:18:01 -07004390 * Set the network selection mode to automatic.
4391 *
4392 */
4393 @Override
4394 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4396 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004397
Pengquan Meng466e2482018-09-21 15:54:48 -07004398 if (!isActiveSubscription(subId)) {
4399 return;
4400 }
4401
Malcolm Chend965c8b2018-02-28 15:00:40 -08004402 final long identity = Binder.clearCallingIdentity();
4403 try {
4404 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4405 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
Stuart Scott54788802015-03-30 13:18:01 -07004409 }
4410
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004411 /**
4412 * Ask the radio to connect to the input network and change selection mode to manual.
4413 *
4414 * @param subId the id of the subscription.
4415 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4416 * the operator to attach to.
4417 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4418 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4419 * normal network selection next time.
4420 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004421 */
4422 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004423 public boolean setNetworkSelectionModeManual(
4424 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4426 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004427
4428 if (!isActiveSubscription(subId)) {
4429 return false;
4430 }
4431
Malcolm Chend965c8b2018-02-28 15:00:40 -08004432 final long identity = Binder.clearCallingIdentity();
4433 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004434 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004435 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004436 if (DBG) {
4437 log("setNetworkSelectionModeManual: subId: " + subId
4438 + " operator: " + operatorInfo);
4439 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004440 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4441 } finally {
4442 Binder.restoreCallingIdentity(identity);
4443 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004444 }
4445
4446 /**
4447 * Scans for available networks.
4448 */
4449 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004450 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4452 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004453 LocationAccessPolicy.LocationPermissionResult locationResult =
4454 LocationAccessPolicy.checkLocationPermission(mApp,
4455 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4456 .setCallingPackage(callingPackage)
4457 .setCallingPid(Binder.getCallingPid())
4458 .setCallingUid(Binder.getCallingUid())
4459 .setMethod("getCellNetworkScanResults")
4460 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4461 .build());
4462 switch (locationResult) {
4463 case DENIED_HARD:
4464 throw new SecurityException("Not allowed to access scan results -- location");
4465 case DENIED_SOFT:
4466 return null;
4467 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004468
Pengquan Meng0c05b502018-09-06 09:59:22 -07004469 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004470 try {
4471 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004472 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004473 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004474 } finally {
4475 Binder.restoreCallingIdentity(identity);
4476 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004477 }
4478
4479 /**
yinxub1bed742017-04-17 11:45:04 -07004480 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004481 *
yinxub1bed742017-04-17 11:45:04 -07004482 * @param subId id of the subscription
4483 * @param request contains the radio access networks with bands/channels to scan
4484 * @param messenger callback messenger for scan results or errors
4485 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004486 * @return the id of the requested scan which can be used to stop the scan.
4487 */
4488 @Override
4489 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004490 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4492 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004493 LocationAccessPolicy.LocationPermissionResult locationResult =
4494 LocationAccessPolicy.checkLocationPermission(mApp,
4495 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4496 .setCallingPackage(callingPackage)
4497 .setCallingPid(Binder.getCallingPid())
4498 .setCallingUid(Binder.getCallingUid())
4499 .setMethod("requestNetworkScan")
4500 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4501 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004502 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4503 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4504 if (e != null) {
4505 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4506 throw e;
4507 } else {
Hall Liu46dd96a2019-04-03 12:50:44 -07004508 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004509 return TelephonyScanManager.INVALID_SCAN_ID;
4510 }
4511 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004512 }
Hall Liubac7d482019-04-25 14:02:26 -07004513 int callingUid = Binder.getCallingUid();
4514 int callingPid = Binder.getCallingPid();
yinxu612a8192019-04-18 10:38:27 -07004515 final long identity = Binder.clearCallingIdentity();
4516 try {
4517 return mNetworkScanRequestTracker.startNetworkScan(
4518 request, messenger, binder, getPhone(subId),
Hall Liubac7d482019-04-25 14:02:26 -07004519 callingUid, callingPid, callingPackage);
yinxu612a8192019-04-18 10:38:27 -07004520 } finally {
4521 Binder.restoreCallingIdentity(identity);
4522 }
yinxu504e1392017-04-12 16:03:22 -07004523 }
4524
Hall Liub2ac8ef2019-02-28 15:56:23 -08004525 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4526 NetworkScanRequest request) {
4527 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4528 != PERMISSION_GRANTED) {
4529 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4530 + " without location access.");
4531 }
4532
4533 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4534 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004535 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4536 return new SecurityException("Specific channels must not be"
4537 + " scanned without location access.");
4538 }
4539 }
4540 }
4541
Hall Liub2ac8ef2019-02-28 15:56:23 -08004542 return null;
4543 }
4544
yinxu504e1392017-04-12 16:03:22 -07004545 /**
4546 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004547 *
4548 * @param subId id of the subscription
4549 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004550 */
4551 @Override
4552 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4554 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004555
Hall Liubac7d482019-04-25 14:02:26 -07004556 int callingUid = Binder.getCallingUid();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004557 final long identity = Binder.clearCallingIdentity();
4558 try {
Hall Liubac7d482019-04-25 14:02:26 -07004559 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004560 } finally {
4561 Binder.restoreCallingIdentity(identity);
4562 }
yinxu504e1392017-04-12 16:03:22 -07004563 }
4564
4565 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004566 * Get the calculated preferred network type.
4567 * Used for debugging incorrect network type.
4568 *
4569 * @return the preferred network type, defined in RILConstants.java.
4570 */
4571 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004572 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004573 final Phone defaultPhone = getDefaultPhone();
4574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4575 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004576 return RILConstants.PREFERRED_NETWORK_MODE;
4577 }
4578
Malcolm Chend965c8b2018-02-28 15:00:40 -08004579 final long identity = Binder.clearCallingIdentity();
4580 try {
4581 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004582 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004583 } finally {
4584 Binder.restoreCallingIdentity(identity);
4585 }
Junda Liu84d15a22014-07-02 11:21:04 -07004586 }
4587
4588 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004589 * Get the preferred network type.
4590 * Used for device configuration by some CDMA operators.
4591 *
4592 * @return the preferred network type, defined in RILConstants.java.
4593 */
4594 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004595 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004596 TelephonyPermissions
4597 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4598 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004599
4600 final long identity = Binder.clearCallingIdentity();
4601 try {
4602 if (DBG) log("getPreferredNetworkType");
4603 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4604 int networkType = (result != null ? result[0] : -1);
4605 if (DBG) log("getPreferredNetworkType: " + networkType);
4606 return networkType;
4607 } finally {
4608 Binder.restoreCallingIdentity(identity);
4609 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004610 }
4611
4612 /**
4613 * Set the preferred network type.
4614 * Used for device configuration by some CDMA operators.
4615 *
4616 * @param networkType the preferred network type, defined in RILConstants.java.
4617 * @return true on success; false on any failure.
4618 */
4619 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004620 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4622 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004623
4624 final long identity = Binder.clearCallingIdentity();
4625 try {
4626 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4627 Boolean success = (Boolean) sendRequest(
4628 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4629 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4630 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004631 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004632 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4633 }
4634 return success;
4635 } finally {
4636 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004637 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004638 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004639
4640 /**
Miaoa84611c2019-03-15 09:21:10 +08004641 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004642 *
Miaoa84611c2019-03-15 09:21:10 +08004643 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004644 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004645 * @hide
4646 */
4647 @Override
Miaoa84611c2019-03-15 09:21:10 +08004648 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004649 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004650 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004651 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004652 try {
Miaoa84611c2019-03-15 09:21:10 +08004653 if (phone != null) {
4654 return phone.hasMatchedTetherApnSetting();
4655 } else {
4656 return false;
4657 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004658 } finally {
4659 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004660 }
Junda Liu475951f2014-11-07 16:45:03 -08004661 }
4662
4663 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004664 * Set mobile data enabled
4665 * Used by the user through settings etc to turn on/off mobile data
4666 *
4667 * @param enable {@code true} turn turn data on, else {@code false}
4668 */
4669 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004670 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4672 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004673
4674 final long identity = Binder.clearCallingIdentity();
4675 try {
4676 int phoneId = mSubscriptionController.getPhoneId(subId);
4677 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4678 Phone phone = PhoneFactory.getPhone(phoneId);
4679 if (phone != null) {
4680 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004681 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004682 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004683 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004684 }
4685 } finally {
4686 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004687 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004688 }
4689
4690 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004691 * Get the user enabled state of Mobile Data.
4692 *
4693 * TODO: remove and use isUserDataEnabled.
4694 * This can't be removed now because some vendor codes
4695 * calls through ITelephony directly while they should
4696 * use TelephonyManager.
4697 *
4698 * @return true on enabled
4699 */
4700 @Override
4701 public boolean getDataEnabled(int subId) {
4702 return isUserDataEnabled(subId);
4703 }
4704
4705 /**
4706 * Get whether mobile data is enabled per user setting.
4707 *
4708 * There are other factors deciding whether mobile data is actually enabled, but they are
4709 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004710 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004711 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004712 *
4713 * @return {@code true} if data is enabled else {@code false}
4714 */
4715 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004716 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004717 try {
4718 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4719 null);
4720 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4722 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004723 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004724
4725 final long identity = Binder.clearCallingIdentity();
4726 try {
4727 int phoneId = mSubscriptionController.getPhoneId(subId);
4728 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4729 Phone phone = PhoneFactory.getPhone(phoneId);
4730 if (phone != null) {
4731 boolean retVal = phone.isUserDataEnabled();
4732 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4733 return retVal;
4734 } else {
4735 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4736 return false;
4737 }
4738 } finally {
4739 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004740 }
4741 }
4742
4743 /**
4744 * Get whether mobile data is enabled.
4745 *
4746 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4747 * whether mobile data is actually enabled.
4748 *
4749 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4750 *
4751 * @return {@code true} if data is enabled else {@code false}
4752 */
4753 @Override
4754 public boolean isDataEnabled(int subId) {
4755 try {
4756 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4757 null);
4758 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4760 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004761 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004762
4763 final long identity = Binder.clearCallingIdentity();
4764 try {
4765 int phoneId = mSubscriptionController.getPhoneId(subId);
4766 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4767 Phone phone = PhoneFactory.getPhone(phoneId);
4768 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004769 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004770 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4771 return retVal;
4772 } else {
4773 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4774 return false;
4775 }
4776 } finally {
4777 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004778 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004779 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004780
4781 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004782 public int getCarrierPrivilegeStatus(int subId) {
4783 final Phone phone = getPhone(subId);
4784 if (phone == null) {
4785 loge("getCarrierPrivilegeStatus: Invalid subId");
4786 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4787 }
4788 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004789 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004790 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004791 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4792 }
4793 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004794 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004795 }
Junda Liu29340342014-07-10 15:23:27 -07004796
4797 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004798 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4799 final Phone phone = getPhone(subId);
4800 if (phone == null) {
4801 loge("getCarrierPrivilegeStatus: Invalid subId");
4802 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4803 }
4804 UiccProfile profile =
4805 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4806 if (profile == null) {
4807 loge("getCarrierPrivilegeStatus: No UICC");
4808 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4809 }
4810 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4811 }
4812
4813 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004814 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004815 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004816 if (TextUtils.isEmpty(pkgName))
4817 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004818 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004819 if (card == null) {
4820 loge("checkCarrierPrivilegesForPackage: No UICC");
4821 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4822 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004823 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4824 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004825 }
4826
4827 @Override
4828 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004829 if (TextUtils.isEmpty(pkgName))
4830 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004831 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4832 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4833 UiccCard card = UiccController.getInstance().getUiccCard(i);
4834 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004835 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004836 continue;
4837 }
4838
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004839 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004840 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4841 break;
4842 }
4843 }
4844
4845 return result;
Junda Liu29340342014-07-10 15:23:27 -07004846 }
Derek Tan89e89d42014-07-08 17:00:10 -07004847
4848 @Override
Junda Liue64de782015-04-16 17:19:16 -07004849 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4850 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4851 loge("phoneId " + phoneId + " is not valid.");
4852 return null;
4853 }
4854 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004855 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004856 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004857 return null ;
4858 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004859 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004860 }
4861
Amith Yamasani6e118872016-02-19 12:53:51 -08004862 @Override
4863 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004864 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004865 List<String> privilegedPackages = new ArrayList<>();
4866 List<PackageInfo> packages = null;
4867 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4868 UiccCard card = UiccController.getInstance().getUiccCard(i);
4869 if (card == null) {
4870 // No UICC in that slot.
4871 continue;
4872 }
4873 if (card.hasCarrierPrivilegeRules()) {
4874 if (packages == null) {
4875 // Only check packages in user 0 for now
4876 packages = pm.getInstalledPackagesAsUser(
4877 PackageManager.MATCH_DISABLED_COMPONENTS
4878 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4879 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4880 }
4881 for (int p = packages.size() - 1; p >= 0; p--) {
4882 PackageInfo pkgInfo = packages.get(p);
4883 if (pkgInfo != null && pkgInfo.packageName != null
4884 && card.getCarrierPrivilegeStatus(pkgInfo)
4885 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4886 privilegedPackages.add(pkgInfo.packageName);
4887 }
4888 }
4889 }
4890 }
4891 return privilegedPackages;
4892 }
4893
Wink Savilleb564aae2014-10-23 10:18:09 -07004894 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004895 final Phone phone = getPhone(subId);
4896 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004897 if (card == null) {
4898 loge("getIccId: No UICC");
4899 return null;
4900 }
4901 String iccId = card.getIccId();
4902 if (TextUtils.isEmpty(iccId)) {
4903 loge("getIccId: ICC ID is null or empty.");
4904 return null;
4905 }
4906 return iccId;
4907 }
4908
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004909 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004910 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4911 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004912 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4913 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004914
Malcolm Chend965c8b2018-02-28 15:00:40 -08004915 final long identity = Binder.clearCallingIdentity();
4916 try {
4917 final String iccId = getIccId(subId);
4918 final Phone phone = getPhone(subId);
4919 if (phone == null) {
4920 return false;
4921 }
4922 final String subscriberId = phone.getSubscriberId();
4923
4924 if (DBG_MERGE) {
4925 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4926 + subscriberId + " to " + number);
4927 }
4928
4929 if (TextUtils.isEmpty(iccId)) {
4930 return false;
4931 }
4932
4933 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4934
4935 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4936 if (alphaTag == null) {
4937 editor.remove(alphaTagPrefKey);
4938 } else {
4939 editor.putString(alphaTagPrefKey, alphaTag);
4940 }
4941
4942 // Record both the line number and IMSI for this ICCID, since we need to
4943 // track all merged IMSIs based on line number
4944 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4945 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4946 if (number == null) {
4947 editor.remove(numberPrefKey);
4948 editor.remove(subscriberPrefKey);
4949 } else {
4950 editor.putString(numberPrefKey, number);
4951 editor.putString(subscriberPrefKey, subscriberId);
4952 }
4953
4954 editor.commit();
4955 return true;
4956 } finally {
4957 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004958 }
Derek Tan7226c842014-07-02 17:42:23 -07004959 }
4960
4961 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004962 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004963 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004965 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004966 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004967 return null;
4968 }
Derek Tan97ebb422014-09-05 16:55:38 -07004969
Malcolm Chend965c8b2018-02-28 15:00:40 -08004970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 String iccId = getIccId(subId);
4973 if (iccId != null) {
4974 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4975 if (DBG_MERGE) {
4976 log("getLine1NumberForDisplay returning "
4977 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4978 }
4979 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004980 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004981 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4982 return null;
4983 } finally {
4984 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004985 }
Derek Tan7226c842014-07-02 17:42:23 -07004986 }
4987
4988 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004989 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004991 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004992 return null;
4993 }
Derek Tan97ebb422014-09-05 16:55:38 -07004994
Malcolm Chend965c8b2018-02-28 15:00:40 -08004995 final long identity = Binder.clearCallingIdentity();
4996 try {
4997 String iccId = getIccId(subId);
4998 if (iccId != null) {
4999 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5000 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5001 }
5002 return null;
5003 } finally {
5004 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005005 }
Derek Tan7226c842014-07-02 17:42:23 -07005006 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005007
5008 @Override
Jordan Liu9775d4b2019-05-06 14:45:15 -07005009 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005010 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5011 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005013 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5014 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005015 return null;
5016 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005017
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005018 final long identity = Binder.clearCallingIdentity();
5019 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005020 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005021 final TelephonyManager tele = TelephonyManager.from(context);
5022 final SubscriptionManager sub = SubscriptionManager.from(context);
5023
5024 // Figure out what subscribers are currently active
5025 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
5026 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5027 // the process, where TelephonyManager was instantiated.
5028 // Otherwise AppOps check will fail.
5029
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005030 final int[] subIds = sub.getActiveSubscriptionIdList();
Jordan Liu9775d4b2019-05-06 14:45:15 -07005031 for (int id : subIds) {
5032 // Only consider subs which match the current subId
5033 // This logic can be simplified. See b/131189269 for progress.
5034 if (subId != id) {
5035 continue;
5036 }
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005037 activeSubscriberIds.add(tele.getSubscriberId(subId));
5038 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005039
5040 // First pass, find a number override for an active subscriber
5041 String mergeNumber = null;
5042 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5043 for (String key : prefs.keySet()) {
5044 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5045 final String subscriberId = (String) prefs.get(key);
5046 if (activeSubscriberIds.contains(subscriberId)) {
5047 final String iccId = key.substring(
5048 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5049 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5050 mergeNumber = (String) prefs.get(numberKey);
5051 if (DBG_MERGE) {
5052 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5053 + " for active subscriber " + subscriberId);
5054 }
5055 if (!TextUtils.isEmpty(mergeNumber)) {
5056 break;
5057 }
5058 }
5059 }
5060 }
5061
5062 // Shortcut when no active merged subscribers
5063 if (TextUtils.isEmpty(mergeNumber)) {
5064 return null;
5065 }
5066
5067 // Second pass, find all subscribers under that line override
5068 final ArraySet<String> result = new ArraySet<>();
5069 for (String key : prefs.keySet()) {
5070 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5071 final String number = (String) prefs.get(key);
5072 if (mergeNumber.equals(number)) {
5073 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5074 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5075 final String subscriberId = (String) prefs.get(subscriberKey);
5076 if (!TextUtils.isEmpty(subscriberId)) {
5077 result.add(subscriberId);
5078 }
5079 }
5080 }
5081 }
5082
5083 final String[] resultArray = result.toArray(new String[result.size()]);
5084 Arrays.sort(resultArray);
5085 if (DBG_MERGE) {
5086 Slog.d(LOG_TAG,
5087 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5088 }
5089 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005090 } finally {
5091 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005092 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005093 }
5094
5095 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005096 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005097 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5098 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005099
5100 final long identity = Binder.clearCallingIdentity();
5101 try {
5102 final Phone phone = getPhone(subId);
5103 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5104 } finally {
5105 Binder.restoreCallingIdentity(identity);
5106 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005107 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005108
5109 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005110 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005111 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5112 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005113 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005114
5115 final long identity = Binder.clearCallingIdentity();
5116 try {
5117 final Phone phone = getPhone(subId);
5118 if (phone == null) {
5119 return false;
5120 }
5121 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5122 cdmaNonRoamingList);
5123 } finally {
5124 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005125 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005126 }
5127
5128 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005129 @Deprecated
5130 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5131 enforceModifyPermission();
5132
5133 int returnValue = 0;
5134 try {
vagdevie435a3e2018-08-15 16:01:53 -07005135 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005136 if(result.exception == null) {
5137 if (result.result != null) {
5138 byte[] responseData = (byte[])(result.result);
5139 if(responseData.length > oemResp.length) {
5140 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5141 responseData.length + "bytes. Buffer Size is " +
5142 oemResp.length + "bytes.");
5143 }
5144 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5145 returnValue = responseData.length;
5146 }
5147 } else {
5148 CommandException ex = (CommandException) result.exception;
5149 returnValue = ex.getCommandError().ordinal();
5150 if(returnValue > 0) returnValue *= -1;
5151 }
5152 } catch (RuntimeException e) {
5153 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5154 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5155 if(returnValue > 0) returnValue *= -1;
5156 }
5157
5158 return returnValue;
5159 }
5160
5161 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005162 public void setRadioCapability(RadioAccessFamily[] rafs) {
5163 try {
5164 ProxyController.getInstance().setRadioCapability(rafs);
5165 } catch (RuntimeException e) {
5166 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5167 }
5168 }
5169
5170 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005171 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005172 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005173 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005174 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005175 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005176 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005177 final long identity = Binder.clearCallingIdentity();
5178 try {
chen xufeeed752018-10-26 14:17:57 -07005179 TelephonyPermissions
5180 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5181 mApp, phone.getSubId(), "getRadioAccessFamily");
5182 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005183 } finally {
5184 Binder.restoreCallingIdentity(identity);
5185 }
chen xufeeed752018-10-26 14:17:57 -07005186 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005187 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005188
5189 @Override
5190 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005191 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005192 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005193
5194 final long identity = Binder.clearCallingIdentity();
5195 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005196 ImsManager.getInstance(defaultPhone.getContext(),
5197 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005198 } finally {
5199 Binder.restoreCallingIdentity(identity);
5200 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005201 }
5202
5203 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005204 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005205 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005206 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005207 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005208 return false;
5209 }
Svet Ganovb320e182015-04-16 12:30:10 -07005210
Malcolm Chend965c8b2018-02-28 15:00:40 -08005211 final long identity = Binder.clearCallingIdentity();
5212 try {
5213 // Check the user preference and the system-level IMS setting. Even if the user has
5214 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5215 // In the long run, we may instead need to check if there exists a connection service
5216 // which can support video calling.
5217 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005218 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005219 return imsManager.isVtEnabledByPlatform()
5220 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5221 && imsManager.isVtEnabledByUser();
5222 } finally {
5223 Binder.restoreCallingIdentity(identity);
5224 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005225 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005226
Andrew Leea1239f22015-03-02 17:44:07 -08005227 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005228 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5230 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5231 return false;
5232 }
5233
5234 final long identity = Binder.clearCallingIdentity();
5235 try {
5236 CarrierConfigManager configManager =
5237 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005238 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005239 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
Andrew Leea1239f22015-03-02 17:44:07 -08005243 }
5244
5245 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005246 public boolean isWorldPhone(int subId, String callingPackage) {
5247 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5248 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5249 return false;
5250 }
5251
5252 final long identity = Binder.clearCallingIdentity();
5253 try {
5254 CarrierConfigManager configManager =
5255 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005256 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005257 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
Andrew Leea1239f22015-03-02 17:44:07 -08005261 }
5262
Andrew Lee9431b832015-03-09 18:46:45 -07005263 @Override
5264 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005265 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005266 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005267 }
5268
5269 @Override
5270 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005271 final long identity = Binder.clearCallingIdentity();
5272 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005273 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005274 } finally {
5275 Binder.restoreCallingIdentity(identity);
5276 }
Andrew Lee9431b832015-03-09 18:46:45 -07005277 }
5278
Hall Liuf6668912018-10-31 17:05:23 -07005279 /**
5280 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5281 * support for the feature and device firmware support.
5282 *
5283 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5284 */
5285 @Override
5286 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005287 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005288 final Phone phone = getPhone(subscriptionId);
5289 if (phone == null) {
5290 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5291 return false;
5292 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005293 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005294 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005295 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5296 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005297 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005298 return isCarrierSupported && isDeviceSupported;
5299 } finally {
5300 Binder.restoreCallingIdentity(identity);
5301 }
Hall Liu98187582018-01-22 19:15:32 -08005302 }
5303
Hall Liuf6668912018-10-31 17:05:23 -07005304 /**
5305 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5306 * both also support RTT.
5307 */
5308 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005309 final long identity = Binder.clearCallingIdentity();
5310 try {
Hall Liuf6668912018-10-31 17:05:23 -07005311 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005312 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005316 }
5317
Sanket Padawe7310cc72015-01-14 09:53:20 -08005318 /**
5319 * Returns the unique device ID of phone, for example, the IMEI for
5320 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5321 *
5322 * <p>Requires Permission:
5323 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5324 */
5325 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005326 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005327 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005328 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005329 return null;
5330 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005331 int subId = phone.getSubId();
5332 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5333 mApp, subId, callingPackage, "getDeviceId")) {
5334 return null;
5335 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005336
5337 final long identity = Binder.clearCallingIdentity();
5338 try {
5339 return phone.getDeviceId();
5340 } finally {
5341 Binder.restoreCallingIdentity(identity);
5342 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005343 }
5344
Ping Sunc67b7c22016-03-02 19:16:45 +08005345 /**
5346 * {@hide}
5347 * Returns the IMS Registration Status on a particular subid
5348 *
5349 * @param subId
5350 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005351 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005352 Phone phone = getPhone(subId);
5353 if (phone != null) {
5354 return phone.isImsRegistered();
5355 } else {
5356 return false;
5357 }
5358 }
5359
Santos Cordon7a1885b2015-02-03 11:15:19 -08005360 @Override
5361 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005362 final long identity = Binder.clearCallingIdentity();
5363 try {
5364 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5365 } finally {
5366 Binder.restoreCallingIdentity(identity);
5367 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005368 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005369
Tyler Gunn327a9722019-04-03 15:28:53 -07005370 @Override
5371 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5372 final long identity = Binder.clearCallingIdentity();
5373 try {
5374 Phone phone = getPhone(subscriptionId);
5375 if (phone == null) {
5376 return null;
5377 }
5378 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5379 } finally {
5380 Binder.restoreCallingIdentity(identity);
5381 }
5382 }
5383
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005384 /**
5385 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005386 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005387 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005388 final long identity = Binder.clearCallingIdentity();
5389 try {
5390 Phone phone = getPhone(subId);
5391 if (phone != null) {
5392 return phone.isWifiCallingEnabled();
5393 } else {
5394 return false;
5395 }
5396 } finally {
5397 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005398 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005399 }
5400
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005401 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005402 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005403 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005404 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005405 final long identity = Binder.clearCallingIdentity();
5406 try {
5407 Phone phone = getPhone(subId);
5408 if (phone != null) {
5409 return phone.isVideoEnabled();
5410 } else {
5411 return false;
5412 }
5413 } finally {
5414 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005415 }
5416 }
5417
5418 /**
5419 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5420 * defined in {@link ImsRegistrationImplBase}.
5421 */
5422 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005423 final long identity = Binder.clearCallingIdentity();
5424 try {
5425 Phone phone = getPhone(subId);
5426 if (phone != null) {
5427 return phone.getImsRegistrationTech();
5428 } else {
5429 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5430 }
5431 } finally {
5432 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005433 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005434 }
5435
Stuart Scott8eef64f2015-04-08 15:13:54 -07005436 @Override
5437 public void factoryReset(int subId) {
5438 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005439 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5440 return;
5441 }
5442
Svet Ganovcc087f82015-05-12 20:35:54 -07005443 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005444
Svet Ganovcc087f82015-05-12 20:35:54 -07005445 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005446 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5447 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005448 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005449 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005450 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005451 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5452 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005453 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005454 // There has been issues when Sms raw table somehow stores orphan
5455 // fragments. They lead to garbled message when new fragments come
5456 // in and combined with those stale ones. In case this happens again,
5457 // user can reset all network settings which will clean up this table.
5458 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005459 } finally {
5460 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005461 }
5462 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005463
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005464 private void cleanUpSmsRawTable(Context context) {
5465 ContentResolver resolver = context.getContentResolver();
5466 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5467 resolver.delete(uri, null, null);
5468 }
5469
Narayan Kamath1c496c22015-04-16 14:40:19 +01005470 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005471 public String getSimLocaleForSubscriber(int subId) {
5472 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5473 final Phone phone = getPhone(subId);
5474 if (phone == null) {
5475 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005476 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005477 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005478 final long identity = Binder.clearCallingIdentity();
5479 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005480 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5481 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005482 // Try and fetch the locale from the carrier properties or from the SIM language
5483 // preferences (EF-PL and EF-LI)...
5484 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005485 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005486 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5487 if (localeFromDefaultSim != null) {
5488 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5489 if (DBG) log("Using locale from subId: " + subId + " locale: "
5490 + localeFromDefaultSim);
5491 return localeFromDefaultSim.toLanguageTag();
5492 } else {
5493 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005494 }
5495 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005496
Malcolm Chend965c8b2018-02-28 15:00:40 -08005497 // The SIM language preferences only store a language (e.g. fr = French), not an
5498 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5499 // the SIM and carrier preferences does not include a country we add the country
5500 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005501 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005502 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005503 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005504 return mccLocale.toLanguageTag();
5505 }
5506
5507 if (DBG) log("No locale found - returning null");
5508 return null;
5509 } finally {
5510 Binder.restoreCallingIdentity(identity);
5511 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005512 }
5513
5514 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005515 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005516 }
5517
Malcolm Chend965c8b2018-02-28 15:00:40 -08005518 /**
5519 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5520 */
5521 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005522 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005523 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005524
Chenjie Yu1ba97252018-01-11 18:16:20 -08005525 private final ModemActivityInfo mLastModemActivityInfo =
5526 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5527
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005528 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005529 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5530 * representing the state of the modem.
5531 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005532 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5533 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005534 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005535 */
5536 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005537 public void requestModemActivityInfo(ResultReceiver result) {
5538 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005539 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005540
5541 final long identity = Binder.clearCallingIdentity();
5542 try {
5543 ModemActivityInfo ret = null;
5544 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005545 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5546 CMD_GET_MODEM_ACTIVITY_INFO,
5547 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005548 if (isModemActivityInfoValid(info)) {
5549 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5550 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5551 mergedTxTimeMs[i] =
5552 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5553 }
5554 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5555 mLastModemActivityInfo.setSleepTimeMillis(
5556 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5557 mLastModemActivityInfo.setIdleTimeMillis(
5558 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5559 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5560 mLastModemActivityInfo.setRxTimeMillis(
5561 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5562 mLastModemActivityInfo.setEnergyUsed(
5563 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005564 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005565 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5566 mLastModemActivityInfo.getSleepTimeMillis(),
5567 mLastModemActivityInfo.getIdleTimeMillis(),
5568 mLastModemActivityInfo.getTxTimeMillis(),
5569 mLastModemActivityInfo.getRxTimeMillis(),
5570 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005571 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005572 Bundle bundle = new Bundle();
5573 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5574 result.send(0, bundle);
5575 } finally {
5576 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005577 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005578 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005579
Siddharth Rayf5d29552018-06-17 15:02:38 -07005580 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5581 // less than total activity duration.
5582 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5583 if (info == null) {
5584 return false;
5585 }
5586 int activityDurationMs =
5587 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5588 int totalTxTimeMs = 0;
5589 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5590 totalTxTimeMs += info.getTxTimeMillis()[i];
5591 }
5592 return (info.isValid()
5593 && (info.getSleepTimeMillis() <= activityDurationMs)
5594 && (info.getIdleTimeMillis() <= activityDurationMs)
5595 && (info.getRxTimeMillis() <= activityDurationMs)
5596 && (totalTxTimeMs <= activityDurationMs));
5597 }
5598
Jack Yu85bd38a2015-11-09 11:34:32 -08005599 /**
5600 * {@hide}
5601 * Returns the service state information on specified subscription.
5602 */
5603 @Override
5604 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005605 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005606 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005607 return null;
5608 }
5609
Hall Liuf19c44f2018-11-27 14:38:17 -08005610 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5611 LocationAccessPolicy.checkLocationPermission(mApp,
5612 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5613 .setCallingPackage(callingPackage)
5614 .setCallingPid(Binder.getCallingPid())
5615 .setCallingUid(Binder.getCallingUid())
5616 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005617 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005618 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5619 .build());
5620
5621 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5622 LocationAccessPolicy.checkLocationPermission(mApp,
5623 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5624 .setCallingPackage(callingPackage)
5625 .setCallingPid(Binder.getCallingPid())
5626 .setCallingUid(Binder.getCallingUid())
5627 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005628 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005629 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5630 .build());
5631 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5632 boolean hasFinePermission =
5633 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5634 boolean hasCoarsePermission =
5635 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5636
Malcolm Chend965c8b2018-02-28 15:00:40 -08005637 final long identity = Binder.clearCallingIdentity();
5638 try {
5639 final Phone phone = getPhone(subId);
5640 if (phone == null) {
5641 return null;
5642 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005643
Hall Liuf19c44f2018-11-27 14:38:17 -08005644 ServiceState ss = phone.getServiceState();
5645
5646 // Scrub out the location info in ServiceState depending on what level of access
5647 // the caller has.
5648 if (hasFinePermission) return ss;
5649 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5650 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005651 } finally {
5652 Binder.restoreCallingIdentity(identity);
5653 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005654 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005655
5656 /**
5657 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5658 *
5659 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5660 * voicemail ringtone.
5661 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5662 * PhoneAccount.
5663 */
5664 @Override
5665 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005666 final long identity = Binder.clearCallingIdentity();
5667 try {
5668 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5669 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005670 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005671 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005672
Malcolm Chend965c8b2018-02-28 15:00:40 -08005673 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005677 }
5678
5679 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005680 * Sets the per-account voicemail ringtone.
5681 *
5682 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5683 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5684 *
5685 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5686 * voicemail ringtone.
5687 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5688 * PhoneAccount.
5689 */
5690 @Override
5691 public void setVoicemailRingtoneUri(String callingPackage,
5692 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005693 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005694 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5695 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005696 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5698 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5699 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005700 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005701
5702 final long identity = Binder.clearCallingIdentity();
5703 try {
5704 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5705 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005706 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005707 }
5708 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005711 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005712 }
5713
5714 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005715 * Returns whether vibration is set for voicemail notification in Phone settings.
5716 *
5717 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5718 * voicemail vibration setting.
5719 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5720 */
5721 @Override
5722 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005723 final long identity = Binder.clearCallingIdentity();
5724 try {
5725 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5726 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005727 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005728 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005729
Malcolm Chend965c8b2018-02-28 15:00:40 -08005730 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5731 } finally {
5732 Binder.restoreCallingIdentity(identity);
5733 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005734 }
5735
Youhan Wange64578a2016-05-02 15:32:42 -07005736 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005737 * Sets the per-account voicemail vibration.
5738 *
5739 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5740 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5741 *
5742 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5743 * voicemail vibration setting.
5744 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5745 * specific PhoneAccount.
5746 */
5747 @Override
5748 public void setVoicemailVibrationEnabled(String callingPackage,
5749 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005750 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005751 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5752 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005753 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5755 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5756 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005757 }
5758
Malcolm Chend965c8b2018-02-28 15:00:40 -08005759 final long identity = Binder.clearCallingIdentity();
5760 try {
5761 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5762 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005763 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005764 }
5765 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5766 } finally {
5767 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005768 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005769 }
5770
5771 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005772 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5773 *
5774 * @throws SecurityException if the caller does not have the required permission
5775 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005776 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005777 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005778 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005779 }
5780
5781 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005782 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5783 * permission.
5784 *
5785 * @throws SecurityException if the caller does not have the required permission
5786 */
5787 private void enforceSendSmsPermission() {
5788 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5789 }
5790
5791 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005792 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005793 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005794 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005795 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005796 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005797 final long identity = Binder.clearCallingIdentity();
5798 try {
5799 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005800 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005801 if (componentName == null) {
5802 throw new SecurityException(
5803 "Caller not current active visual voicemail package[null]");
5804 }
5805 String vvmPackage = componentName.getPackageName();
5806 if (!callingPackage.equals(vvmPackage)) {
5807 throw new SecurityException("Caller not current active visual voicemail package["
5808 + vvmPackage + "]");
5809 }
5810 } finally {
5811 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005812 }
5813 }
5814
5815 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005816 * Return the application ID for the app type.
5817 *
5818 * @param subId the subscription ID that this request applies to.
5819 * @param appType the uicc app type.
5820 * @return Application ID for specificied app type, or null if no uicc.
5821 */
5822 @Override
5823 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005824 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005825 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005826
5827 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005828 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005829 if (phone == null) {
5830 return null;
5831 }
5832 String aid = null;
5833 try {
5834 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5835 .getApplicationByType(appType).getAid();
5836 } catch (Exception e) {
5837 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5838 }
5839 return aid;
5840 } finally {
5841 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005842 }
Youhan Wange64578a2016-05-02 15:32:42 -07005843 }
5844
Youhan Wang4001d252016-05-11 10:29:41 -07005845 /**
5846 * Return the Electronic Serial Number.
5847 *
5848 * @param subId the subscription ID that this request applies to.
5849 * @return ESN or null if error.
5850 */
5851 @Override
5852 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005853 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005854 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005855
5856 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005857 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005858 if (phone == null) {
5859 return null;
5860 }
5861 String esn = null;
5862 try {
5863 esn = phone.getEsn();
5864 } catch (Exception e) {
5865 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5866 }
5867 return esn;
5868 } finally {
5869 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005870 }
Youhan Wang4001d252016-05-11 10:29:41 -07005871 }
5872
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005873 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005874 * Return the Preferred Roaming List Version.
5875 *
5876 * @param subId the subscription ID that this request applies to.
5877 * @return PRLVersion or null if error.
5878 */
5879 @Override
5880 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005881 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005882 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005883
5884 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005885 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005886 if (phone == null) {
5887 return null;
5888 }
5889 String cdmaPrlVersion = null;
5890 try {
5891 cdmaPrlVersion = phone.getCdmaPrlVersion();
5892 } catch (Exception e) {
5893 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5894 }
5895 return cdmaPrlVersion;
5896 } finally {
5897 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005898 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005899 }
5900
5901 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005902 * Get snapshot of Telephony histograms
5903 * @return List of Telephony histograms
5904 * @hide
5905 */
5906 @Override
5907 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5909 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005910
5911 final long identity = Binder.clearCallingIdentity();
5912 try {
5913 return RIL.getTelephonyRILTimingHistograms();
5914 } finally {
5915 Binder.restoreCallingIdentity(identity);
5916 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005917 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005918
5919 /**
5920 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005921 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5922 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005923 * Require system privileges. In the future we may add this to carrier APIs.
5924 *
Michele Berionne0963c862018-11-27 18:57:59 -08005925 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005926 */
5927 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005928 @TelephonyManager.SetCarrierRestrictionResult
5929 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005930 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005931 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005932
Michele Berionne0963c862018-11-27 18:57:59 -08005933 if (carrierRestrictionRules == null) {
5934 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005935 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005936
Malcolm Chend965c8b2018-02-28 15:00:40 -08005937 final long identity = Binder.clearCallingIdentity();
5938 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005939 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005940 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005941 } finally {
5942 Binder.restoreCallingIdentity(identity);
5943 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005944 }
5945
5946 /**
5947 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005948 * Get the allowed carrier list and the excluded carrier list, including the priority between
5949 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005950 * Require system privileges. In the future we may add this to carrier APIs.
5951 *
Michele Berionne0963c862018-11-27 18:57:59 -08005952 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005953 */
5954 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005955 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005956 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005957 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005958
5959 final long identity = Binder.clearCallingIdentity();
5960 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005961 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5962 if (response instanceof CarrierRestrictionRules) {
5963 return (CarrierRestrictionRules) response;
5964 }
5965 // Response is an Exception of some kind,
5966 // which is signalled to the user as a NULL retval
5967 return null;
5968 } catch (Exception e) {
5969 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5970 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005971 } finally {
5972 Binder.restoreCallingIdentity(identity);
5973 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005974 }
5975
fionaxu59545b42016-05-25 15:53:37 -07005976 /**
5977 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5978 * @param subId the subscription ID that this action applies to.
5979 * @param enabled control enable or disable metered apns.
5980 * {@hide}
5981 */
5982 @Override
5983 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5984 enforceModifyPermission();
5985 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005986
5987 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005988 if (phone == null) {
5989 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5990 return;
5991 }
5992 try {
5993 phone.carrierActionSetMeteredApnsEnabled(enabled);
5994 } catch (Exception e) {
5995 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005996 } finally {
5997 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005998 }
5999 }
6000
6001 /**
6002 * Action set from carrier signalling broadcast receivers to enable/disable radio
6003 * @param subId the subscription ID that this action applies to.
6004 * @param enabled control enable or disable radio.
6005 * {@hide}
6006 */
6007 @Override
6008 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6009 enforceModifyPermission();
6010 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006011
6012 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006013 if (phone == null) {
6014 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6015 return;
6016 }
6017 try {
6018 phone.carrierActionSetRadioEnabled(enabled);
6019 } catch (Exception e) {
6020 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006021 } finally {
6022 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006023 }
6024 }
6025
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006026 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006027 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6028 * network status based on which carrier apps could apply actions accordingly,
6029 * enable/disable default url handler for example.
6030 *
6031 * @param subId the subscription ID that this action applies to.
6032 * @param report control start/stop reporting the default network status.
6033 * {@hide}
6034 */
6035 @Override
6036 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6037 enforceModifyPermission();
6038 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006039
6040 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006041 if (phone == null) {
6042 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6043 return;
6044 }
6045 try {
6046 phone.carrierActionReportDefaultNetworkStatus(report);
6047 } catch (Exception e) {
6048 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006049 } finally {
6050 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006051 }
6052 }
6053
6054 /**
fionaxud9622282017-07-17 17:51:30 -07006055 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6056 * @param subId the subscription ID that this action applies to.
6057 * {@hide}
6058 */
6059 @Override
6060 public void carrierActionResetAll(int subId) {
6061 enforceModifyPermission();
6062 final Phone phone = getPhone(subId);
6063 if (phone == null) {
6064 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6065 return;
6066 }
6067 try {
6068 phone.carrierActionResetAll();
6069 } catch (Exception e) {
6070 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6071 }
6072 }
6073
6074 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006075 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6076 * bug report is being generated.
6077 */
6078 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006079 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006080 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6081 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006082 writer.println("Permission Denial: can't dump Phone from pid="
6083 + Binder.getCallingPid()
6084 + ", uid=" + Binder.getCallingUid()
6085 + "without permission "
6086 + android.Manifest.permission.DUMP);
6087 return;
6088 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006089 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006090 }
Jack Yueb89b242016-06-22 13:27:47 -07006091
Brad Ebingerdac2f002018-04-03 15:17:52 -07006092 @Override
6093 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6094 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6095 throws RemoteException {
6096 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6097 }
6098
Jack Yueb89b242016-06-22 13:27:47 -07006099 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006100 * Get aggregated video call data usage since boot.
6101 *
6102 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6103 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006104 * {@hide}
6105 */
6106 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006107 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006108 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6109 null);
6110
Malcolm Chend965c8b2018-02-28 15:00:40 -08006111 final long identity = Binder.clearCallingIdentity();
6112 try {
6113 // NetworkStatsService keeps tracking the active network interface and identity. It
6114 // records the delta with the corresponding network identity.
6115 // We just return the total video call data usage snapshot since boot.
6116 Phone phone = getPhone(subId);
6117 if (phone != null) {
6118 return phone.getVtDataUsage(perUidStats);
6119 }
6120 return null;
6121 } finally {
6122 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006123 }
Jack Yueb89b242016-06-22 13:27:47 -07006124 }
Jack Yu75ab2952016-07-08 14:29:33 -07006125
6126 /**
6127 * Policy control of data connection. Usually used when data limit is passed.
6128 * @param enabled True if enabling the data, otherwise disabling.
6129 * @param subId Subscription index
6130 * {@hide}
6131 */
6132 @Override
6133 public void setPolicyDataEnabled(boolean enabled, int subId) {
6134 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006135
6136 final long identity = Binder.clearCallingIdentity();
6137 try {
6138 Phone phone = getPhone(subId);
6139 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006140 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006141 }
6142 } finally {
6143 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006144 }
6145 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006146
6147 /**
6148 * Get Client request stats
6149 * @return List of Client Request Stats
6150 * @hide
6151 */
6152 @Override
6153 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006154 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006155 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006156 return null;
6157 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006158 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006159
Malcolm Chend965c8b2018-02-28 15:00:40 -08006160 final long identity = Binder.clearCallingIdentity();
6161 try {
6162 if (phone != null) {
6163 return phone.getClientRequestStats();
6164 }
6165
6166 return null;
6167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006170 }
6171
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006172 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006173 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006174 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006175 }
Jack Yueb4124c2017-02-16 15:32:43 -08006176
6177 /**
Grace Chen70990072017-03-24 17:21:30 -07006178 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006179 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006180 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006181 * @param state State of SIM (power down, power up, pass through)
6182 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6183 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6184 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006185 *
6186 **/
6187 @Override
Grace Chen70990072017-03-24 17:21:30 -07006188 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006189 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006190 Phone phone = PhoneFactory.getPhone(slotIndex);
6191
vagdevie435a3e2018-08-15 16:01:53 -07006192 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6193
Malcolm Chend965c8b2018-02-28 15:00:40 -08006194 final long identity = Binder.clearCallingIdentity();
6195 try {
6196 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006197 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006198 }
6199 } finally {
6200 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006201 }
6202 }
Shuo Qiandd210312017-04-12 22:11:33 +00006203
Tyler Gunn65d45c22017-06-05 11:22:26 -07006204 private boolean isUssdApiAllowed(int subId) {
6205 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006206 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006207 if (configManager == null) {
6208 return false;
6209 }
6210 PersistableBundle pb = configManager.getConfigForSubId(subId);
6211 if (pb == null) {
6212 return false;
6213 }
6214 return pb.getBoolean(
6215 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6216 }
6217
Shuo Qiandd210312017-04-12 22:11:33 +00006218 /**
6219 * Check if phone is in emergency callback mode
6220 * @return true if phone is in emergency callback mode
6221 * @param subId sub id
6222 */
goneil9c5f4872017-12-05 14:07:56 -08006223 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006224 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006225 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006226 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006227
6228 final long identity = Binder.clearCallingIdentity();
6229 try {
6230 if (phone != null) {
6231 return phone.isInEcm();
6232 } else {
6233 return false;
6234 }
6235 } finally {
6236 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006237 }
6238 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006239
6240 /**
6241 * Get the current signal strength information for the given subscription.
6242 * Because this information is not updated when the device is in a low power state
6243 * it should not be relied-upon to be current.
6244 * @param subId Subscription index
6245 * @return the most recent cached signal strength info from the modem
6246 */
6247 @Override
6248 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006249 final long identity = Binder.clearCallingIdentity();
6250 try {
6251 Phone p = getPhone(subId);
6252 if (p == null) {
6253 return null;
6254 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006255
Malcolm Chend965c8b2018-02-28 15:00:40 -08006256 return p.getSignalStrength();
6257 } finally {
6258 Binder.restoreCallingIdentity(identity);
6259 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006260 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006261
Pengquan Meng9140aec2018-08-22 14:49:57 -07006262 /**
chen xu907e5a22018-10-11 13:21:04 -07006263 * Get the current modem radio state for the given slot.
6264 * @param slotIndex slot index.
6265 * @param callingPackage the name of the package making the call.
6266 * @return the current radio power state from the modem
6267 */
6268 @Override
6269 public int getRadioPowerState(int slotIndex, String callingPackage) {
6270 Phone phone = PhoneFactory.getPhone(slotIndex);
6271 if (phone != null) {
6272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6273 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6274 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6275 }
6276
6277 final long identity = Binder.clearCallingIdentity();
6278 try {
6279 return phone.getRadioPowerState();
6280 } finally {
6281 Binder.restoreCallingIdentity(identity);
6282 }
6283 }
6284 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6285 }
6286
6287 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006288 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6289 *
6290 * <p>Requires one of the following permissions:
6291 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6292 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6293 * privileges.
6294 *
6295 * @param subId subscription id
6296 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6297 * {@code false}.
6298 */
6299 @Override
6300 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006301 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6302 null /* message */);
6303
Pengquan Meng0c05b502018-09-06 09:59:22 -07006304 boolean isEnabled = false;
6305 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006306 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006307 Phone phone = getPhone(subId);
6308 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006309 } catch (Exception e) {
6310 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6311 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006312 } finally {
6313 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006314 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006315 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006316 }
6317
6318
6319 /**
6320 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6321 *
6322 * <p> Requires permission:
6323 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6324 * privileges.
6325 *
6326 * @param subId subscription id
6327 * @param isEnabled {@code true} means enable, {@code false} means disable.
6328 */
6329 @Override
6330 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6332 mApp, subId, "setDataRoamingEnabled");
6333
Pengquan Meng0c05b502018-09-06 09:59:22 -07006334 final long identity = Binder.clearCallingIdentity();
6335 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006336 Phone phone = getPhone(subId);
6337 if (phone != null) {
6338 phone.setDataRoamingEnabled(isEnabled);
6339 }
6340 } finally {
6341 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006342 }
6343 }
6344
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006345 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006346 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006347 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6348 mApp, subId, "isManualNetworkSelectionAllowed");
6349
Pengquan Meng312de0c2018-10-03 12:19:13 -07006350 boolean isAllowed = true;
6351 final long identity = Binder.clearCallingIdentity();
6352 try {
Pengquan Meng312de0c2018-10-03 12:19:13 -07006353 Phone phone = getPhone(subId);
6354 if (phone != null) {
6355 isAllowed = phone.isCspPlmnEnabled();
6356 }
6357 } finally {
6358 Binder.restoreCallingIdentity(identity);
6359 }
6360 return isAllowed;
6361 }
6362
6363 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006364 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu67997952019-04-22 15:10:43 -07006365 boolean hasReadPermission = false;
Jordan Liu53fdb782019-02-12 17:54:02 -08006366 try {
6367 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu67997952019-04-22 15:10:43 -07006368 hasReadPermission = true;
Jordan Liu53fdb782019-02-12 17:54:02 -08006369 } catch (SecurityException e) {
6370 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6371 // has carrier privileges on an active UICC
6372 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6373 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu67997952019-04-22 15:10:43 -07006374 throw new SecurityException("Caller does not have permission.");
Jordan Liu53fdb782019-02-12 17:54:02 -08006375 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006376 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006377
6378 final long identity = Binder.clearCallingIdentity();
6379 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006380 UiccController uiccController = UiccController.getInstance();
6381 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu67997952019-04-22 15:10:43 -07006382 if (hasReadPermission) {
6383 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006384 }
Jordan Liu67997952019-04-22 15:10:43 -07006385
6386 // Remove private info if the caller doesn't have access
6387 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6388 for (UiccCardInfo cardInfo : cardInfos) {
6389 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6390 // is available
6391 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6392 if (card == null || card.getUiccProfile() == null) {
6393 // assume no access if the card or profile is unavailable
6394 filteredInfos.add(cardInfo.getUnprivileged());
6395 continue;
6396 }
6397 UiccProfile profile = card.getUiccProfile();
6398 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6399 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6400 filteredInfos.add(cardInfo);
6401 } else {
6402 filteredInfos.add(cardInfo.getUnprivileged());
6403 }
6404 }
6405 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006406 } finally {
6407 Binder.restoreCallingIdentity(identity);
6408 }
6409 }
6410
6411 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006412 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006413 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006414
Malcolm Chend965c8b2018-02-28 15:00:40 -08006415 final long identity = Binder.clearCallingIdentity();
6416 try {
6417 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6418 if (slots == null) {
6419 Rlog.i(LOG_TAG, "slots is null.");
6420 return null;
6421 }
6422
6423 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6424 for (int i = 0; i < slots.length; i++) {
6425 UiccSlot slot = slots[i];
6426 if (slot == null) {
6427 continue;
6428 }
6429
6430 String cardId;
6431 UiccCard card = slot.getUiccCard();
6432 if (card != null) {
6433 cardId = card.getCardId();
6434 } else {
6435 cardId = slot.getIccId();
6436 }
6437
Jordan Liu857451f2019-05-09 16:35:35 -07006438 if (cardId != null) {
6439 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6440 // if cardId is an EID, it's all digits so this is fine
6441 cardId = IccUtils.stripTrailingFs(cardId);
6442 }
6443
Malcolm Chend965c8b2018-02-28 15:00:40 -08006444 int cardState = 0;
6445 switch (slot.getCardState()) {
6446 case CARDSTATE_ABSENT:
6447 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6448 break;
6449 case CARDSTATE_PRESENT:
6450 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6451 break;
6452 case CARDSTATE_ERROR:
6453 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6454 break;
6455 case CARDSTATE_RESTRICTED:
6456 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6457 break;
6458 default:
6459 break;
6460
6461 }
6462
6463 infos[i] = new UiccSlotInfo(
6464 slot.isActive(),
6465 slot.isEuicc(),
6466 cardId,
6467 cardState,
6468 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006469 slot.isExtendedApduSupported(),
6470 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006471 }
6472 return infos;
6473 } finally {
6474 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006475 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006476 }
6477
6478 @Override
6479 public boolean switchSlots(int[] physicalSlots) {
6480 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006481
6482 final long identity = Binder.clearCallingIdentity();
6483 try {
6484 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6485 } finally {
6486 Binder.restoreCallingIdentity(identity);
6487 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006488 }
Jack Yu4c988042018-02-27 15:30:01 -08006489
6490 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006491 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006492 final long identity = Binder.clearCallingIdentity();
6493 try {
6494 return UiccController.getInstance().getCardIdForDefaultEuicc();
6495 } finally {
6496 Binder.restoreCallingIdentity(identity);
6497 }
6498 }
6499
6500 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006501 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6502 enforceModifyPermission();
6503 final Phone phone = getPhone(subId);
6504 if (phone == null) {
6505 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6506 return;
6507 }
6508
Malcolm Chend965c8b2018-02-28 15:00:40 -08006509 final long identity = Binder.clearCallingIdentity();
6510 try {
6511 phone.setRadioIndicationUpdateMode(filters, mode);
6512 } finally {
6513 Binder.restoreCallingIdentity(identity);
6514 }
Jack Yu4c988042018-02-27 15:30:01 -08006515 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006516
6517 /**
goneil47ffb6e2018-04-06 15:40:58 -07006518 * A test API to reload the UICC profile.
6519 *
6520 * <p>Requires that the calling app has permission
6521 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6522 * @hide
6523 */
6524 @Override
6525 public void refreshUiccProfile(int subId) {
6526 enforceModifyPermission();
6527
6528 final long identity = Binder.clearCallingIdentity();
6529 try {
6530 Phone phone = getPhone(subId);
6531 if (phone == null) {
6532 return;
6533 }
6534 UiccCard uiccCard = phone.getUiccCard();
6535 if (uiccCard == null) {
6536 return;
6537 }
6538 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6539 if (uiccProfile == null) {
6540 return;
6541 }
6542 uiccProfile.refresh();
6543 } finally {
6544 Binder.restoreCallingIdentity(identity);
6545 }
6546 }
6547
6548 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006549 * Returns false if the mobile data is disabled by default, otherwise return true.
6550 */
6551 private boolean getDefaultDataEnabled() {
6552 return "true".equalsIgnoreCase(
6553 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6554 }
6555
6556 /**
6557 * Returns true if the data roaming is enabled by default, i.e the system property
6558 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6559 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6560 */
6561 private boolean getDefaultDataRoamingEnabled(int subId) {
6562 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006563 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006564 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6565 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6566 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6567 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6568 return isDataRoamingEnabled;
6569 }
6570
6571 /**
6572 * Returns the default network type for the given {@code subId}, if the default network type is
6573 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6574 */
6575 private int getDefaultNetworkType(int subId) {
6576 return Integer.parseInt(
6577 TelephonyManager.getTelephonyProperty(
6578 mSubscriptionController.getPhoneId(subId),
6579 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6580 String.valueOf(Phone.PREFERRED_NT_MODE)));
6581 }
fionaxua13278b2018-03-21 00:08:13 -07006582
6583 @Override
6584 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6585 gid1, String gid2, String plmn, String spn) {
6586 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006587
6588 final long identity = Binder.clearCallingIdentity();
6589 try {
6590 final Phone phone = getPhone(subId);
6591 if (phone == null) {
6592 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6593 return;
6594 }
6595 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6596 } finally {
6597 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006598 }
fionaxua13278b2018-03-21 00:08:13 -07006599 }
6600
6601 @Override
6602 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006603 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006604
6605 final long identity = Binder.clearCallingIdentity();
6606 try {
6607 final Phone phone = getPhone(subId);
6608 if (phone == null) {
6609 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6610 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6611 }
6612 return phone.getCarrierIdListVersion();
6613 } finally {
6614 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006615 }
fionaxua13278b2018-03-21 00:08:13 -07006616 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006617
6618 @Override
6619 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6620 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6621 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6622 return -1;
6623 }
6624
6625 final long identity = Binder.clearCallingIdentity();
6626 try {
6627 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6628 } finally {
6629 Binder.restoreCallingIdentity(identity);
6630 }
6631 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006632
6633 @Override
6634 public int getCdmaRoamingMode(int subId) {
6635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6636 mApp, subId, "getCdmaRoamingMode");
6637
6638 final long identity = Binder.clearCallingIdentity();
6639 try {
6640 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6641 } finally {
6642 Binder.restoreCallingIdentity(identity);
6643 }
6644 }
6645
6646 @Override
6647 public boolean setCdmaRoamingMode(int subId, int mode) {
6648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6649 mApp, subId, "setCdmaRoamingMode");
6650
6651 final long identity = Binder.clearCallingIdentity();
6652 try {
6653 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6654 } finally {
6655 Binder.restoreCallingIdentity(identity);
6656 }
6657 }
6658
6659 @Override
6660 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6662 mApp, subId, "setCdmaSubscriptionMode");
6663
6664 final long identity = Binder.clearCallingIdentity();
6665 try {
6666 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6667 } finally {
6668 Binder.restoreCallingIdentity(identity);
6669 }
6670 }
chen xu7ee67862018-10-30 22:27:10 -07006671
sqian2fff4a32018-11-05 14:18:37 -08006672 private void ensureUserRunning(int userId) {
6673 if (!mUserManager.isUserRunning(userId)) {
6674 throw new IllegalStateException("User " + userId + " does not exist or not running");
6675 }
6676 }
6677
6678 /**
6679 * Returns a list of SMS apps on a given user.
6680 *
6681 * Only the shell user (UID 2000 or 0) can call it.
6682 * Target user must be running.
6683 */
6684 @Override
6685 public String[] getSmsApps(int userId) {
6686 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6687 ensureUserRunning(userId);
6688
6689 final Collection<SmsApplicationData> apps =
6690 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6691
6692 String[] ret = new String[apps.size()];
6693 int i = 0;
6694 for (SmsApplicationData app : apps) {
6695 ret[i++] = app.mPackageName;
6696 }
6697 return ret;
6698 }
6699
6700 /**
6701 * Returns the default SMS app package name on a given user.
6702 *
6703 * Only the shell user (UID 2000 or 0) can call it.
6704 * Target user must be running.
6705 */
6706 @Override
6707 public String getDefaultSmsApp(int userId) {
6708 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6709 ensureUserRunning(userId);
6710
6711 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6712 /* updateIfNeeded= */ true, userId);
6713 return cn == null ? null : cn.getPackageName();
6714 }
6715
6716 /**
6717 * Set a package as the default SMS app on a given user.
6718 *
6719 * Only the shell user (UID 2000 or 0) can call it.
6720 * Target user must be running.
6721 */
6722 @Override
6723 public void setDefaultSmsApp(int userId, String packageName) {
6724 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6725 ensureUserRunning(userId);
6726
6727 boolean found = false;
6728 for (String pkg : getSmsApps(userId)) {
6729 if (TextUtils.equals(packageName, pkg)) {
6730 found = true;
6731 break;
6732 }
6733 }
6734 if (!found) {
6735 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6736 }
6737
6738 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6739 }
6740
chen xu7ee67862018-10-30 22:27:10 -07006741 @Override
sqian65eefe12019-02-22 15:55:18 -08006742 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006743 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006744 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006745 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006746 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6747 }
6748 final long identity = Binder.clearCallingIdentity();
6749 try {
sqian991b35e2018-12-12 16:48:18 -08006750 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6751 for (Phone phone: PhoneFactory.getPhones()) {
6752 if (phone.getEmergencyNumberTracker() != null
6753 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6754 emergencyNumberListInternal.put(
6755 phone.getSubId(),
6756 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6757 }
sqian03bca152018-12-05 18:48:28 -08006758 }
sqian991b35e2018-12-12 16:48:18 -08006759 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006760 } finally {
6761 Binder.restoreCallingIdentity(identity);
6762 }
sqian04b86072018-11-07 14:02:21 -08006763 }
6764
6765 @Override
sqian65eefe12019-02-22 15:55:18 -08006766 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006767 final Phone defaultPhone = getDefaultPhone();
6768 if (!exactMatch) {
6769 TelephonyPermissions
6770 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006771 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006772 }
6773 final long identity = Binder.clearCallingIdentity();
6774 try {
sqian991b35e2018-12-12 16:48:18 -08006775 for (Phone phone: PhoneFactory.getPhones()) {
6776 if (phone.getEmergencyNumberTracker() != null
6777 && phone.getEmergencyNumberTracker() != null) {
6778 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6779 number, exactMatch)) {
6780 return true;
sqian03bca152018-12-05 18:48:28 -08006781 }
6782 }
sqian03bca152018-12-05 18:48:28 -08006783 }
6784 return false;
6785 } finally {
6786 Binder.restoreCallingIdentity(identity);
6787 }
6788 }
6789
sqian9d4df8b2019-01-15 18:32:07 -08006790 /**
6791 * Update emergency number list for test mode.
6792 */
6793 @Override
6794 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6795 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6796 "updateEmergencyNumberListTestMode");
6797
6798 final long identity = Binder.clearCallingIdentity();
6799 try {
6800 for (Phone phone: PhoneFactory.getPhones()) {
6801 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6802 if (tracker != null) {
6803 tracker.executeEmergencyNumberTestModeCommand(action, num);
6804 }
6805 }
6806 } finally {
6807 Binder.restoreCallingIdentity(identity);
6808 }
6809 }
6810
6811 /**
6812 * Get the full emergency number list for test mode.
6813 */
6814 @Override
6815 public List<String> getEmergencyNumberListTestMode() {
6816 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6817 "getEmergencyNumberListTestMode");
6818
6819 final long identity = Binder.clearCallingIdentity();
6820 try {
6821 Set<String> emergencyNumbers = new HashSet<>();
6822 for (Phone phone: PhoneFactory.getPhones()) {
6823 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6824 if (tracker != null) {
6825 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6826 emergencyNumbers.add(num.getNumber());
6827 }
6828 }
6829 }
6830 return new ArrayList<>(emergencyNumbers);
6831 } finally {
6832 Binder.restoreCallingIdentity(identity);
6833 }
6834 }
6835
sqian04b86072018-11-07 14:02:21 -08006836 @Override
chen xu7ee67862018-10-30 22:27:10 -07006837 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6838 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6839 Phone phone = getPhone(subId);
6840 if (phone == null) {
6841 return null;
6842 }
6843 final long identity = Binder.clearCallingIdentity();
6844 try {
6845 UiccProfile profile = UiccController.getInstance()
6846 .getUiccProfileForPhone(phone.getPhoneId());
6847 if (profile != null) {
6848 return profile.getCertsFromCarrierPrivilegeAccessRules();
6849 }
6850 } finally {
6851 Binder.restoreCallingIdentity(identity);
6852 }
6853 return null;
6854 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006855
6856 /**
6857 * Enable or disable a modem stack.
6858 */
6859 @Override
6860 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6861 enforceModifyPermission();
6862
6863 final long identity = Binder.clearCallingIdentity();
6864 try {
6865 Phone phone = PhoneFactory.getPhone(slotIndex);
6866 if (phone == null) {
6867 return false;
6868 } else {
6869 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6870 }
6871 } finally {
6872 Binder.restoreCallingIdentity(identity);
6873 }
6874 }
Micheled3107c52018-12-21 15:00:11 -08006875
Malcolm Chen33f55e12019-03-27 18:34:05 -07006876 /**
6877 * Whether a modem stack is enabled or not.
6878 */
6879 @Override
6880 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6881 Phone phone = PhoneFactory.getPhone(slotIndex);
6882 if (phone == null) return false;
6883
6884 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6885 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6886 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6887 }
6888
6889 final long identity = Binder.clearCallingIdentity();
6890 try {
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07006891 try {
6892 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6893 } catch (NoSuchElementException ex) {
6894 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6895 }
Malcolm Chen33f55e12019-03-27 18:34:05 -07006896 } finally {
6897 Binder.restoreCallingIdentity(identity);
6898 }
6899 }
6900
Micheled3107c52018-12-21 15:00:11 -08006901 @Override
Michele2fb0f222019-03-19 14:58:42 -07006902 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006903 enforceModifyPermission();
6904
6905 final long identity = Binder.clearCallingIdentity();
6906 try {
6907 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006908 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006909 .commit();
6910 } finally {
6911 Binder.restoreCallingIdentity(identity);
6912 }
6913 }
6914
6915 @Override
Michele2fb0f222019-03-19 14:58:42 -07006916 @TelephonyManager.IsMultiSimSupportedResult
6917 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006919 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6920 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006921 }
Micheled3107c52018-12-21 15:00:11 -08006922
6923 final long identity = Binder.clearCallingIdentity();
6924 try {
Michele2fb0f222019-03-19 14:58:42 -07006925 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006926 } finally {
6927 Binder.restoreCallingIdentity(identity);
6928 }
6929 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006930
Michele2fb0f222019-03-19 14:58:42 -07006931 @TelephonyManager.IsMultiSimSupportedResult
6932 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006933 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6934 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6935 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006936 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6937 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006938 }
6939 // Check if the hardware supports multisim functionality. If usage of multisim is not
6940 // supported by the modem, indicate that it is restricted.
6941 PhoneCapability staticCapability =
6942 mPhoneConfigurationManager.getStaticPhoneCapability();
6943 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006944 loge("isMultiSimSupportedInternal: no static configuration available");
6945 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006946 }
6947 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006948 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6949 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006950 }
6951 // Check if support of multiple SIMs is restricted by carrier
6952 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006953 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006954 }
6955
Michele2fb0f222019-03-19 14:58:42 -07006956 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006957 }
6958
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006959 /**
6960 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006961 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6962 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6963 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006964 * @param numOfSims number of active sims we want to switch to
6965 */
6966 @Override
6967 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006968 if (numOfSims == 1) {
6969 enforceModifyPermission();
6970 } else {
6971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6972 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6973 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006974 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006975
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006976 try {
Michele30b57b22019-03-01 12:01:14 -08006977 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006978 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006979 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6980 return;
6981 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006982 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6983 } finally {
6984 Binder.restoreCallingIdentity(identity);
6985 }
6986 }
6987
6988 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006989 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006990 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006991 */
6992 @Override
6993 public boolean isRebootRequiredForModemConfigChange() {
6994 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6995 final long identity = Binder.clearCallingIdentity();
6996 try {
6997 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6998 } finally {
6999 Binder.restoreCallingIdentity(identity);
7000 }
7001 }
7002
Pengquan Meng92d253b2019-02-06 11:12:53 -08007003 private void updateModemStateMetrics() {
7004 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7005 // TODO: check the state for each modem if the api is ready.
7006 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7007 }
7008
Pengquan Meng3aceaec2019-01-23 11:16:29 -08007009 @Override
7010 public int[] getSlotsMapping() {
7011 enforceReadPrivilegedPermission("getSlotsMapping");
7012
7013 final long identity = Binder.clearCallingIdentity();
7014 try {
7015 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7016 // All logical slots should have a mapping to a physical slot.
7017 int[] logicalSlotsMapping = new int[phoneCount];
7018 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7019 for (int i = 0; i < slotInfos.length; i++) {
7020 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7021 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7022 }
7023 }
7024 return logicalSlotsMapping;
7025 } finally {
7026 Binder.restoreCallingIdentity(identity);
7027 }
7028 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007029
7030 /**
7031 * Get the IRadio HAL Version
7032 */
7033 @Override
7034 public int getRadioHalVersion() {
7035 Phone phone = getDefaultPhone();
7036 if (phone == null) return -1;
7037 HalVersion hv = phone.getHalVersion();
7038 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7039 return hv.major * 100 + hv.minor;
7040 }
Malcolm Chen460810d2019-04-10 18:25:07 -07007041
7042 /**
Malcolm Chen29739692019-04-18 13:51:02 -07007043 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7044 * corresponding network requests on a subId.
7045 *
7046 * Data is enabled if:
Malcolm Chen460810d2019-04-10 18:25:07 -07007047 * 1) user data is turned on, or
Malcolm Chen29739692019-04-18 13:51:02 -07007048 * 2) APN is un-metered for this subscription, or
7049 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7050 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7051 *
7052 * @return whether data is allowed for a apn type.
7053 *
7054 * @hide
Malcolm Chen460810d2019-04-10 18:25:07 -07007055 */
7056 @Override
Malcolm Chen29739692019-04-18 13:51:02 -07007057 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chen460810d2019-04-10 18:25:07 -07007058 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chen29739692019-04-18 13:51:02 -07007059 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7060 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chen460810d2019-04-10 18:25:07 -07007061 }
7062
7063 // Now that all security checks passes, perform the operation as ourselves.
7064 final long identity = Binder.clearCallingIdentity();
7065 try {
7066 Phone phone = getPhone(subId);
7067 if (phone == null) return false;
7068
Jack Yu40306fc2019-05-13 16:54:09 -07007069 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chen29739692019-04-18 13:51:02 -07007070 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7071 } finally {
7072 Binder.restoreCallingIdentity(identity);
7073 }
7074 }
7075
7076 @Override
Jack Yu40306fc2019-05-13 16:54:09 -07007077 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chen29739692019-04-18 13:51:02 -07007078 enforceReadPrivilegedPermission("isApnMetered");
7079
7080 // Now that all security checks passes, perform the operation as ourselves.
7081 final long identity = Binder.clearCallingIdentity();
7082 try {
7083 Phone phone = getPhone(subId);
7084 if (phone == null) return true; // By default return true.
7085
Jack Yu40306fc2019-05-13 16:54:09 -07007086 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chen460810d2019-04-10 18:25:07 -07007087 } finally {
7088 Binder.restoreCallingIdentity(identity);
7089 }
7090 }
chen xu7bc8e072019-05-28 15:20:57 -07007091
7092 @Override
Brad Ebinger5ff97f62019-04-23 16:31:13 -07007093 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7094 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7095 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7096 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7097 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7098 }
7099 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7100 Intent intent = new Intent();
7101 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7102 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7103 // Bring up choose default SMS subscription dialog right now
7104 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7105 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7106 mApp.startActivity(intent);
7107 }
7108
7109 @Override
chen xu7bc8e072019-05-28 15:20:57 -07007110 public String getMmsUAProfUrl(int subId) {
7111 //TODO investigate if this API should require proper permission check in R b/133791609
7112 final long identity = Binder.clearCallingIdentity();
7113 try {
7114 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7115 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7116 } finally {
7117 Binder.restoreCallingIdentity(identity);
7118 }
7119 }
7120
7121 @Override
7122 public String getMmsUserAgent(int subId) {
7123 //TODO investigate if this API should require proper permission check in R b/133791609
7124 final long identity = Binder.clearCallingIdentity();
7125 try {
7126 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7127 .getString(com.android.internal.R.string.config_mms_user_agent);
7128 } finally {
7129 Binder.restoreCallingIdentity(identity);
7130 }
7131 }
Jack Yuea3bebe2019-05-28 16:12:25 -07007132
7133 @Override
7134 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7135 enforceModifyPermission();
7136
7137 // Now that all security checks passes, perform the operation as ourselves.
7138 final long identity = Binder.clearCallingIdentity();
7139 try {
7140 Phone phone = getPhone(subId);
7141 if (phone == null) return false;
7142
7143 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7144 } finally {
7145 Binder.restoreCallingIdentity(identity);
7146 }
7147 }
7148
7149 @Override
7150 public boolean isDataAllowedInVoiceCall(int subId) {
7151 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7152
7153 // Now that all security checks passes, perform the operation as ourselves.
7154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 Phone phone = getPhone(subId);
7157 if (phone == null) return false;
7158
7159 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7160 } finally {
7161 Binder.restoreCallingIdentity(identity);
7162 }
7163 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007164}