blob: 4a36be71b04ab399b5eded808087b5d6afaf792c [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070027import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.content.Context;
29import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070030import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070031import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070032import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080033import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070034import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070035import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.net.Uri;
37import android.os.AsyncResult;
38import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080039import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.os.Bundle;
41import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070042import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Looper;
44import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070046import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080047import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070048import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070050import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070051import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070053import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070054import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070055import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080056import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070057import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080058import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080059import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070060import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070061import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080062import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070064import android.telephony.CellInfoGsm;
65import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070066import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070067import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070068import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070069import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080070import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070071import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080072import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070073import android.telephony.NetworkScanRequest;
Michelebcb01bc2019-02-04 11:36:23 -080074import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080075import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070076import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080077import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070078import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080080import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070081import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080082import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080083import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070084import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070085import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080087import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000088import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070089import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070090import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070091import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080092import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080093import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070094import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080095import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070096import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080097import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070098import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080099import android.telephony.ims.aidl.IImsMmTelFeature;
100import android.telephony.ims.aidl.IImsRcsFeature;
101import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -0700102import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800103import android.telephony.ims.feature.MmTelFeature;
104import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800105import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800107import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800109import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800110import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800111
Brad Ebinger4c460712018-10-01 10:40:55 -0700112import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700113import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800114import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700115import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700116import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700117import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800118import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700119import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700120import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800122import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800123import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800125import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700126import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100127import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700128import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700129import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700131import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800132import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700133import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700134import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700135import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700136import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700137import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700138import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800139import com.android.internal.telephony.SmsApplication;
140import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800141import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800142import com.android.internal.telephony.TelephonyPermissions;
sqian9d4df8b2019-01-15 18:32:07 -0800143import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700144import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebingereb160e22019-01-23 15:06:19 -0800145import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800146import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.uicc.IccIoResult;
148import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800149import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700150import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800151import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700152import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800153import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000154import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700155import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800156import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700157import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800158import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700159import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700160import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800161
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700162import java.io.FileDescriptor;
163import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800164import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800166import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800167import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800168import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800169import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800170import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100171import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800172import java.util.Map;
sqian9d4df8b2019-01-15 18:32:07 -0800173import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174
175/**
176 * Implementation of the ITelephony interface.
177 */
Santos Cordon117fee72014-05-16 17:56:12 -0700178public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179 private static final String LOG_TAG = "PhoneInterfaceManager";
180 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
181 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800182 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700183
184 // Message codes used with mMainThreadHandler
185 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700186 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
187 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700188 private static final int CMD_OPEN_CHANNEL = 9;
189 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
190 private static final int CMD_CLOSE_CHANNEL = 11;
191 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800192 private static final int CMD_NV_READ_ITEM = 13;
193 private static final int EVENT_NV_READ_ITEM_DONE = 14;
194 private static final int CMD_NV_WRITE_ITEM = 15;
195 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
196 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
197 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700198 private static final int CMD_RESET_MODEM_CONFIG = 19;
199 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800200 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
201 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
202 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
203 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800204 private static final int CMD_SEND_ENVELOPE = 25;
205 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000206 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
207 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700208 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
209 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
210 private static final int CMD_EXCHANGE_SIM_IO = 31;
211 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800212 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
213 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700214 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
215 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700216 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
217 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700218 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
219 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
220 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
221 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700222 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
223 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
224 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
225 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700226 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800227 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
228 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000229 private static final int CMD_SWITCH_SLOTS = 50;
230 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700231 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
232 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
233 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
234 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
235 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
236 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
237 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
238 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700239 private static final int CMD_GET_ALL_CELL_INFO = 60;
240 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
241 private static final int CMD_GET_CELL_LOCATION = 62;
242 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700243 private static final int CMD_MODEM_REBOOT = 64;
244 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700245 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
246 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800247 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
248 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800250 // Parameters of select command.
251 private static final int SELECT_COMMAND = 0xA4;
252 private static final int SELECT_P1 = 0x04;
253 private static final int SELECT_P2 = 0;
254 private static final int SELECT_P3 = 0x10;
255
Pengquan Meng85728fb2018-03-12 16:31:21 -0700256 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
257 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
258 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
259
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700260 /** The singleton instance. */
261 private static PhoneInterfaceManager sInstance;
262
Wink Saville3ab207e2014-11-20 13:07:20 -0800263 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800264 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700265 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800266 private AppOpsManager mAppOps;
267 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800268 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800269 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700270 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271
Derek Tan97ebb422014-09-05 16:55:38 -0700272 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
273 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800274 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800275 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700276
Micheled3107c52018-12-21 15:00:11 -0800277 // String to store multi SIM allowed
278 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
279
Derek Tan740e1672017-06-27 14:56:27 -0700280 // The AID of ISD-R.
281 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
282
yinxub1bed742017-04-17 11:45:04 -0700283 private NetworkScanRequestTracker mNetworkScanRequestTracker;
284
David Kelly5e06a7f2018-03-12 14:10:59 +0000285 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
286 private static final int MANUFACTURER_CODE_LENGTH = 8;
287
Derek Tan89e89d42014-07-08 17:00:10 -0700288 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700289 * A request object to use for transmitting data to an ICC.
290 */
291 private static final class IccAPDUArgument {
292 public int channel, cla, command, p1, p2, p3;
293 public String data;
294
295 public IccAPDUArgument(int channel, int cla, int command,
296 int p1, int p2, int p3, String data) {
297 this.channel = channel;
298 this.cla = cla;
299 this.command = command;
300 this.p1 = p1;
301 this.p2 = p2;
302 this.p3 = p3;
303 this.data = data;
304 }
305 }
306
307 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700308 * A request object to use for transmitting data to an ICC.
309 */
310 private static final class ManualNetworkSelectionArgument {
311 public OperatorInfo operatorInfo;
312 public boolean persistSelection;
313
314 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
315 this.operatorInfo = operatorInfo;
316 this.persistSelection = persistSelection;
317 }
318 }
319
320 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700321 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
322 * request after sending. The main thread will notify the request when it is complete.
323 */
324 private static final class MainThreadRequest {
325 /** The argument to use for the request */
326 public Object argument;
327 /** The result of the request that is run on the main thread */
328 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800329 // The subscriber id that this request applies to. Defaults to
330 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
331 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332
Nathan Harold92bed182018-10-12 18:16:49 -0700333 // In cases where subId is unavailable, the caller needs to specify the phone.
334 public Phone phone;
335
vagdevie435a3e2018-08-15 16:01:53 -0700336 public WorkSource workSource;
337
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 public MainThreadRequest(Object argument) {
339 this.argument = argument;
340 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800341
Nathan Harold92bed182018-10-12 18:16:49 -0700342 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
343 this.argument = argument;
344 if (phone != null) {
345 this.phone = phone;
346 }
347 this.workSource = workSource;
348 }
349
vagdevie435a3e2018-08-15 16:01:53 -0700350 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800351 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800352 if (subId != null) {
353 this.subId = subId;
354 }
vagdevie435a3e2018-08-15 16:01:53 -0700355 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800356 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357 }
358
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800359 private static final class IncomingThirdPartyCallArgs {
360 public final ComponentName component;
361 public final String callId;
362 public final String callerDisplayName;
363
364 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
365 String callerDisplayName) {
366 this.component = component;
367 this.callId = callId;
368 this.callerDisplayName = callerDisplayName;
369 }
370 }
371
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 /**
373 * A handler that processes messages on the main thread in the phone process. Since many
374 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
375 * inbound binder threads to the main thread in the phone process. The Binder thread
376 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
377 * on, which will be notified when the operation completes and will contain the result of the
378 * request.
379 *
380 * <p>If a MainThreadRequest object is provided in the msg.obj field,
381 * note that request.result must be set to something non-null for the calling thread to
382 * unblock.
383 */
384 private final class MainThreadHandler extends Handler {
385 @Override
386 public void handleMessage(Message msg) {
387 MainThreadRequest request;
388 Message onCompleted;
389 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800390 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700391 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800392 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393
394 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700395 case CMD_HANDLE_USSD_REQUEST: {
396 request = (MainThreadRequest) msg.obj;
397 final Phone phone = getPhoneFromRequest(request);
398 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
399 String ussdRequest = ussdObject.first;
400 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700401
Pengquan Meng0c05b502018-09-06 09:59:22 -0700402 if (!isUssdApiAllowed(request.subId)) {
403 // Carrier does not support use of this API, return failure.
404 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
405 UssdResponse response = new UssdResponse(ussdRequest, null);
406 Bundle returnData = new Bundle();
407 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
408 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700409
Pengquan Meng0c05b502018-09-06 09:59:22 -0700410 request.result = true;
411 notifyRequester(request);
412 return;
413 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700414
Pengquan Meng0c05b502018-09-06 09:59:22 -0700415 try {
416 request.result = phone != null
417 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
418 } catch (CallStateException cse) {
419 request.result = false;
420 }
421 // Wake up the requesting thread
422 notifyRequester(request);
423 break;
pkanwar32d516d2016-10-14 19:37:38 -0700424 }
425
Yorke Lee716f67e2015-06-17 15:39:16 -0700426 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700428 final Phone phone = getPhoneFromRequest(request);
429 request.result = phone != null ?
430 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
431 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700433 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700439 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800440 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700441 if (uiccCard == null) {
442 loge("iccTransmitApduLogicalChannel: No UICC");
443 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700444 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700445 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
447 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700448 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700449 iccArgument.channel, iccArgument.cla, iccArgument.command,
450 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700451 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700452 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700453 break;
454
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 ar = (AsyncResult) msg.obj;
457 request = (MainThreadRequest) ar.userObj;
458 if (ar.exception == null && ar.result != null) {
459 request.result = ar.result;
460 } else {
461 request.result = new IccIoResult(0x6F, 0, (byte[])null);
462 if (ar.result == null) {
463 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800464 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800466 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700467 } else {
468 loge("iccTransmitApduLogicalChannel: Unknown exception");
469 }
470 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700471 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 break;
473
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700474 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
475 request = (MainThreadRequest) msg.obj;
476 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800477 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 if (uiccCard == null) {
479 loge("iccTransmitApduBasicChannel: No UICC");
480 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700481 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 } else {
483 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
484 request);
485 uiccCard.iccTransmitApduBasicChannel(
486 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
487 iccArgument.p3, iccArgument.data, onCompleted);
488 }
489 break;
490
491 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
492 ar = (AsyncResult) msg.obj;
493 request = (MainThreadRequest) ar.userObj;
494 if (ar.exception == null && ar.result != null) {
495 request.result = ar.result;
496 } else {
497 request.result = new IccIoResult(0x6F, 0, (byte[])null);
498 if (ar.result == null) {
499 loge("iccTransmitApduBasicChannel: Empty response");
500 } else if (ar.exception instanceof CommandException) {
501 loge("iccTransmitApduBasicChannel: CommandException: " +
502 ar.exception);
503 } else {
504 loge("iccTransmitApduBasicChannel: Unknown exception");
505 }
506 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700507 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 break;
509
510 case CMD_EXCHANGE_SIM_IO:
511 request = (MainThreadRequest) msg.obj;
512 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800513 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700514 if (uiccCard == null) {
515 loge("iccExchangeSimIO: No UICC");
516 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700517 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700518 } else {
519 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
520 request);
521 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
522 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
523 iccArgument.data, onCompleted);
524 }
525 break;
526
527 case EVENT_EXCHANGE_SIM_IO_DONE:
528 ar = (AsyncResult) msg.obj;
529 request = (MainThreadRequest) ar.userObj;
530 if (ar.exception == null && ar.result != null) {
531 request.result = ar.result;
532 } else {
533 request.result = new IccIoResult(0x6f, 0, (byte[])null);
534 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700535 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 break;
537
Derek Tan4d5e5c12014-02-04 11:54:58 -0800538 case CMD_SEND_ENVELOPE:
539 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800540 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700541 if (uiccCard == null) {
542 loge("sendEnvelopeWithStatus: No UICC");
543 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700544 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700545 } else {
546 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
547 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
548 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800549 break;
550
551 case EVENT_SEND_ENVELOPE_DONE:
552 ar = (AsyncResult) msg.obj;
553 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700554 if (ar.exception == null && ar.result != null) {
555 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800556 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700557 request.result = new IccIoResult(0x6F, 0, (byte[])null);
558 if (ar.result == null) {
559 loge("sendEnvelopeWithStatus: Empty response");
560 } else if (ar.exception instanceof CommandException) {
561 loge("sendEnvelopeWithStatus: CommandException: " +
562 ar.exception);
563 } else {
564 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
565 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800566 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700567 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800568 break;
569
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 case CMD_OPEN_CHANNEL:
571 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800572 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800573 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700574 if (uiccCard == null) {
575 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800576 request.result = new IccOpenLogicalChannelResponse(-1,
577 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700578 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 } else {
580 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800581 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
582 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 break;
585
586 case EVENT_OPEN_CHANNEL_DONE:
587 ar = (AsyncResult) msg.obj;
588 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 int[] result = (int[]) ar.result;
592 int channelId = result[0];
593 byte[] selectResponse = null;
594 if (result.length > 1) {
595 selectResponse = new byte[result.length - 1];
596 for (int i = 1; i < result.length; ++i) {
597 selectResponse[i - 1] = (byte) result[i];
598 }
599 }
600 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700601 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 if (ar.result == null) {
604 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 if (ar.exception != null) {
607 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
608 }
609
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700611 if (ar.exception instanceof CommandException) {
612 CommandException.Error error =
613 ((CommandException) (ar.exception)).getCommandError();
614 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700615 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700616 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700617 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 }
619 }
620 openChannelResp = new IccOpenLogicalChannelResponse(
621 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700623 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 break;
626
627 case CMD_CLOSE_CHANNEL:
628 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800629 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 if (uiccCard == null) {
631 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900632 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700634 } else {
635 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
636 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
637 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 break;
639
640 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800641 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
642 break;
643
644 case CMD_NV_READ_ITEM:
645 request = (MainThreadRequest) msg.obj;
646 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800647 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
648 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800649 break;
650
651 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 ar = (AsyncResult) msg.obj;
653 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800654 if (ar.exception == null && ar.result != null) {
655 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800657 request.result = "";
658 if (ar.result == null) {
659 loge("nvReadItem: Empty response");
660 } else if (ar.exception instanceof CommandException) {
661 loge("nvReadItem: CommandException: " +
662 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800664 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 }
666 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 break;
669
Jake Hambye994d462014-02-03 13:10:13 -0800670 case CMD_NV_WRITE_ITEM:
671 request = (MainThreadRequest) msg.obj;
672 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
673 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800674 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700675 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800676 break;
677
678 case EVENT_NV_WRITE_ITEM_DONE:
679 handleNullReturnEvent(msg, "nvWriteItem");
680 break;
681
682 case CMD_NV_WRITE_CDMA_PRL:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800685 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800686 break;
687
688 case EVENT_NV_WRITE_CDMA_PRL_DONE:
689 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
690 break;
691
chen xu1cc0abe2018-10-26 17:39:23 -0700692 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800693 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700694 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800695 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800696 break;
697
chen xu1cc0abe2018-10-26 17:39:23 -0700698 case EVENT_RESET_MODEM_CONFIG_DONE:
699 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800700 break;
701
Jake Hamby7c27be32014-03-03 13:25:59 -0800702 case CMD_GET_PREFERRED_NETWORK_TYPE:
703 request = (MainThreadRequest) msg.obj;
704 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700705 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800706 break;
707
708 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
709 ar = (AsyncResult) msg.obj;
710 request = (MainThreadRequest) ar.userObj;
711 if (ar.exception == null && ar.result != null) {
712 request.result = ar.result; // Integer
713 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800714 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800715 if (ar.result == null) {
716 loge("getPreferredNetworkType: Empty response");
717 } else if (ar.exception instanceof CommandException) {
718 loge("getPreferredNetworkType: CommandException: " +
719 ar.exception);
720 } else {
721 loge("getPreferredNetworkType: Unknown exception");
722 }
723 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700724 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800725 break;
726
727 case CMD_SET_PREFERRED_NETWORK_TYPE:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
730 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700731 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800732 break;
733
734 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
735 handleNullReturnEvent(msg, "setPreferredNetworkType");
736 break;
737
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000738 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
739 request = (MainThreadRequest)msg.obj;
740 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800741 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000742 break;
743
744 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
745 ar = (AsyncResult)msg.obj;
746 request = (MainThreadRequest)ar.userObj;
747 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700748 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000749 break;
750
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800751 case CMD_SET_VOICEMAIL_NUMBER:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
754 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800755 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
756 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800757 break;
758
759 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
760 handleNullReturnEvent(msg, "setVoicemailNumber");
761 break;
762
Stuart Scott54788802015-03-30 13:18:01 -0700763 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
766 request);
767 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
768 break;
769
770 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
771 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
772 break;
773
Shishir Agrawal302c8692015-06-19 13:49:39 -0700774 case CMD_PERFORM_NETWORK_SCAN:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
777 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
778 break;
779
780 case EVENT_PERFORM_NETWORK_SCAN_DONE:
781 ar = (AsyncResult) msg.obj;
782 request = (MainThreadRequest) ar.userObj;
783 CellNetworkScanResult cellScanResult;
784 if (ar.exception == null && ar.result != null) {
785 cellScanResult = new CellNetworkScanResult(
786 CellNetworkScanResult.STATUS_SUCCESS,
787 (List<OperatorInfo>) ar.result);
788 } else {
789 if (ar.result == null) {
790 loge("getCellNetworkScanResults: Empty response");
791 }
792 if (ar.exception != null) {
793 loge("getCellNetworkScanResults: Exception: " + ar.exception);
794 }
795 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
796 if (ar.exception instanceof CommandException) {
797 CommandException.Error error =
798 ((CommandException) (ar.exception)).getCommandError();
799 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
800 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
801 } else if (error == CommandException.Error.GENERIC_FAILURE) {
802 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
803 }
804 }
805 cellScanResult = new CellNetworkScanResult(errorCode, null);
806 }
807 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700808 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700809 break;
810
811 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
812 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700813 ManualNetworkSelectionArgument selArg =
814 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700815 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
816 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700817 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
818 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700819 break;
820
821 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700822 ar = (AsyncResult) msg.obj;
823 request = (MainThreadRequest) ar.userObj;
824 if (ar.exception == null) {
825 request.result = true;
826 } else {
827 request.result = false;
828 loge("setNetworkSelectionModeManual " + ar.exception);
829 }
830 notifyRequester(request);
831 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700832 break;
833
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700834 case CMD_GET_MODEM_ACTIVITY_INFO:
835 request = (MainThreadRequest) msg.obj;
836 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800837 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700838 break;
839
840 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
841 ar = (AsyncResult) msg.obj;
842 request = (MainThreadRequest) ar.userObj;
843 if (ar.exception == null && ar.result != null) {
844 request.result = ar.result;
845 } else {
846 if (ar.result == null) {
847 loge("queryModemActivityInfo: Empty response");
848 } else if (ar.exception instanceof CommandException) {
849 loge("queryModemActivityInfo: CommandException: " +
850 ar.exception);
851 } else {
852 loge("queryModemActivityInfo: Unknown exception");
853 }
854 }
Amit Mahajand4766222016-01-28 15:28:28 -0800855 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
856 if (request.result == null) {
857 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
858 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700859 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700860 break;
861
Meng Wang1a7c35a2016-05-05 20:56:15 -0700862 case CMD_SET_ALLOWED_CARRIERS:
863 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800864 CarrierRestrictionRules argument =
865 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700866 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800867 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700868 break;
869
870 case EVENT_SET_ALLOWED_CARRIERS_DONE:
871 ar = (AsyncResult) msg.obj;
872 request = (MainThreadRequest) ar.userObj;
873 if (ar.exception == null && ar.result != null) {
874 request.result = ar.result;
875 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800876 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
877 if (ar.exception instanceof CommandException) {
878 loge("setAllowedCarriers: CommandException: " + ar.exception);
879 CommandException.Error error =
880 ((CommandException) (ar.exception)).getCommandError();
881 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
882 request.result =
883 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
884 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 } else {
886 loge("setAllowedCarriers: Unknown exception");
887 }
888 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700889 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700890 break;
891
892 case CMD_GET_ALLOWED_CARRIERS:
893 request = (MainThreadRequest) msg.obj;
894 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800895 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700896 break;
897
898 case EVENT_GET_ALLOWED_CARRIERS_DONE:
899 ar = (AsyncResult) msg.obj;
900 request = (MainThreadRequest) ar.userObj;
901 if (ar.exception == null && ar.result != null) {
902 request.result = ar.result;
903 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800904 request.result = new IllegalStateException(
905 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700906 if (ar.result == null) {
907 loge("getAllowedCarriers: Empty response");
908 } else if (ar.exception instanceof CommandException) {
909 loge("getAllowedCarriers: CommandException: " +
910 ar.exception);
911 } else {
912 loge("getAllowedCarriers: Unknown exception");
913 }
914 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700915 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700916 break;
917
Nathan Haroldb3014052017-01-25 15:57:32 -0800918 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
921 if (ar.exception == null && ar.result != null) {
922 request.result = ar.result;
923 } else {
924 request.result = new IllegalArgumentException(
925 "Failed to retrieve Forbidden Plmns");
926 if (ar.result == null) {
927 loge("getForbiddenPlmns: Empty response");
928 } else {
929 loge("getForbiddenPlmns: Unknown exception");
930 }
931 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700932 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800933 break;
934
935 case CMD_GET_FORBIDDEN_PLMNS:
936 request = (MainThreadRequest) msg.obj;
937 uiccCard = getUiccCardFromRequest(request);
938 if (uiccCard == null) {
939 loge("getForbiddenPlmns() UiccCard is null");
940 request.result = new IllegalArgumentException(
941 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700942 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800943 break;
944 }
945 Integer appType = (Integer) request.argument;
946 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
947 if (uiccApp == null) {
948 loge("getForbiddenPlmns() no app with specified type -- "
949 + appType);
950 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700951 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800952 break;
953 } else {
954 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
955 + " specified type -- " + appType);
956 }
957 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
958 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
959 onCompleted);
960 break;
961
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000962 case CMD_SWITCH_SLOTS:
963 request = (MainThreadRequest) msg.obj;
964 int[] physicalSlots = (int[]) request.argument;
965 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
966 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
967 break;
968
969 case EVENT_SWITCH_SLOTS_DONE:
970 ar = (AsyncResult) msg.obj;
971 request = (MainThreadRequest) ar.userObj;
972 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700973 notifyRequester(request);
974 break;
975 case CMD_GET_NETWORK_SELECTION_MODE:
976 request = (MainThreadRequest) msg.obj;
977 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
978 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
979 break;
980
981 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 if (ar.exception != null) {
985 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
986 } else {
987 int mode = ((int[]) ar.result)[0];
988 if (mode == 0) {
989 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
990 } else {
991 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
992 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000993 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700994 notifyRequester(request);
995 break;
996 case CMD_GET_CDMA_ROAMING_MODE:
997 request = (MainThreadRequest) msg.obj;
998 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
999 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1000 break;
1001 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
1004 if (ar.exception != null) {
1005 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1006 } else {
1007 request.result = ((int[]) ar.result)[0];
1008 }
1009 notifyRequester(request);
1010 break;
1011 case CMD_SET_CDMA_ROAMING_MODE:
1012 request = (MainThreadRequest) msg.obj;
1013 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1014 int mode = (int) request.argument;
1015 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1016 break;
1017 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1018 ar = (AsyncResult) msg.obj;
1019 request = (MainThreadRequest) ar.userObj;
1020 request.result = ar.exception == null;
1021 notifyRequester(request);
1022 break;
1023 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1026 int subscriptionMode = (int) request.argument;
1027 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1028 break;
1029 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 request.result = ar.exception == null;
1033 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001034 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001035 case CMD_GET_ALL_CELL_INFO:
1036 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001037 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001038 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001039 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001040 case EVENT_GET_ALL_CELL_INFO_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001043 // If a timeout occurs, the response will be null
1044 request.result = (ar.exception == null && ar.result != null)
1045 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001046 synchronized (request) {
1047 request.notifyAll();
1048 }
1049 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001050 case CMD_REQUEST_CELL_INFO_UPDATE:
1051 request = (MainThreadRequest) msg.obj;
1052 request.phone.requestCellInfoUpdate(request.workSource,
1053 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1054 break;
1055 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1056 ar = (AsyncResult) msg.obj;
1057 request = (MainThreadRequest) ar.userObj;
1058 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1059 try {
1060 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001062 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1063 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001064 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001065 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001066 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001067 } else {
1068 // use the result as returned
1069 cb.onCellInfo((List<CellInfo>) ar.result);
1070 }
1071 } catch (RemoteException re) {
1072 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1073 }
1074 break;
1075 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001076 request = (MainThreadRequest) msg.obj;
1077 WorkSource ws = (WorkSource) request.argument;
1078 Phone phone = getPhoneFromRequest(request);
1079 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1080 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001081 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001082 ar = (AsyncResult) msg.obj;
1083 request = (MainThreadRequest) ar.userObj;
1084 if (ar.exception == null) {
1085 request.result = ar.result;
1086 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001087 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001088 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1089 ? new CdmaCellLocation() : new GsmCellLocation();
1090 }
1091
1092 synchronized (request) {
1093 request.notifyAll();
1094 }
1095 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001096 case CMD_MODEM_REBOOT:
1097 request = (MainThreadRequest) msg.obj;
1098 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001099 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001100 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001101 case EVENT_CMD_MODEM_REBOOT_DONE:
1102 handleNullReturnEvent(msg, "rebootModem");
1103 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001104 case CMD_REQUEST_ENABLE_MODEM:
1105 request = (MainThreadRequest) msg.obj;
1106 boolean enable = (boolean) request.argument;
1107 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001108 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001109 PhoneConfigurationManager.getInstance()
1110 .enablePhone(request.phone, enable, onCompleted);
1111 break;
1112 case EVENT_ENABLE_MODEM_DONE:
1113 ar = (AsyncResult) msg.obj;
1114 request = (MainThreadRequest) ar.userObj;
1115 request.result = (ar.exception == null);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001116 //update the cache as modem status has changed
1117 mPhoneConfigurationManager.addToPhoneStatusCache(
1118 request.phone.getPhoneId(), msg.arg1 == 1);
Pengquan Meng92d253b2019-02-06 11:12:53 -08001119 updateModemStateMetrics();
Malcolm Chen509b5b72019-01-15 20:22:16 -08001120 notifyRequester(request);
1121 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001122 default:
1123 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1124 break;
1125 }
1126 }
Jake Hambye994d462014-02-03 13:10:13 -08001127
Pengquan Meng0c05b502018-09-06 09:59:22 -07001128 private void notifyRequester(MainThreadRequest request) {
1129 synchronized (request) {
1130 request.notifyAll();
1131 }
1132 }
1133
Jake Hambye994d462014-02-03 13:10:13 -08001134 private void handleNullReturnEvent(Message msg, String command) {
1135 AsyncResult ar = (AsyncResult) msg.obj;
1136 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1137 if (ar.exception == null) {
1138 request.result = true;
1139 } else {
1140 request.result = false;
1141 if (ar.exception instanceof CommandException) {
1142 loge(command + ": CommandException: " + ar.exception);
1143 } else {
1144 loge(command + ": Unknown exception");
1145 }
1146 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001147 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001148 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001149 }
1150
1151 /**
1152 * Posts the specified command to be executed on the main thread,
1153 * waits for the request to complete, and returns the result.
1154 * @see #sendRequestAsync
1155 */
1156 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001157 return sendRequest(
1158 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001159 }
1160
1161 /**
1162 * Posts the specified command to be executed on the main thread,
1163 * waits for the request to complete, and returns the result.
1164 * @see #sendRequestAsync
1165 */
1166 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1167 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001168 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001169 }
1170
1171 /**
1172 * Posts the specified command to be executed on the main thread,
1173 * waits for the request to complete, and returns the result.
1174 * @see #sendRequestAsync
1175 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001176 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001177 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001178 }
1179
1180 /**
1181 * Posts the specified command to be executed on the main thread,
1182 * waits for the request to complete, and returns the result.
1183 * @see #sendRequestAsync
1184 */
Nathan Harold92bed182018-10-12 18:16:49 -07001185 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1186 return sendRequest(command, argument, subId, null, workSource);
1187 }
1188
1189 /**
1190 * Posts the specified command to be executed on the main thread,
1191 * waits for the request to complete, and returns the result.
1192 * @see #sendRequestAsync
1193 */
1194 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1195 return sendRequest(
1196 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1197 }
1198
1199 /**
1200 * Posts the specified command to be executed on the main thread,
1201 * waits for the request to complete, and returns the result.
1202 * @see #sendRequestAsync
1203 */
1204 private Object sendRequest(
1205 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001206 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1207 throw new RuntimeException("This method will deadlock if called from the main thread.");
1208 }
1209
Nathan Harold92bed182018-10-12 18:16:49 -07001210 MainThreadRequest request = null;
1211 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1212 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1213 } else if (phone != null) {
1214 request = new MainThreadRequest(argument, phone, workSource);
1215 } else {
1216 request = new MainThreadRequest(argument, subId, workSource);
1217 }
1218
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 Message msg = mMainThreadHandler.obtainMessage(command, request);
1220 msg.sendToTarget();
1221
1222 // Wait for the request to complete
1223 synchronized (request) {
1224 while (request.result == null) {
1225 try {
1226 request.wait();
1227 } catch (InterruptedException e) {
1228 // Do nothing, go back and wait until the request is complete
1229 }
1230 }
1231 }
1232 return request.result;
1233 }
1234
1235 /**
1236 * Asynchronous ("fire and forget") version of sendRequest():
1237 * Posts the specified command to be executed on the main thread, and
1238 * returns immediately.
1239 * @see #sendRequest
1240 */
1241 private void sendRequestAsync(int command) {
1242 mMainThreadHandler.sendEmptyMessage(command);
1243 }
1244
1245 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001246 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001247 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001248 */
1249 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001250 sendRequestAsync(command, argument, null, null);
1251 }
1252
1253 /**
1254 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1255 * @see {@link #sendRequest(int,Object)}
1256 */
1257 private void sendRequestAsync(
1258 int command, Object argument, Phone phone, WorkSource workSource) {
1259 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001260 Message msg = mMainThreadHandler.obtainMessage(command, request);
1261 msg.sendToTarget();
1262 }
1263
1264 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001265 * Initialize the singleton PhoneInterfaceManager instance.
1266 * This is only done once, at startup, from PhoneApp.onCreate().
1267 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001268 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001269 synchronized (PhoneInterfaceManager.class) {
1270 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001271 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001272 } else {
1273 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1274 }
1275 return sInstance;
1276 }
1277 }
1278
1279 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001280 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001283 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1285 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001286 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001287 mTelephonySharedPreferences =
1288 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001289 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001290 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001291
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001292 publish();
1293 }
1294
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001295 private Phone getDefaultPhone() {
1296 Phone thePhone = getPhone(getDefaultSubscription());
1297 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1298 }
1299
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300 private void publish() {
1301 if (DBG) log("publish: " + this);
1302
1303 ServiceManager.addService("phone", this);
1304 }
1305
Stuart Scott584921c2015-01-15 17:10:34 -08001306 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu73b078d2019-02-28 12:03:40 -08001307 if (request.phone != null) {
1308 return request.phone;
1309 } else {
1310 return getPhoneFromSubId(request.subId);
1311 }
1312 }
1313
1314 private Phone getPhoneFromSubId(int subId) {
1315 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1316 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001317 }
1318
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001319 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1320 Phone phone = getPhoneFromRequest(request);
1321 return phone == null ? null :
1322 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1323 }
1324
Wink Saville36469e72014-06-11 15:17:00 -07001325 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001326 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001327 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329
1330 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001331 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001332 }
1333
Wink Savilleb564aae2014-10-23 10:18:09 -07001334 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335 if (DBG) log("dial: " + number);
1336 // No permission check needed here: This is just a wrapper around the
1337 // ACTION_DIAL intent, which is available to any app since it puts up
1338 // the UI before it does anything.
1339
Malcolm Chend965c8b2018-02-28 15:00:40 -08001340 final long identity = Binder.clearCallingIdentity();
1341 try {
1342 String url = createTelUrl(number);
1343 if (url == null) {
1344 return;
1345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001346
Malcolm Chend965c8b2018-02-28 15:00:40 -08001347 // PENDING: should we just silently fail if phone is offhook or ringing?
1348 PhoneConstants.State state = mCM.getState(subId);
1349 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1350 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1351 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1352 mApp.startActivity(intent);
1353 }
1354 } finally {
1355 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001356 }
1357 }
1358
1359 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001360 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001361 }
1362
Wink Savilleb564aae2014-10-23 10:18:09 -07001363 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364 if (DBG) log("call: " + number);
1365
1366 // This is just a wrapper around the ACTION_CALL intent, but we still
1367 // need to do a permission check since we're calling startActivity()
1368 // from the context of the phone app.
1369 enforceCallPermission();
1370
1371 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1372 != AppOpsManager.MODE_ALLOWED) {
1373 return;
1374 }
1375
Malcolm Chend965c8b2018-02-28 15:00:40 -08001376 final long identity = Binder.clearCallingIdentity();
1377 try {
1378 String url = createTelUrl(number);
1379 if (url == null) {
1380 return;
1381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382
Malcolm Chend965c8b2018-02-28 15:00:40 -08001383 boolean isValid = false;
1384 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1385 if (slist != null) {
1386 for (SubscriptionInfo subInfoRecord : slist) {
1387 if (subInfoRecord.getSubscriptionId() == subId) {
1388 isValid = true;
1389 break;
1390 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001391 }
Wink Saville08874612014-08-31 19:19:58 -07001392 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001393 if (!isValid) {
1394 return;
1395 }
Wink Saville08874612014-08-31 19:19:58 -07001396
Malcolm Chend965c8b2018-02-28 15:00:40 -08001397 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1398 intent.putExtra(SUBSCRIPTION_KEY, subId);
1399 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1400 mApp.startActivity(intent);
1401 } finally {
1402 Binder.restoreCallingIdentity(identity);
1403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 }
1405
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001407 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001408 }
1409
Wink Savilleb564aae2014-10-23 10:18:09 -07001410 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001411 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001412 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1413 }
1414
1415 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001416 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001417 }
1418
Wink Savilleb564aae2014-10-23 10:18:09 -07001419 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001420 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001421 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1422 }
1423
1424 /** {@hide} */
1425 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001426 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001427 }
1428
Wink Savilleb564aae2014-10-23 10:18:09 -07001429 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001430 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001431
1432 final long identity = Binder.clearCallingIdentity();
1433 try {
1434 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1435 checkSimPin.start();
1436 return checkSimPin.unlockSim(null, pin);
1437 } finally {
1438 Binder.restoreCallingIdentity(identity);
1439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440 }
1441
Wink Saville9de0f752013-10-22 19:04:03 -07001442 /** {@hide} */
1443 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001444 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001445 }
1446
Wink Savilleb564aae2014-10-23 10:18:09 -07001447 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001449
1450 final long identity = Binder.clearCallingIdentity();
1451 try {
1452 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1453 checkSimPuk.start();
1454 return checkSimPuk.unlockSim(puk, pin);
1455 } finally {
1456 Binder.restoreCallingIdentity(identity);
1457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458 }
1459
1460 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001461 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 * a synchronous one.
1463 */
1464 private static class UnlockSim extends Thread {
1465
1466 private final IccCard mSimCard;
1467
1468 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001469 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1470 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471
1472 // For replies from SimCard interface
1473 private Handler mHandler;
1474
1475 // For async handler to identify request type
1476 private static final int SUPPLY_PIN_COMPLETE = 100;
1477
1478 public UnlockSim(IccCard simCard) {
1479 mSimCard = simCard;
1480 }
1481
1482 @Override
1483 public void run() {
1484 Looper.prepare();
1485 synchronized (UnlockSim.this) {
1486 mHandler = new Handler() {
1487 @Override
1488 public void handleMessage(Message msg) {
1489 AsyncResult ar = (AsyncResult) msg.obj;
1490 switch (msg.what) {
1491 case SUPPLY_PIN_COMPLETE:
1492 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1493 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001494 mRetryCount = msg.arg1;
1495 if (ar.exception != null) {
1496 if (ar.exception instanceof CommandException &&
1497 ((CommandException)(ar.exception)).getCommandError()
1498 == CommandException.Error.PASSWORD_INCORRECT) {
1499 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1500 } else {
1501 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1502 }
1503 } else {
1504 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506 mDone = true;
1507 UnlockSim.this.notifyAll();
1508 }
1509 break;
1510 }
1511 }
1512 };
1513 UnlockSim.this.notifyAll();
1514 }
1515 Looper.loop();
1516 }
1517
1518 /*
1519 * Use PIN or PUK to unlock SIM card
1520 *
1521 * If PUK is null, unlock SIM card with PIN
1522 *
1523 * If PUK is not null, unlock SIM card with PUK and set PIN code
1524 */
Wink Saville9de0f752013-10-22 19:04:03 -07001525 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526
1527 while (mHandler == null) {
1528 try {
1529 wait();
1530 } catch (InterruptedException e) {
1531 Thread.currentThread().interrupt();
1532 }
1533 }
1534 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1535
1536 if (puk == null) {
1537 mSimCard.supplyPin(pin, callback);
1538 } else {
1539 mSimCard.supplyPuk(puk, pin, callback);
1540 }
1541
1542 while (!mDone) {
1543 try {
1544 Log.d(LOG_TAG, "wait for done");
1545 wait();
1546 } catch (InterruptedException e) {
1547 // Restore the interrupted status
1548 Thread.currentThread().interrupt();
1549 }
1550 }
1551 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001552 int[] resultArray = new int[2];
1553 resultArray[0] = mResult;
1554 resultArray[1] = mRetryCount;
1555 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 }
1557 }
1558
1559 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001560 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001561
1562 }
1563
Wink Savilleb564aae2014-10-23 10:18:09 -07001564 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 // No permission check needed here: this call is harmless, and it's
1566 // needed for the ServiceState.requestStateUpdate() call (which is
1567 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001568 final long identity = Binder.clearCallingIdentity();
1569 try {
1570 final Phone phone = getPhone(subId);
1571 if (phone != null) {
1572 phone.updateServiceLocation();
1573 }
1574 } finally {
1575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 }
1578
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001579 @Override
1580 public boolean isRadioOn(String callingPackage) {
1581 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001582 }
1583
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001584 @Override
1585 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001587 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001588 return false;
1589 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001590
1591 final long identity = Binder.clearCallingIdentity();
1592 try {
1593 return isRadioOnForSubscriber(subId);
1594 } finally {
1595 Binder.restoreCallingIdentity(identity);
1596 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001597 }
1598
1599 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001600 final long identity = Binder.clearCallingIdentity();
1601 try {
1602 final Phone phone = getPhone(subId);
1603 if (phone != null) {
1604 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1605 } else {
1606 return false;
1607 }
1608 } finally {
1609 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001611 }
1612
1613 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001614 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 }
Wink Saville36469e72014-06-11 15:17:00 -07001616
Wink Savilleb564aae2014-10-23 10:18:09 -07001617 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001619
1620 final long identity = Binder.clearCallingIdentity();
1621 try {
1622 final Phone phone = getPhone(subId);
1623 if (phone != null) {
1624 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1625 }
1626 } finally {
1627 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001628 }
Wink Saville36469e72014-06-11 15:17:00 -07001629 }
1630
1631 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001632 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001633 }
1634
Wink Savilleb564aae2014-10-23 10:18:09 -07001635 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001636 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001637
1638 final long identity = Binder.clearCallingIdentity();
1639 try {
1640 final Phone phone = getPhone(subId);
1641 if (phone == null) {
1642 return false;
1643 }
1644 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1645 toggleRadioOnOffForSubscriber(subId);
1646 }
1647 return true;
1648 } finally {
1649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 }
Wink Saville36469e72014-06-11 15:17:00 -07001652
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001653 public boolean needMobileRadioShutdown() {
1654 /*
1655 * If any of the Radios are available, it will need to be
1656 * shutdown. So return true if any Radio is available.
1657 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001658 final long identity = Binder.clearCallingIdentity();
1659 try {
1660 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1661 Phone phone = PhoneFactory.getPhone(i);
1662 if (phone != null && phone.isRadioAvailable()) return true;
1663 }
1664 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1665 return false;
1666 } finally {
1667 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001668 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001669 }
1670
Malcolm Chend965c8b2018-02-28 15:00:40 -08001671 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001672 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001673 enforceModifyPermission();
1674
1675 final long identity = Binder.clearCallingIdentity();
1676 try {
1677 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1678 logv("Shutting down Phone " + i);
1679 shutdownRadioUsingPhoneId(i);
1680 }
1681 } finally {
1682 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001683 }
1684 }
1685
1686 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001687 Phone phone = PhoneFactory.getPhone(phoneId);
1688 if (phone != null && phone.isRadioAvailable()) {
1689 phone.shutdownRadio();
1690 }
1691 }
1692
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001694 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001695
1696 final long identity = Binder.clearCallingIdentity();
1697 try {
1698 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1699 if (defaultPhone != null) {
1700 defaultPhone.setRadioPower(turnOn);
1701 return true;
1702 } else {
1703 loge("There's no default phone.");
1704 return false;
1705 }
1706 } finally {
1707 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001708 }
Wink Saville36469e72014-06-11 15:17:00 -07001709 }
1710
Wink Savilleb564aae2014-10-23 10:18:09 -07001711 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
1718 phone.setRadioPower(turnOn);
1719 return true;
1720 } else {
1721 return false;
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
Wink Saville36469e72014-06-11 15:17:00 -07001728 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001729 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 public boolean enableDataConnectivity() {
1731 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001732
1733 final long identity = Binder.clearCallingIdentity();
1734 try {
1735 int subId = mSubscriptionController.getDefaultDataSubId();
1736 final Phone phone = getPhone(subId);
1737 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001738 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001739 return true;
1740 } else {
1741 return false;
1742 }
1743 } finally {
1744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 }
1747
Wink Saville36469e72014-06-11 15:17:00 -07001748 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001749 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 public boolean disableDataConnectivity() {
1751 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001752
1753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 int subId = mSubscriptionController.getDefaultDataSubId();
1756 final Phone phone = getPhone(subId);
1757 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001758 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001759 return true;
1760 } else {
1761 return false;
1762 }
1763 } finally {
1764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 }
1767
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001769 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001770 final long identity = Binder.clearCallingIdentity();
1771 try {
1772 final Phone phone = getPhone(subId);
1773 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001774 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001775 } else {
1776 return false;
1777 }
1778 } finally {
1779 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001780 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 }
1782
1783 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001784 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001785 }
1786
pkanwarae03a6b2016-11-06 20:37:09 -08001787 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001788 enforceCallPermission();
1789
1790 final long identity = Binder.clearCallingIdentity();
1791 try {
1792 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1793 return;
1794 }
1795 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1796 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1797 } finally {
1798 Binder.restoreCallingIdentity(identity);
1799 }
pkanwar32d516d2016-10-14 19:37:38 -07001800 };
1801
Wink Savilleb564aae2014-10-23 10:18:09 -07001802 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001804
1805 final long identity = Binder.clearCallingIdentity();
1806 try {
1807 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1808 return false;
1809 }
1810 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1811 } finally {
1812 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 }
1815
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001817 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001818 }
1819
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001820 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001821 final long identity = Binder.clearCallingIdentity();
1822 try {
1823 Phone phone = PhoneFactory.getPhone(slotIndex);
1824 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1825 PhoneConstantConversions.convertCallState(phone.getState());
1826 } finally {
1827 Binder.restoreCallingIdentity(identity);
1828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 }
1830
Sanket Padawe356d7632015-06-22 14:03:32 -07001831 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001833 final long identity = Binder.clearCallingIdentity();
1834 try {
1835 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1836 if (phone != null) {
1837 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1838 } else {
1839 return PhoneConstantConversions.convertDataState(
1840 PhoneConstants.DataState.DISCONNECTED);
1841 }
1842 } finally {
1843 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001844 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 }
1846
Sanket Padawe356d7632015-06-22 14:03:32 -07001847 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001849 final long identity = Binder.clearCallingIdentity();
1850 try {
1851 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1852 if (phone != null) {
1853 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1854 } else {
1855 return TelephonyManager.DATA_ACTIVITY_NONE;
1856 }
1857 } finally {
1858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 }
1861
1862 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001863 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001864 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001865 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001866
1867 LocationAccessPolicy.LocationPermissionResult locationResult =
1868 LocationAccessPolicy.checkLocationPermission(mApp,
1869 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1870 .setCallingPackage(callingPackage)
1871 .setCallingPid(Binder.getCallingPid())
1872 .setCallingUid(Binder.getCallingUid())
1873 .setMethod("getCellLocation")
1874 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1875 .build());
1876 switch (locationResult) {
1877 case DENIED_HARD:
1878 throw new SecurityException("Not allowed to access cell location");
1879 case DENIED_SOFT:
1880 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 }
1882
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001883 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001884 final long identity = Binder.clearCallingIdentity();
1885 try {
1886 if (DBG_LOC) log("getCellLocation: is active user");
1887 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001888 int subId = mSubscriptionController.getDefaultDataSubId();
1889 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1890 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001891 return data;
1892 } finally {
1893 Binder.restoreCallingIdentity(identity);
1894 }
Svetoslav64fad262015-04-14 14:35:21 -07001895 }
1896
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001898 public String getNetworkCountryIsoForPhone(int phoneId) {
1899 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1900 // registered cell info, so return a NULL country instead.
1901 final long identity = Binder.clearCallingIdentity();
1902 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001903 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1904 // Get default phone in this case.
1905 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1906 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001907 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001908 // Todo: fix this when we can get the actual cellular network info when the device
1909 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001910 if (TelephonyManager.NETWORK_TYPE_IWLAN
1911 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1912 return "";
1913 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001914 Phone phone = PhoneFactory.getPhone(phoneId);
1915 if (phone != null) {
1916 ServiceStateTracker sst = phone.getServiceStateTracker();
1917 if (sst != null) {
1918 LocaleTracker lt = sst.getLocaleTracker();
1919 if (lt != null) {
1920 return lt.getCurrentCountry();
1921 }
1922 }
1923 }
1924 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001925 } finally {
1926 Binder.restoreCallingIdentity(identity);
1927 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001928 }
1929
1930 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001932 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001933 }
1934
Sanket Padawe356d7632015-06-22 14:03:32 -07001935 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001936 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 mApp.enforceCallingOrSelfPermission(
1938 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001939
1940 final long identity = Binder.clearCallingIdentity();
1941 try {
1942 final Phone phone = getPhone(subId);
1943 if (phone != null) {
1944 phone.enableLocationUpdates();
1945 }
1946 } finally {
1947 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949 }
1950
1951 @Override
1952 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001953 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001954 }
1955
Sanket Padawe356d7632015-06-22 14:03:32 -07001956 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001957 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958 mApp.enforceCallingOrSelfPermission(
1959 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001960
1961 final long identity = Binder.clearCallingIdentity();
1962 try {
1963 final Phone phone = getPhone(subId);
1964 if (phone != null) {
1965 phone.disableLocationUpdates();
1966 }
1967 } finally {
1968 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 }
1971
Nathan Harold31d7ff32018-10-15 20:20:30 -07001972 /**
1973 * Returns the target SDK version number for a given package name.
1974 *
1975 * @return target SDK if the package is found or INT_MAX.
1976 */
1977 private int getTargetSdk(String packageName) {
1978 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001979 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1980 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001981 if (ai != null) return ai.targetSdkVersion;
1982 } catch (PackageManager.NameNotFoundException unexpected) {
1983 }
1984 return Integer.MAX_VALUE;
1985 }
1986
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 @Override
1988 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001989 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1990 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001991 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1992 throw new SecurityException(
1993 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1994 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001995
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1997 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1998 return null;
1999 }
Svetoslav64fad262015-04-14 14:35:21 -07002000
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002001 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002
Nathan Haroldf180aac2018-06-01 18:43:55 -07002003 List<CellInfo> info = getAllCellInfo(callingPackage);
2004 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005
Nathan Haroldf180aac2018-06-01 18:43:55 -07002006 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2007 for (CellInfo ci : info) {
2008 if (ci instanceof CellInfoGsm) {
2009 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2010 } else if (ci instanceof CellInfoWcdma) {
2011 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002014 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 }
2016
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002017 private List<CellInfo> getCachedCellInfo() {
2018 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2019 for (Phone phone : PhoneFactory.getPhones()) {
2020 List<CellInfo> info = phone.getAllCellInfo();
2021 if (info != null) cellInfos.addAll(info);
2022 }
2023 return cellInfos;
2024 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002025
2026 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002027 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002028 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002029 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002030
2031 LocationAccessPolicy.LocationPermissionResult locationResult =
2032 LocationAccessPolicy.checkLocationPermission(mApp,
2033 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2034 .setCallingPackage(callingPackage)
2035 .setCallingPid(Binder.getCallingPid())
2036 .setCallingUid(Binder.getCallingUid())
2037 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002038 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002039 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2040 .build());
2041 switch (locationResult) {
2042 case DENIED_HARD:
2043 throw new SecurityException("Not allowed to access cell info");
2044 case DENIED_SOFT:
2045 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 }
2047
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002048 final int targetSdk = getTargetSdk(callingPackage);
2049 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2050 return getCachedCellInfo();
2051 }
2052
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002053 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002054 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002055 final long identity = Binder.clearCallingIdentity();
2056 try {
2057 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2058 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002059 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002060 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002061 if (info != null) cellInfos.addAll(info);
2062 }
2063 return cellInfos;
2064 } finally {
2065 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 }
2067 }
2068
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002069 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002070 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2071 requestCellInfoUpdateInternal(
2072 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2073 }
2074
2075 @Override
2076 public void requestCellInfoUpdateWithWorkSource(
2077 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2078 enforceModifyPermission();
2079 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2080 }
2081
2082 private void requestCellInfoUpdateInternal(
2083 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002084 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002085 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002086
2087 LocationAccessPolicy.LocationPermissionResult locationResult =
2088 LocationAccessPolicy.checkLocationPermission(mApp,
2089 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2090 .setCallingPackage(callingPackage)
2091 .setCallingPid(Binder.getCallingPid())
2092 .setCallingUid(Binder.getCallingUid())
2093 .setMethod("requestCellInfoUpdate")
2094 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2095 .build());
2096 switch (locationResult) {
2097 case DENIED_HARD:
2098 throw new SecurityException("Not allowed to access cell info");
2099 case DENIED_SOFT:
2100 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002101 }
2102
2103 final Phone phone = getPhone(subId);
2104 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2105
2106 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2107 }
2108
2109 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002111 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002112 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002113
2114 final long identity = Binder.clearCallingIdentity();
2115 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002116 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002117 } finally {
2118 Binder.restoreCallingIdentity(identity);
2119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 }
2121
Shishir Agrawala9f32182016-04-12 12:00:16 -07002122 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002123 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002124 Phone phone = PhoneFactory.getPhone(slotIndex);
2125 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002126 return null;
2127 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002128 int subId = phone.getSubId();
2129 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2130 mApp, subId, callingPackage, "getImeiForSlot")) {
2131 return null;
2132 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002133
2134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 return phone.getImei();
2137 } finally {
2138 Binder.restoreCallingIdentity(identity);
2139 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002140 }
2141
2142 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002143 public String getTypeAllocationCodeForSlot(int slotIndex) {
2144 Phone phone = PhoneFactory.getPhone(slotIndex);
2145 String tac = null;
2146 if (phone != null) {
2147 String imei = phone.getImei();
2148 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2149 }
2150 return tac;
2151 }
2152
2153 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002154 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002155 Phone phone = PhoneFactory.getPhone(slotIndex);
2156 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002157 return null;
2158 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002159
Jeff Davidson913390f2018-02-23 17:11:49 -08002160 int subId = phone.getSubId();
2161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2162 mApp, subId, callingPackage, "getMeidForSlot")) {
2163 return null;
2164 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002165
2166 final long identity = Binder.clearCallingIdentity();
2167 try {
2168 return phone.getMeid();
2169 } finally {
2170 Binder.restoreCallingIdentity(identity);
2171 }
Jack Yu2af8d712017-03-15 17:14:14 -07002172 }
2173
2174 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002175 public String getManufacturerCodeForSlot(int slotIndex) {
2176 Phone phone = PhoneFactory.getPhone(slotIndex);
2177 String manufacturerCode = null;
2178 if (phone != null) {
2179 String meid = phone.getMeid();
2180 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2181 }
2182 return manufacturerCode;
2183 }
2184
2185 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002186 public String getDeviceSoftwareVersionForSlot(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, "getDeviceSoftwareVersionForSlot")) {
2194 return null;
2195 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002196
2197 final long identity = Binder.clearCallingIdentity();
2198 try {
2199 return phone.getDeviceSvn();
2200 } finally {
2201 Binder.restoreCallingIdentity(identity);
2202 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002203 }
2204
fionaxu43304da2017-11-27 22:51:16 -08002205 @Override
2206 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002207 final long identity = Binder.clearCallingIdentity();
2208 try {
2209 final Phone phone = getPhone(subId);
2210 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2211 } finally {
2212 Binder.restoreCallingIdentity(identity);
2213 }
fionaxu43304da2017-11-27 22:51:16 -08002214 }
2215
2216 @Override
2217 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002218 final long identity = Binder.clearCallingIdentity();
2219 try {
2220 final Phone phone = getPhone(subId);
2221 return phone == null ? null : phone.getCarrierName();
2222 } finally {
2223 Binder.restoreCallingIdentity(identity);
2224 }
fionaxu43304da2017-11-27 22:51:16 -08002225 }
2226
calvinpaneed9ae82018-11-01 19:43:06 +08002227 @Override
chen xua31f22b2019-03-06 15:28:50 -08002228 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002229 final long identity = Binder.clearCallingIdentity();
2230 try {
2231 final Phone phone = getPhone(subId);
2232 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002233 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002234 } finally {
2235 Binder.restoreCallingIdentity(identity);
2236 }
2237 }
2238
2239 @Override
chen xua31f22b2019-03-06 15:28:50 -08002240 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002241 final long identity = Binder.clearCallingIdentity();
2242 try {
2243 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002244 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002245 } finally {
2246 Binder.restoreCallingIdentity(identity);
2247 }
2248 }
2249
chen xu02581692018-11-11 19:03:44 -08002250 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002251 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2252 if (!isSubscriptionMccMnc) {
2253 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2254 }
chen xu02581692018-11-11 19:03:44 -08002255 final Phone phone = PhoneFactory.getPhone(slotIndex);
2256 if (phone == null) {
2257 return TelephonyManager.UNKNOWN_CARRIER_ID;
2258 }
2259 final long identity = Binder.clearCallingIdentity();
2260 try {
2261 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
2264 }
2265 }
2266
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 //
2268 // Internal helper methods.
2269 //
2270
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002271 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2273 *
2274 * @throws SecurityException if the caller does not have the required permission
2275 */
2276 private void enforceModifyPermission() {
2277 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2278 }
2279
2280 /**
2281 * Make sure the caller has the CALL_PHONE permission.
2282 *
2283 * @throws SecurityException if the caller does not have the required permission
2284 */
2285 private void enforceCallPermission() {
2286 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2287 }
2288
Stuart Scott8eef64f2015-04-08 15:13:54 -07002289 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002290 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002291 "ConnectivityService");
2292 }
2293
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 private String createTelUrl(String number) {
2295 if (TextUtils.isEmpty(number)) {
2296 return null;
2297 }
2298
Jake Hambye994d462014-02-03 13:10:13 -08002299 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 }
2301
Ihab Awadf9e92732013-12-05 18:02:52 -08002302 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2304 }
2305
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002306 private static void logv(String msg) {
2307 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2308 }
2309
Ihab Awadf9e92732013-12-05 18:02:52 -08002310 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2312 }
2313
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002314 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002316 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002317 }
2318
Sanket Padawe356d7632015-06-22 14:03:32 -07002319 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002320 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002321 final long identity = Binder.clearCallingIdentity();
2322 try {
2323 final Phone phone = PhoneFactory.getPhone(slotIndex);
2324 if (phone == null) {
2325 return PhoneConstants.PHONE_TYPE_NONE;
2326 } else {
2327 return phone.getPhoneType();
2328 }
2329 } finally {
2330 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 }
2333
2334 /**
2335 * Returns the CDMA ERI icon index to display
2336 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002337 @Override
2338 public int getCdmaEriIconIndex(String callingPackage) {
2339 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002340 }
2341
Sanket Padawe356d7632015-06-22 14:03:32 -07002342 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002343 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002344 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002345 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002346 return -1;
2347 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002348
2349 final long identity = Binder.clearCallingIdentity();
2350 try {
2351 final Phone phone = getPhone(subId);
2352 if (phone != null) {
2353 return phone.getCdmaEriIconIndex();
2354 } else {
2355 return -1;
2356 }
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
2361
2362 /**
2363 * Returns the CDMA ERI icon mode,
2364 * 0 - ON
2365 * 1 - FLASHING
2366 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002367 @Override
2368 public int getCdmaEriIconMode(String callingPackage) {
2369 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002370 }
2371
Sanket Padawe356d7632015-06-22 14:03:32 -07002372 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002373 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002375 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002376 return -1;
2377 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002378
2379 final long identity = Binder.clearCallingIdentity();
2380 try {
2381 final Phone phone = getPhone(subId);
2382 if (phone != null) {
2383 return phone.getCdmaEriIconMode();
2384 } else {
2385 return -1;
2386 }
2387 } finally {
2388 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 }
2391
2392 /**
2393 * Returns the CDMA ERI text,
2394 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002395 @Override
2396 public String getCdmaEriText(String callingPackage) {
2397 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002398 }
2399
Sanket Padawe356d7632015-06-22 14:03:32 -07002400 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002401 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002402 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002403 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002404 return null;
2405 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002406
2407 final long identity = Binder.clearCallingIdentity();
2408 try {
2409 final Phone phone = getPhone(subId);
2410 if (phone != null) {
2411 return phone.getCdmaEriText();
2412 } else {
2413 return null;
2414 }
2415 } finally {
2416 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 }
2419
2420 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002421 * Returns the CDMA MDN.
2422 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002423 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002424 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2426 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002427
2428 final long identity = Binder.clearCallingIdentity();
2429 try {
2430 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002431 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002432 return phone.getLine1Number();
2433 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002434 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002435 return null;
2436 }
2437 } finally {
2438 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002439 }
2440 }
2441
2442 /**
2443 * Returns the CDMA MIN.
2444 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002445 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002446 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2448 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002449
2450 final long identity = Binder.clearCallingIdentity();
2451 try {
2452 final Phone phone = getPhone(subId);
2453 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2454 return phone.getCdmaMin();
2455 } else {
2456 return null;
2457 }
2458 } finally {
2459 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002460 }
2461 }
2462
Hall Liud892bec2018-11-30 14:51:45 -08002463 @Override
2464 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2465 INumberVerificationCallback callback, String callingPackage) {
2466 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2467 != PERMISSION_GRANTED) {
2468 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2469 }
2470 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2471
2472 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2473 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2474 throw new SecurityException("Calling package must be configured in the device config");
2475 }
2476
2477 if (range == null) {
2478 throw new NullPointerException("Range must be non-null");
2479 }
2480
2481 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002482 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002483
2484 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2485 }
2486
Junda Liuca05d5d2014-08-14 22:36:34 -07002487 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 * Returns true if CDMA provisioning needs to run.
2489 */
2490 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002491 final long identity = Binder.clearCallingIdentity();
2492 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002493 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002494 } finally {
2495 Binder.restoreCallingIdentity(identity);
2496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
2498
2499 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002500 * Sets the voice mail number of a given subId.
2501 */
2502 @Override
2503 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002504 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2509 new Pair<String, String>(alphaTag, number), new Integer(subId));
2510 return success;
2511 } finally {
2512 Binder.restoreCallingIdentity(identity);
2513 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002514 }
2515
Ta-wei Yen87c49842016-05-13 21:19:52 -07002516 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002517 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2518 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002519 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002520 if (!TextUtils.equals(callingPackage, systemDialer)) {
2521 throw new SecurityException("caller must be system dialer");
2522 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002523
2524 final long identity = Binder.clearCallingIdentity();
2525 try {
2526 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2527 if (phoneAccountHandle == null) {
2528 return null;
2529 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002530 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002531 } finally {
2532 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002533 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002534 }
2535
2536 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002537 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002538 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002540 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002541 return null;
2542 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002543
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002544 final long identity = Binder.clearCallingIdentity();
2545 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002546 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002547 } finally {
2548 Binder.restoreCallingIdentity(identity);
2549 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002550 }
2551
2552 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002553 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2554 VisualVoicemailSmsFilterSettings settings) {
2555 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002556
2557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002560 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002561 } finally {
2562 Binder.restoreCallingIdentity(identity);
2563 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002564 }
2565
2566 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002567 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2568 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002573 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002574 } finally {
2575 Binder.restoreCallingIdentity(identity);
2576 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002577 }
2578
2579 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002580 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2581 String callingPackage, int subId) {
2582 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002587 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002588 } finally {
2589 Binder.restoreCallingIdentity(identity);
2590 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002591 }
2592
2593 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002594 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002595 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002596
2597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002600 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002601 } finally {
2602 Binder.restoreCallingIdentity(identity);
2603 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002604 }
2605
2606 @Override
2607 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2608 String number, int port, String text, PendingIntent sentIntent) {
2609 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002610 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002611 enforceSendSmsPermission();
2612 // Make the calls as the phone process.
2613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2616 if (port == 0) {
2617 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2618 sentIntent, null, false);
2619 } else {
2620 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2621 smsManager.sendDataMessageWithSelfPermissions(number, null,
2622 (short) port, data, sentIntent, null);
2623 }
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
2626 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002627 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002628 /**
fionaxu0152e512016-11-14 13:36:14 -08002629 * Sets the voice activation state of a given subId.
2630 */
2631 @Override
2632 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2634 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002635
2636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 final Phone phone = getPhone(subId);
2639 if (phone != null) {
2640 phone.setVoiceActivationState(activationState);
2641 } else {
2642 loge("setVoiceActivationState fails with invalid subId: " + subId);
2643 }
2644 } finally {
2645 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002646 }
2647 }
2648
2649 /**
2650 * Sets the data activation state of a given subId.
2651 */
2652 @Override
2653 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2655 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002656
2657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 final Phone phone = getPhone(subId);
2660 if (phone != null) {
2661 phone.setDataActivationState(activationState);
2662 } else {
2663 loge("setVoiceActivationState fails with invalid subId: " + subId);
2664 }
2665 } finally {
2666 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002667 }
2668 }
2669
2670 /**
2671 * Returns the voice activation state of a given subId.
2672 */
2673 @Override
2674 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002675 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002676
fionaxu0152e512016-11-14 13:36:14 -08002677 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002678 final long identity = Binder.clearCallingIdentity();
2679 try {
2680 if (phone != null) {
2681 return phone.getVoiceActivationState();
2682 } else {
2683 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2684 }
2685 } finally {
2686 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002687 }
2688 }
2689
2690 /**
2691 * Returns the data activation state of a given subId.
2692 */
2693 @Override
2694 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002695 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002696
fionaxu0152e512016-11-14 13:36:14 -08002697 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 if (phone != null) {
2701 return phone.getDataActivationState();
2702 } else {
2703 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2704 }
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002707 }
2708 }
2709
2710 /**
Wink Saville36469e72014-06-11 15:17:00 -07002711 * Returns the unread count of voicemails for a subId
2712 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002714 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2716 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2717 return 0;
2718 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 final Phone phone = getPhone(subId);
2722 if (phone != null) {
2723 return phone.getVoiceMessageCount();
2724 } else {
2725 return 0;
2726 }
2727 } finally {
2728 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 }
2731
2732 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002733 * returns true, if the device is in a state where both voice and data
2734 * are supported simultaneously. This can change based on location or network condition.
2735 */
2736 @Override
2737 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 final Phone phone = getPhone(subId);
2741 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
2744 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002745 }
2746
2747 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002748 * Send the dialer code if called from the current default dialer or the caller has
2749 * carrier privilege.
2750 * @param inputCode The dialer code to send
2751 */
2752 @Override
2753 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002754 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002755 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002756 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2757 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002758 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002759 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2760 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002761 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002765 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002766 } finally {
2767 Binder.restoreCallingIdentity(identity);
2768 }
fionaxu235cc5e2017-03-06 22:25:57 -08002769 }
2770
2771 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002772 * Returns the data network type.
2773 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 *
2775 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2776 */
2777 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002778 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 final Phone phone = getPhone(getDefaultSubscription());
2782 if (phone != null) {
2783 return phone.getServiceState().getDataNetworkType();
2784 } else {
2785 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2786 }
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002789 }
Wink Saville36469e72014-06-11 15:17:00 -07002790 }
2791
Pengquan Meng0c05b502018-09-06 09:59:22 -07002792 @Override
2793 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002794 if (!isActiveSubscription(subId)) {
2795 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2796 }
2797
Pengquan Meng0c05b502018-09-06 09:59:22 -07002798 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2799 }
2800
Brad Ebinger4c460712018-10-01 10:40:55 -07002801 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002802 public boolean isInEmergencySmsMode() {
2803 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2804 final long identity = Binder.clearCallingIdentity();
2805 try {
2806 for (Phone phone : PhoneFactory.getPhones()) {
2807 if (phone.isInEmergencySmsMode()) {
2808 return true;
2809 }
2810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
2813 }
2814 return false;
2815 }
2816
2817 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002818 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2819 throws RemoteException {
2820 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002821 final long token = Binder.clearCallingIdentity();
2822 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002823 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002824 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002825 .addRegistrationCallbackForSubscription(c, subId);
2826 } finally {
2827 Binder.restoreCallingIdentity(token);
2828 }
2829 }
2830
2831 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002832 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2833 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002834 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2835 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2836 }
2837 Binder.withCleanCallingIdentity(() -> {
2838 try {
2839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002840 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002841 .removeRegistrationCallbackForSubscription(c, subId);
2842 } catch (IllegalArgumentException e) {
2843 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2844 + "is inactive, ignoring unregister.");
2845 // If the subscription is no longer active, just return, since the callback
2846 // will already have been removed internally.
2847 }
2848 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002849 }
2850
2851 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002852 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2853 throws RemoteException {
2854 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002855 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2856 final long token = Binder.clearCallingIdentity();
2857 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002858 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002859 .addCapabilitiesCallbackForSubscription(c, subId);
2860 } finally {
2861 Binder.restoreCallingIdentity(token);
2862 }
2863 }
2864
2865 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002866 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2867 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002868
2869 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2870 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2871 }
2872 Binder.withCleanCallingIdentity(() -> {
2873 try {
2874 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002875 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002876 .removeCapabilitiesCallbackForSubscription(c, subId);
2877 } catch (IllegalArgumentException e) {
2878 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2879 + "is inactive, ignoring unregister.");
2880 // If the subscription is no longer active, just return, since the callback
2881 // will already have been removed internally.
2882 }
2883 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002884 }
2885
2886 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002887 public boolean isCapable(int subId, int capability, int regTech) {
2888 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002889 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2890 final long token = Binder.clearCallingIdentity();
2891 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002892 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002893 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2894 } catch (ImsException e) {
2895 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2896 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002897 } catch (IllegalArgumentException e) {
2898 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2899 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002900 } finally {
2901 Binder.restoreCallingIdentity(token);
2902 }
2903 }
2904
2905 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002906 public boolean isAvailable(int subId, int capability, int regTech) {
2907 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002908 final long token = Binder.clearCallingIdentity();
2909 try {
2910 Phone phone = getPhone(subId);
2911 if (phone == null) return false;
2912 return phone.isImsCapabilityAvailable(capability, regTech);
2913 } finally {
2914 Binder.restoreCallingIdentity(token);
2915 }
2916 }
2917
2918 @Override
2919 public boolean isAdvancedCallingSettingEnabled(int subId) {
2920 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2921 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2922 final long token = Binder.clearCallingIdentity();
2923 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002924 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002925 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2926 } finally {
2927 Binder.restoreCallingIdentity(token);
2928 }
2929 }
2930
2931 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002932 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002934 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002935 final long identity = Binder.clearCallingIdentity();
2936 try {
2937 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002938 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002939 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
2942 }
2943 }
2944
2945 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002946 public boolean isVtSettingEnabled(int subId) {
2947 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002951 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002952 getSlotIndexOrException(subId)).isVtEnabledByUser();
2953 } finally {
2954 Binder.restoreCallingIdentity(identity);
2955 }
2956 }
2957
2958 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002959 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002961 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002962 final long identity = Binder.clearCallingIdentity();
2963 try {
2964 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002965 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
2969 }
2970
2971 @Override
2972 public boolean isVoWiFiSettingEnabled(int subId) {
2973 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002977 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002978 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002985 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002987 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002991 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
2995 }
2996
2997 @Override
2998 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2999 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003003 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003004 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
3008 }
3009
3010 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003011 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003013 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003017 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003018 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
3022 }
3023
3024 @Override
3025 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3027 "setVoWiFiNonPersistent");
3028 final long identity = Binder.clearCallingIdentity();
3029 try {
3030 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003031 boolean isRoaming = TelephonyManager.from(
3032 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003033 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003034 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07003035 } finally {
3036 Binder.restoreCallingIdentity(identity);
3037 }
3038 }
3039
3040 @Override
3041 public int getVoWiFiModeSetting(int subId) {
3042 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003046 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003047 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3048 } finally {
3049 Binder.restoreCallingIdentity(identity);
3050 }
3051 }
3052
3053 @Override
3054 public void setVoWiFiModeSetting(int subId, int mode) {
3055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3056 "setVoWiFiModeSetting");
3057 final long identity = Binder.clearCallingIdentity();
3058 try {
3059 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003060 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003061 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
3065 }
3066
3067 @Override
3068 public int getVoWiFiRoamingModeSetting(int subId) {
3069 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003073 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003074 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
3078 }
3079
3080 @Override
3081 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3083 "setVoWiFiRoamingModeSetting");
3084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003087 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003088 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3089 } finally {
3090 Binder.restoreCallingIdentity(identity);
3091 }
3092 }
3093
3094 @Override
3095 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3097 "setRttCapabilityEnabled");
3098 final long identity = Binder.clearCallingIdentity();
3099 try {
3100 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003101 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003102 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
3106 }
3107
3108 @Override
3109 public boolean isTtyOverVolteEnabled(int subId) {
3110 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003114 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003115 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
3118 }
3119 }
3120
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003121 @Override
3122 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3123 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
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 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003128 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
3132 }
3133
3134 @Override
3135 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3136 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3137 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003138 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3139 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3140 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003141 try {
3142 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003143 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003144 .removeProvisioningCallbackForSubscription(callback, subId);
3145 } catch (IllegalArgumentException e) {
3146 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3147 + "is inactive, ignoring unregister.");
3148 // If the subscription is no longer active, just return, since the callback will already
3149 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003150 } finally {
3151 Binder.restoreCallingIdentity(identity);
3152 }
3153 }
3154
3155 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003156 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3157 boolean isProvisioned) {
3158 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3159 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3160 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3161 }
3162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3163 "setProvisioningStatusForCapability");
3164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3167 Phone phone = getPhone(subId);
3168 if (phone == null) {
3169 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3170 + subId);
3171 return;
3172 }
3173 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3174 return;
3175 }
3176
3177 // this capability requires provisioning, route to the correct API.
3178 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3179 switch (capability) {
3180 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3181 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3182 ims.setVolteProvisioned(isProvisioned);
3183 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3184 ims.setWfcProvisioned(isProvisioned);
3185 }
3186 break;
3187 }
3188 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3189 // There is currently no difference in VT provisioning type.
3190 ims.setVtProvisioned(isProvisioned);
3191 break;
3192 }
3193 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3194 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3195 // change the capability of the feature instead if needed.
3196 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3197 == isProvisioned) {
3198 // No change in provisioning.
3199 return;
3200 }
3201 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3202 try {
3203 ims.changeMmTelCapability(capability, tech, isProvisioned);
3204 } catch (ImsException e) {
3205 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3206 + ", Exception" + e.getMessage());
3207 }
3208 break;
3209 }
3210 default: {
3211 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3212 + capability + "', which does not require provisioning.");
3213 }
3214 }
3215
3216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
3219 }
3220
3221 @Override
3222 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3223 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3224 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3225 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3226 }
3227 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3231 Phone phone = getPhone(subId);
3232 if (phone == null) {
3233 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3234 + subId);
3235 // We will fail with "true" as the provisioning status because this is the default
3236 // if we do not require provisioning.
3237 return true;
3238 }
3239
3240 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3241 return true;
3242 }
3243
3244 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3245 switch (capability) {
3246 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3247 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3248 return ims.isVolteProvisionedOnDevice();
3249 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3250 return ims.isWfcProvisionedOnDevice();
3251 }
3252 // This should never happen, since we are checking tech above to make sure it
3253 // is either LTE or IWLAN.
3254 throw new IllegalArgumentException("Invalid radio technology for voice "
3255 + "capability.");
3256 }
3257 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3258 // There is currently no difference in VT provisioning type.
3259 return ims.isVtProvisionedOnDevice();
3260 }
3261 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3262 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3263 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3264 }
3265 default: {
3266 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3267 + capability + "', which does not require provisioning.");
3268 }
3269 }
3270
3271 } finally {
3272 Binder.restoreCallingIdentity(identity);
3273 }
3274 }
3275
3276 @Override
3277 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3278 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3279 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3280 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3281 }
3282 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3283 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3284 return (provisionedBits & capability) > 0;
3285 }
3286
3287 @Override
3288 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3289 boolean isProvisioned) {
3290 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3291 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3292 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3293 }
3294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3295 "setProvisioningStatusForCapability");
3296 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3297 // If the current provisioning status for capability already matches isProvisioned,
3298 // do nothing.
3299 if (((provisionedBits & capability) > 0) == isProvisioned) {
3300 return;
3301 }
3302 if (isProvisioned) {
3303 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3304 } else {
3305 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3306 }
3307 }
3308
3309 /**
3310 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3311 * technology. The bitfield should mirror the bitfield defined by
3312 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3313 */
3314 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3315 String key = getMmTelProvisioningKey(subId, tech);
3316 // Default is no capabilities are provisioned.
3317 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3318 }
3319
3320 /**
3321 * Sets the MmTel capability provisioning bitfield (defined by
3322 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3323 * technology specified.
3324 *
3325 * Note: This is a synchronous command and should not be called on UI thread.
3326 */
3327 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3328 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3329 String key = getMmTelProvisioningKey(subId, tech);
3330 editor.putInt(key, newField);
3331 editor.commit();
3332 }
3333
3334 private static String getMmTelProvisioningKey(int subId, int tech) {
3335 // resulting key is provision_ims_mmtel_{subId}_{tech}
3336 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3337 }
3338
3339 /**
3340 * Query CarrierConfig to see if the specified capability requires provisioning for the
3341 * carrier associated with the subscription id.
3342 */
3343 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3344 int capability) {
3345 CarrierConfigManager configManager = new CarrierConfigManager(context);
3346 PersistableBundle c = configManager.getConfigForSubId(subId);
3347 boolean requireUtProvisioning = c.getBoolean(
3348 // By default, this config is true (even if there is no SIM). We also check to make
3349 // sure the subscription needs provisioning here, so we do not need to check for
3350 // the no-SIM case, where we would normally shortcut this to false.
3351 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3352 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3353 false);
3354 boolean requireVoiceVtProvisioning = c.getBoolean(
3355 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3356
3357 // First check to make sure that the capability requires provisioning.
3358 switch (capability) {
3359 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3360 // intentional fallthrough
3361 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3362 if (requireVoiceVtProvisioning) {
3363 // Voice and Video requires provisioning
3364 return true;
3365 }
3366 break;
3367 }
3368 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3369 if (requireUtProvisioning) {
3370 // UT requires provisioning
3371 return true;
3372 }
3373 break;
3374 }
3375 }
3376 return false;
3377 }
3378
3379 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003380 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003381 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3382 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3383 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003384 enforceReadPrivilegedPermission("getImsProvisioningInt");
3385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003388 int slotId = getSlotIndex(subId);
3389 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3390 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3391 + subId + "' for key:" + key);
3392 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3393 }
3394 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003395 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003396 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3397 + subId + "' for key:" + key);
3398 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
3402 }
3403
3404 @Override
3405 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003406 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3407 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3408 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003409 enforceReadPrivilegedPermission("getImsProvisioningString");
3410 final long identity = Binder.clearCallingIdentity();
3411 try {
3412 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003413 int slotId = getSlotIndex(subId);
3414 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3415 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3416 + subId + "' for key:" + key);
3417 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3418 }
3419 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003420 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003421 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3422 + subId + "' for key:" + key);
3423 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
3427 }
3428
3429 @Override
3430 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003431 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3432 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3433 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3435 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003436 final long identity = Binder.clearCallingIdentity();
3437 try {
3438 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003439 int slotId = getSlotIndex(subId);
3440 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3441 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3442 + subId + "' for key:" + key);
3443 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3444 }
3445 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003446 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003447 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3448 + "' for key:" + key);
3449 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003450 } finally {
3451 Binder.restoreCallingIdentity(identity);
3452 }
3453 }
3454
3455 @Override
3456 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003457 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3458 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3459 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3461 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003462 final long identity = Binder.clearCallingIdentity();
3463 try {
3464 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003465 int slotId = getSlotIndex(subId);
3466 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3467 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3468 + subId + "' for key:" + key);
3469 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3470 }
3471 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003472 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003473 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3474 + "' for key:" + key);
3475 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003476 } finally {
3477 Binder.restoreCallingIdentity(identity);
3478 }
3479 }
3480
Brad Ebinger4c460712018-10-01 10:40:55 -07003481 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3482 int slotId = SubscriptionManager.getSlotIndex(subId);
3483 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003484 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003485 }
3486 return slotId;
3487 }
3488
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003489 private int getSlotIndex(int subId) {
3490 int slotId = SubscriptionManager.getSlotIndex(subId);
3491 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3492 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3493 }
3494 return slotId;
3495 }
3496
Wink Saville36469e72014-06-11 15:17:00 -07003497 /**
3498 * Returns the network type for a subId
3499 */
3500 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003501 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003503 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003504 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3505 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003506
Malcolm Chend965c8b2018-02-28 15:00:40 -08003507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 final Phone phone = getPhone(subId);
3510 if (phone != null) {
3511 return phone.getServiceState().getDataNetworkType();
3512 } else {
3513 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3514 }
3515 } finally {
3516 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003518 }
3519
3520 /**
3521 * Returns the data network type
3522 */
3523 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003524 public int getDataNetworkType(String callingPackage) {
3525 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003526 }
3527
3528 /**
3529 * Returns the data network type for a subId
3530 */
3531 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003532 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003533 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003534 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003535 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3536 }
3537
Malcolm Chend965c8b2018-02-28 15:00:40 -08003538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 final Phone phone = getPhone(subId);
3541 if (phone != null) {
3542 return phone.getServiceState().getDataNetworkType();
3543 } else {
3544 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3545 }
3546 } finally {
3547 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003549 }
3550
3551 /**
Wink Saville36469e72014-06-11 15:17:00 -07003552 * Returns the Voice network type for a subId
3553 */
3554 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003555 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003557 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003558 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3559 }
3560
Malcolm Chend965c8b2018-02-28 15:00:40 -08003561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 final Phone phone = getPhone(subId);
3564 if (phone != null) {
3565 return phone.getServiceState().getVoiceNetworkType();
3566 } else {
3567 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3568 }
3569 } finally {
3570 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003572 }
3573
3574 /**
3575 * @return true if a ICC card is present
3576 */
3577 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003578 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003579 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3580 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003581 }
3582
3583 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003584 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003585 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003586 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003587 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 final Phone phone = PhoneFactory.getPhone(slotIndex);
3591 if (phone != null) {
3592 return phone.getIccCard().hasIccCard();
3593 } else {
3594 return false;
3595 }
3596 } finally {
3597 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003598 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003599 }
3600
3601 /**
3602 * Return if the current radio is LTE on CDMA. This
3603 * is a tri-state return value as for a period of time
3604 * the mode may be unknown.
3605 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003606 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003607 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003608 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003609 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003610 @Override
3611 public int getLteOnCdmaMode(String callingPackage) {
3612 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003613 }
3614
Sanket Padawe356d7632015-06-22 14:03:32 -07003615 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003616 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003618 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003619 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3620 }
3621
Malcolm Chend965c8b2018-02-28 15:00:40 -08003622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 final Phone phone = getPhone(subId);
3625 if (phone == null) {
3626 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3627 } else {
3628 return phone.getLteOnCdmaMode();
3629 }
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003632 }
Wink Saville36469e72014-06-11 15:17:00 -07003633 }
3634
Wink Saville36469e72014-06-11 15:17:00 -07003635 /**
3636 * {@hide}
3637 * Returns Default subId, 0 in the case of single standby.
3638 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003639 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003640 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003641 }
3642
Shishir Agrawala9f32182016-04-12 12:00:16 -07003643 private int getSlotForDefaultSubscription() {
3644 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3645 }
3646
Wink Savilleb564aae2014-10-23 10:18:09 -07003647 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003648 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003649 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003650
Pengquan Meng466e2482018-09-21 15:54:48 -07003651 private boolean isActiveSubscription(int subId) {
3652 return mSubscriptionController.isActiveSubId(subId);
3653 }
3654
Ihab Awadf2177b72013-11-25 13:33:23 -08003655 /**
3656 * @see android.telephony.TelephonyManager.WifiCallingChoices
3657 */
3658 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003659 final long identity = Binder.clearCallingIdentity();
3660 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003661 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003662 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3663 getWhenToMakeWifiCallsDefaultPreference());
3664 } finally {
3665 Binder.restoreCallingIdentity(identity);
3666 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003667 }
3668
3669 /**
3670 * @see android.telephony.TelephonyManager.WifiCallingChoices
3671 */
3672 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003676 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003677 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3678 } finally {
3679 Binder.restoreCallingIdentity(identity);
3680 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003681 }
3682
Sailesh Nepald1e68152013-12-12 19:08:02 -08003683 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003684 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003685 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003686 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003687
Jordan Liu73b078d2019-02-28 12:03:40 -08003688 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3689 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3690 if (phoneId == -1) {
3691 throw new IllegalArgumentException("Given slot index: " + slotIndex
3692 + " does not correspond to an active phone");
3693 }
3694 return PhoneFactory.getPhone(phoneId);
3695 }
3696
Shishir Agrawal566b7612013-10-28 14:41:00 -07003697 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003698 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3699 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3701 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003702 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003703 if (DBG) {
3704 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3705 }
3706 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3707 p2);
3708 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003709
Jordan Liu73b078d2019-02-28 12:03:40 -08003710
3711 @Override
3712 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3713 int slotIndex, String callingPackage, String aid, int p2) {
3714 enforceModifyPermission();
3715 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3716 if (DBG) {
3717 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3718 }
3719 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3720 callingPackage, aid, p2);
3721 }
3722
3723 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3724 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 if (TextUtils.equals(ISDR_AID, aid)) {
3728 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003729 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3730 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003731 if (bestComponent == null
3732 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3733 loge("The calling package is not allowed to access ISD-R.");
3734 throw new SecurityException(
3735 "The calling package is not allowed to access ISD-R.");
3736 }
Derek Tan740e1672017-06-27 14:56:27 -07003737 }
Derek Tan740e1672017-06-27 14:56:27 -07003738
Malcolm Chend965c8b2018-02-28 15:00:40 -08003739 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003740 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3741 null /* workSource */);
3742 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003743 return response;
3744 } finally {
3745 Binder.restoreCallingIdentity(identity);
3746 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003747 }
3748
3749 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003750 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3752 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003753 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3754 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3755 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003756
Jordan Liu73b078d2019-02-28 12:03:40 -08003757 @Override
3758 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3759 enforceModifyPermission();
3760 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3761 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3762 channel);
3763 }
3764
3765 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003766 final long identity = Binder.clearCallingIdentity();
3767 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003768 if (channel < 0) {
3769 return false;
3770 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003771 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3772 null /* workSource */);
3773 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003774 return success;
3775 } finally {
3776 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003777 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003778 }
3779
3780 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003781 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003782 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3784 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003785 if (DBG) {
3786 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3787 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3788 + p3 + " data=" + data);
3789 }
3790 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3791 command, p1, p2, p3, data);
3792 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003793
Jordan Liu73b078d2019-02-28 12:03:40 -08003794 @Override
3795 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3796 int command, int p1, int p2, int p3, String data) {
3797 enforceModifyPermission();
3798 if (DBG) {
3799 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3800 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3801 + p3 + " data=" + data);
3802 }
3803 return iccTransmitApduLogicalChannelWithPermission(
3804 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3805 data);
3806 }
3807
3808 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3809 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003810 final long identity = Binder.clearCallingIdentity();
3811 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003812 if (channel < 0) {
3813 return "";
3814 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003815
Malcolm Chend965c8b2018-02-28 15:00:40 -08003816 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003817 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3818 null /* workSource */);
3819 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003820
Malcolm Chend965c8b2018-02-28 15:00:40 -08003821 // Append the returned status code to the end of the response payload.
3822 String s = Integer.toHexString(
3823 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3824 if (response.payload != null) {
3825 s = IccUtils.bytesToHexString(response.payload) + s;
3826 }
3827 return s;
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003830 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003831 }
Jake Hambye994d462014-02-03 13:10:13 -08003832
Evan Charltonc66da362014-05-16 14:06:40 -07003833 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003834 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3835 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3837 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003838 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003839 if (DBG) {
3840 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3841 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3842 }
3843 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3844 cla, command, p1, p2, p3, data);
3845 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003846
Jordan Liu73b078d2019-02-28 12:03:40 -08003847 @Override
3848 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3849 int command, int p1, int p2, int p3, String data) {
3850 enforceModifyPermission();
3851 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3852 if (DBG) {
3853 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3854 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3855 + " data=" + data);
3856 }
3857
3858 return iccTransmitApduBasicChannelWithPermission(
3859 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3860 p2, p3, data);
3861 }
3862
3863 // open APDU basic channel assuming the caller has sufficient permissions
3864 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3865 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3869 && TextUtils.equals(ISDR_AID, data)) {
3870 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003871 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3872 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003873 if (bestComponent == null
3874 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3875 loge("The calling package is not allowed to select ISD-R.");
3876 throw new SecurityException(
3877 "The calling package is not allowed to select ISD-R.");
3878 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003879 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003880
Malcolm Chend965c8b2018-02-28 15:00:40 -08003881 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003882 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3883 null /* workSource */);
3884 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -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 Agrawalda0bb0d2014-07-29 21:18:53 -07003896 }
3897
3898 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003899 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003900 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3902 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003903
Malcolm Chend965c8b2018-02-28 15:00:40 -08003904 final long identity = Binder.clearCallingIdentity();
3905 try {
3906 if (DBG) {
3907 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3908 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3909 }
3910
3911 IccIoResult response =
3912 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3913 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3914 subId);
3915
3916 if (DBG) {
3917 log("Exchange SIM_IO [R]" + response);
3918 }
3919
3920 byte[] result = null;
3921 int length = 2;
3922 if (response.payload != null) {
3923 length = 2 + response.payload.length;
3924 result = new byte[length];
3925 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3926 } else {
3927 result = new byte[length];
3928 }
3929
3930 result[length - 1] = (byte) response.sw2;
3931 result[length - 2] = (byte) response.sw1;
3932 return result;
3933 } finally {
3934 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003935 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003936 }
3937
Nathan Haroldb3014052017-01-25 15:57:32 -08003938 /**
3939 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3940 * on a particular subscription
3941 */
sqianb6e41952018-03-12 14:54:01 -07003942 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3943 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3944 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3945 return null;
3946 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003947
3948 final long identity = Binder.clearCallingIdentity();
3949 try {
3950 if (appType != TelephonyManager.APPTYPE_USIM
3951 && appType != TelephonyManager.APPTYPE_SIM) {
3952 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3953 return null;
3954 }
3955 Object response = sendRequest(
3956 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3957 if (response instanceof String[]) {
3958 return (String[]) response;
3959 }
3960 // Response is an Exception of some kind,
3961 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003962 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003963 } finally {
3964 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003965 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003966 }
3967
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003968 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003969 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3971 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003972
Malcolm Chend965c8b2018-02-28 15:00:40 -08003973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3976 if (response.payload == null) {
3977 return "";
3978 }
Evan Charltonc66da362014-05-16 14:06:40 -07003979
Malcolm Chend965c8b2018-02-28 15:00:40 -08003980 // Append the returned status code to the end of the response payload.
3981 String s = Integer.toHexString(
3982 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3983 s = IccUtils.bytesToHexString(response.payload) + s;
3984 return s;
3985 } finally {
3986 Binder.restoreCallingIdentity(identity);
3987 }
Evan Charltonc66da362014-05-16 14:06:40 -07003988 }
3989
Jake Hambye994d462014-02-03 13:10:13 -08003990 /**
3991 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3992 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3993 *
3994 * @param itemID the ID of the item to read
3995 * @return the NV item as a String, or null on error.
3996 */
3997 @Override
3998 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003999 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4001 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004002
4003 final long identity = Binder.clearCallingIdentity();
4004 try {
4005 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004006 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004007 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4008 return value;
4009 } finally {
4010 Binder.restoreCallingIdentity(identity);
4011 }
Jake Hambye994d462014-02-03 13:10:13 -08004012 }
4013
4014 /**
4015 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4016 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4017 *
4018 * @param itemID the ID of the item to read
4019 * @param itemValue the value to write, as a String
4020 * @return true on success; false on any failure
4021 */
4022 @Override
4023 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004024 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4026 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004027
4028 final long identity = Binder.clearCallingIdentity();
4029 try {
4030 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4031 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004032 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004033 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4034 return success;
4035 } finally {
4036 Binder.restoreCallingIdentity(identity);
4037 }
Jake Hambye994d462014-02-03 13:10:13 -08004038 }
4039
4040 /**
4041 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4042 * Used for device configuration by some CDMA operators.
4043 *
4044 * @param preferredRoamingList byte array containing the new PRL
4045 * @return true on success; false on any failure
4046 */
4047 @Override
4048 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4050 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004051
4052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4055 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4056 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4057 return success;
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
Jake Hambye994d462014-02-03 13:10:13 -08004061 }
4062
4063 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004064 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004065 * Used for device configuration by some CDMA operators.
4066 *
chen xu1cc0abe2018-10-26 17:39:23 -07004067 * @param slotIndex - device slot.
4068 *
Jake Hambye994d462014-02-03 13:10:13 -08004069 * @return true on success; false on any failure
4070 */
4071 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004072 public boolean resetModemConfig(int slotIndex) {
4073 Phone phone = PhoneFactory.getPhone(slotIndex);
4074 if (phone != null) {
4075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4076 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004077
chen xu1cc0abe2018-10-26 17:39:23 -07004078 final long identity = Binder.clearCallingIdentity();
4079 try {
4080 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4081 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4082 return success;
4083 } finally {
4084 Binder.restoreCallingIdentity(identity);
4085 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004086 }
chen xu1cc0abe2018-10-26 17:39:23 -07004087 return false;
4088 }
4089
4090 /**
4091 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4092 *
4093 * @param slotIndex - device slot.
4094 *
4095 * @return true on success; false on any failure
4096 */
4097 @Override
4098 public boolean rebootModem(int slotIndex) {
4099 Phone phone = PhoneFactory.getPhone(slotIndex);
4100 if (phone != null) {
4101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4102 mApp, phone.getSubId(), "rebootModem");
4103
4104 final long identity = Binder.clearCallingIdentity();
4105 try {
4106 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4107 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4108 return success;
4109 } finally {
4110 Binder.restoreCallingIdentity(identity);
4111 }
4112 }
4113 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004114 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004115
Svet Ganovb320e182015-04-16 12:30:10 -07004116 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004117 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004119 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004120 return new String[0];
4121 }
4122
Malcolm Chend965c8b2018-02-28 15:00:40 -08004123 final long identity = Binder.clearCallingIdentity();
4124 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004125 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
Wink Saville36469e72014-06-11 15:17:00 -07004129 }
4130
Brad Ebinger51f743a2017-01-23 13:50:20 -08004131 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004132 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4133 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004134 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004135 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004136 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004137
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004140 ImsResolver resolver = PhoneFactory.getImsResolver();
4141 if (resolver == null) {
4142 // may happen if the device does not support IMS.
4143 return;
4144 }
4145 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004146 } finally {
4147 Binder.restoreCallingIdentity(identity);
4148 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004149 }
4150
4151 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004152 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4153 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004154 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004155 public void disableIms(int slotId) {
4156 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004157
4158 final long identity = Binder.clearCallingIdentity();
4159 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004160 ImsResolver resolver = PhoneFactory.getImsResolver();
4161 if (resolver == null) {
4162 // may happen if the device does not support IMS.
4163 return;
4164 }
4165 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004166 } finally {
4167 Binder.restoreCallingIdentity(identity);
4168 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004169 }
4170
4171 /**
4172 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4173 * feature or {@link null} if the service is not available. If the feature is available, the
4174 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4175 */
4176 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004177 IImsServiceFeatureCallback callback) {
4178 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004179
4180 final long identity = Binder.clearCallingIdentity();
4181 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004182 ImsResolver resolver = PhoneFactory.getImsResolver();
4183 if (resolver == null) {
4184 // may happen if the device does not support IMS.
4185 return null;
4186 }
4187 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004191 }
4192
4193 /**
4194 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4195 * feature during emergency calling or {@link null} if the service is not available. If the
4196 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4197 * listener for feature updates.
4198 */
4199 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4200 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004201
4202 final long identity = Binder.clearCallingIdentity();
4203 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004204 ImsResolver resolver = PhoneFactory.getImsResolver();
4205 if (resolver == null) {
4206 // may happen if the device does not support IMS.
4207 return null;
4208 }
4209 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004210 } finally {
4211 Binder.restoreCallingIdentity(identity);
4212 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004213 }
4214
Brad Ebinger5f64b052017-12-14 14:26:15 -08004215 /**
4216 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004217 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004218 */
4219 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4220 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004221
4222 final long identity = Binder.clearCallingIdentity();
4223 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004224 ImsResolver resolver = PhoneFactory.getImsResolver();
4225 if (resolver == null) {
4226 // may happen if the device does not support IMS.
4227 return null;
4228 }
4229 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004230 } finally {
4231 Binder.restoreCallingIdentity(identity);
4232 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004233 }
4234
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004235 /**
4236 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004237 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004238 */
4239 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4240 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004241
4242 final long identity = Binder.clearCallingIdentity();
4243 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004244 ImsResolver resolver = PhoneFactory.getImsResolver();
4245 if (resolver == null) {
4246 // may happen if the device does not support IMS.
4247 return null;
4248 }
4249 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004250 } finally {
4251 Binder.restoreCallingIdentity(identity);
4252 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004253 }
4254
Brad Ebinger884c07b2018-02-15 16:17:40 -08004255 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004256 * Sets the ImsService Package Name that Telephony will bind to.
4257 *
4258 * @param slotId the slot ID that the ImsService should bind for.
4259 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4260 * ImsService is the device default ImsService.
4261 * @param packageName The package name of the application that contains the ImsService to bind
4262 * to.
4263 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4264 * @hide
4265 */
4266 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004267 int[] subIds = SubscriptionManager.getSubId(slotId);
4268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4269 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4270 "setImsService");
4271
Malcolm Chend965c8b2018-02-28 15:00:40 -08004272 final long identity = Binder.clearCallingIdentity();
4273 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004274 ImsResolver resolver = PhoneFactory.getImsResolver();
4275 if (resolver == null) {
4276 // may happen if the device does not support IMS.
4277 return false;
4278 }
4279 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4280 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004284 }
4285
4286 /**
4287 * Return the ImsService configuration.
4288 *
4289 * @param slotId The slot that the ImsService is associated with.
4290 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4291 * the device default.
4292 * @return the package name of the ImsService configuration.
4293 */
4294 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004295 int[] subIds = SubscriptionManager.getSubId(slotId);
4296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4297 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4298 "getImsService");
4299
Malcolm Chend965c8b2018-02-28 15:00:40 -08004300 final long identity = Binder.clearCallingIdentity();
4301 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004302 ImsResolver resolver = PhoneFactory.getImsResolver();
4303 if (resolver == null) {
4304 // may happen if the device does not support IMS.
4305 return "";
4306 }
4307 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004308 } finally {
4309 Binder.restoreCallingIdentity(identity);
4310 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004311 }
4312
Wink Saville36469e72014-06-11 15:17:00 -07004313 public void setImsRegistrationState(boolean registered) {
4314 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004315
4316 final long identity = Binder.clearCallingIdentity();
4317 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004318 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
Wink Saville36469e72014-06-11 15:17:00 -07004322 }
4323
4324 /**
Stuart Scott54788802015-03-30 13:18:01 -07004325 * Set the network selection mode to automatic.
4326 *
4327 */
4328 @Override
4329 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4331 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004332
Pengquan Meng466e2482018-09-21 15:54:48 -07004333 if (!isActiveSubscription(subId)) {
4334 return;
4335 }
4336
Malcolm Chend965c8b2018-02-28 15:00:40 -08004337 final long identity = Binder.clearCallingIdentity();
4338 try {
4339 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4340 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
4343 }
Stuart Scott54788802015-03-30 13:18:01 -07004344 }
4345
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004346 /**
4347 * Ask the radio to connect to the input network and change selection mode to manual.
4348 *
4349 * @param subId the id of the subscription.
4350 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4351 * the operator to attach to.
4352 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4353 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4354 * normal network selection next time.
4355 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004356 */
4357 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004358 public boolean setNetworkSelectionModeManual(
4359 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4361 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004362
4363 if (!isActiveSubscription(subId)) {
4364 return false;
4365 }
4366
Malcolm Chend965c8b2018-02-28 15:00:40 -08004367 final long identity = Binder.clearCallingIdentity();
4368 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004369 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004370 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004371 if (DBG) {
4372 log("setNetworkSelectionModeManual: subId: " + subId
4373 + " operator: " + operatorInfo);
4374 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004375 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4376 } finally {
4377 Binder.restoreCallingIdentity(identity);
4378 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004379 }
4380
4381 /**
4382 * Scans for available networks.
4383 */
4384 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004385 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4387 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004388 LocationAccessPolicy.LocationPermissionResult locationResult =
4389 LocationAccessPolicy.checkLocationPermission(mApp,
4390 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4391 .setCallingPackage(callingPackage)
4392 .setCallingPid(Binder.getCallingPid())
4393 .setCallingUid(Binder.getCallingUid())
4394 .setMethod("getCellNetworkScanResults")
4395 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4396 .build());
4397 switch (locationResult) {
4398 case DENIED_HARD:
4399 throw new SecurityException("Not allowed to access scan results -- location");
4400 case DENIED_SOFT:
4401 return null;
4402 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004403
Pengquan Meng0c05b502018-09-06 09:59:22 -07004404 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004405 try {
4406 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004407 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004408 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004409 } finally {
4410 Binder.restoreCallingIdentity(identity);
4411 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004412 }
4413
4414 /**
yinxub1bed742017-04-17 11:45:04 -07004415 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004416 *
yinxub1bed742017-04-17 11:45:04 -07004417 * @param subId id of the subscription
4418 * @param request contains the radio access networks with bands/channels to scan
4419 * @param messenger callback messenger for scan results or errors
4420 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004421 * @return the id of the requested scan which can be used to stop the scan.
4422 */
4423 @Override
4424 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004425 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4427 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004428 LocationAccessPolicy.LocationPermissionResult locationResult =
4429 LocationAccessPolicy.checkLocationPermission(mApp,
4430 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4431 .setCallingPackage(callingPackage)
4432 .setCallingPid(Binder.getCallingPid())
4433 .setCallingUid(Binder.getCallingUid())
4434 .setMethod("requestNetworkScan")
4435 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4436 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004437 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4438 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4439 if (e != null) {
4440 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4441 throw e;
4442 } else {
4443 return TelephonyScanManager.INVALID_SCAN_ID;
4444 }
4445 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004446 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004447 return mNetworkScanRequestTracker.startNetworkScan(
4448 request, messenger, binder, getPhone(subId),
4449 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004450 }
4451
Hall Liub2ac8ef2019-02-28 15:56:23 -08004452 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4453 NetworkScanRequest request) {
4454 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4455 != PERMISSION_GRANTED) {
4456 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4457 + " without location access.");
4458 }
4459
4460 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4461 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
4462 if (ras.getBands() != null && ras.getBands().length > 0) {
4463 return new SecurityException("Specific bands must not be"
4464 + " scanned without location access.");
4465 }
4466 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4467 return new SecurityException("Specific channels must not be"
4468 + " scanned without location access.");
4469 }
4470 }
4471 }
4472
4473 List<String> allowedMccMncs =
4474 NetworkScanRequestTracker.getAllowedMccMncsForLocationRestrictedScan(mApp);
4475 for (String mccmnc : request.getPlmns()) {
4476 if (!allowedMccMncs.contains(mccmnc)) {
4477 return new SecurityException("Requested mccmnc " + mccmnc + " is not known to the"
4478 + " device and cannot be scanned for without location access.");
4479 }
4480 }
4481
4482 return null;
4483 }
4484
yinxu504e1392017-04-12 16:03:22 -07004485 /**
4486 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004487 *
4488 * @param subId id of the subscription
4489 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004490 */
4491 @Override
4492 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4494 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004495
4496 final long identity = Binder.clearCallingIdentity();
4497 try {
4498 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4499 } finally {
4500 Binder.restoreCallingIdentity(identity);
4501 }
yinxu504e1392017-04-12 16:03:22 -07004502 }
4503
4504 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004505 * Get the calculated preferred network type.
4506 * Used for debugging incorrect network type.
4507 *
4508 * @return the preferred network type, defined in RILConstants.java.
4509 */
4510 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004511 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004512 final Phone defaultPhone = getDefaultPhone();
4513 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4514 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004515 return RILConstants.PREFERRED_NETWORK_MODE;
4516 }
4517
Malcolm Chend965c8b2018-02-28 15:00:40 -08004518 final long identity = Binder.clearCallingIdentity();
4519 try {
4520 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004521 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004522 } finally {
4523 Binder.restoreCallingIdentity(identity);
4524 }
Junda Liu84d15a22014-07-02 11:21:04 -07004525 }
4526
4527 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004528 * Get the preferred network type.
4529 * Used for device configuration by some CDMA operators.
4530 *
4531 * @return the preferred network type, defined in RILConstants.java.
4532 */
4533 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004534 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004535 TelephonyPermissions
4536 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4537 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004538
4539 final long identity = Binder.clearCallingIdentity();
4540 try {
4541 if (DBG) log("getPreferredNetworkType");
4542 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4543 int networkType = (result != null ? result[0] : -1);
4544 if (DBG) log("getPreferredNetworkType: " + networkType);
4545 return networkType;
4546 } finally {
4547 Binder.restoreCallingIdentity(identity);
4548 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004549 }
4550
4551 /**
4552 * Set the preferred network type.
4553 * Used for device configuration by some CDMA operators.
4554 *
4555 * @param networkType the preferred network type, defined in RILConstants.java.
4556 * @return true on success; false on any failure.
4557 */
4558 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004559 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4561 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004562
4563 final long identity = Binder.clearCallingIdentity();
4564 try {
4565 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4566 Boolean success = (Boolean) sendRequest(
4567 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4568 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4569 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004570 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004571 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4572 }
4573 return success;
4574 } finally {
4575 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004576 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004577 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004578
4579 /**
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004580 * Check whether DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004581 *
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004582 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004583 * @hide
4584 */
4585 @Override
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004586 public boolean getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004587 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004588 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004589 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004590 try {
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004591 return defaultPhone.hasMatchedTetherApnSetting();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004592 } finally {
4593 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004594 }
Junda Liu475951f2014-11-07 16:45:03 -08004595 }
4596
4597 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004598 * Set mobile data enabled
4599 * Used by the user through settings etc to turn on/off mobile data
4600 *
4601 * @param enable {@code true} turn turn data on, else {@code false}
4602 */
4603 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004604 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4606 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004607
4608 final long identity = Binder.clearCallingIdentity();
4609 try {
4610 int phoneId = mSubscriptionController.getPhoneId(subId);
4611 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4612 Phone phone = PhoneFactory.getPhone(phoneId);
4613 if (phone != null) {
4614 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004615 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004616 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004617 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004618 }
4619 } finally {
4620 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004621 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004622 }
4623
4624 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004625 * Get the user enabled state of Mobile Data.
4626 *
4627 * TODO: remove and use isUserDataEnabled.
4628 * This can't be removed now because some vendor codes
4629 * calls through ITelephony directly while they should
4630 * use TelephonyManager.
4631 *
4632 * @return true on enabled
4633 */
4634 @Override
4635 public boolean getDataEnabled(int subId) {
4636 return isUserDataEnabled(subId);
4637 }
4638
4639 /**
4640 * Get whether mobile data is enabled per user setting.
4641 *
4642 * There are other factors deciding whether mobile data is actually enabled, but they are
4643 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004644 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004645 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004646 *
4647 * @return {@code true} if data is enabled else {@code false}
4648 */
4649 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004650 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004651 try {
4652 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4653 null);
4654 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4656 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004657 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004658
4659 final long identity = Binder.clearCallingIdentity();
4660 try {
4661 int phoneId = mSubscriptionController.getPhoneId(subId);
4662 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4663 Phone phone = PhoneFactory.getPhone(phoneId);
4664 if (phone != null) {
4665 boolean retVal = phone.isUserDataEnabled();
4666 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4667 return retVal;
4668 } else {
4669 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4670 return false;
4671 }
4672 } finally {
4673 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004674 }
4675 }
4676
4677 /**
4678 * Get whether mobile data is enabled.
4679 *
4680 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4681 * whether mobile data is actually enabled.
4682 *
4683 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4684 *
4685 * @return {@code true} if data is enabled else {@code false}
4686 */
4687 @Override
4688 public boolean isDataEnabled(int subId) {
4689 try {
4690 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4691 null);
4692 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4694 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004695 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004696
4697 final long identity = Binder.clearCallingIdentity();
4698 try {
4699 int phoneId = mSubscriptionController.getPhoneId(subId);
4700 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4701 Phone phone = PhoneFactory.getPhone(phoneId);
4702 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004703 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004704 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4705 return retVal;
4706 } else {
4707 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4708 return false;
4709 }
4710 } finally {
4711 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004712 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004713 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004714
4715 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004716 public int getCarrierPrivilegeStatus(int subId) {
4717 final Phone phone = getPhone(subId);
4718 if (phone == null) {
4719 loge("getCarrierPrivilegeStatus: Invalid subId");
4720 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4721 }
4722 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004723 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004724 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004725 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4726 }
4727 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004728 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004729 }
Junda Liu29340342014-07-10 15:23:27 -07004730
4731 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004732 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4733 final Phone phone = getPhone(subId);
4734 if (phone == null) {
4735 loge("getCarrierPrivilegeStatus: Invalid subId");
4736 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4737 }
4738 UiccProfile profile =
4739 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4740 if (profile == null) {
4741 loge("getCarrierPrivilegeStatus: No UICC");
4742 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4743 }
4744 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4745 }
4746
4747 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004748 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004749 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004750 if (TextUtils.isEmpty(pkgName))
4751 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004752 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004753 if (card == null) {
4754 loge("checkCarrierPrivilegesForPackage: No UICC");
4755 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4756 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004757 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4758 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004759 }
4760
4761 @Override
4762 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004763 if (TextUtils.isEmpty(pkgName))
4764 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004765 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4766 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4767 UiccCard card = UiccController.getInstance().getUiccCard(i);
4768 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004769 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004770 continue;
4771 }
4772
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004773 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004774 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4775 break;
4776 }
4777 }
4778
4779 return result;
Junda Liu29340342014-07-10 15:23:27 -07004780 }
Derek Tan89e89d42014-07-08 17:00:10 -07004781
4782 @Override
Junda Liue64de782015-04-16 17:19:16 -07004783 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4784 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4785 loge("phoneId " + phoneId + " is not valid.");
4786 return null;
4787 }
4788 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004789 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004790 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004791 return null ;
4792 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004793 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004794 }
4795
Amith Yamasani6e118872016-02-19 12:53:51 -08004796 @Override
4797 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004798 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004799 List<String> privilegedPackages = new ArrayList<>();
4800 List<PackageInfo> packages = null;
4801 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4802 UiccCard card = UiccController.getInstance().getUiccCard(i);
4803 if (card == null) {
4804 // No UICC in that slot.
4805 continue;
4806 }
4807 if (card.hasCarrierPrivilegeRules()) {
4808 if (packages == null) {
4809 // Only check packages in user 0 for now
4810 packages = pm.getInstalledPackagesAsUser(
4811 PackageManager.MATCH_DISABLED_COMPONENTS
4812 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4813 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4814 }
4815 for (int p = packages.size() - 1; p >= 0; p--) {
4816 PackageInfo pkgInfo = packages.get(p);
4817 if (pkgInfo != null && pkgInfo.packageName != null
4818 && card.getCarrierPrivilegeStatus(pkgInfo)
4819 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4820 privilegedPackages.add(pkgInfo.packageName);
4821 }
4822 }
4823 }
4824 }
4825 return privilegedPackages;
4826 }
4827
Wink Savilleb564aae2014-10-23 10:18:09 -07004828 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004829 final Phone phone = getPhone(subId);
4830 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004831 if (card == null) {
4832 loge("getIccId: No UICC");
4833 return null;
4834 }
4835 String iccId = card.getIccId();
4836 if (TextUtils.isEmpty(iccId)) {
4837 loge("getIccId: ICC ID is null or empty.");
4838 return null;
4839 }
4840 return iccId;
4841 }
4842
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004843 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004844 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4845 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004846 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4847 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004848
Malcolm Chend965c8b2018-02-28 15:00:40 -08004849 final long identity = Binder.clearCallingIdentity();
4850 try {
4851 final String iccId = getIccId(subId);
4852 final Phone phone = getPhone(subId);
4853 if (phone == null) {
4854 return false;
4855 }
4856 final String subscriberId = phone.getSubscriberId();
4857
4858 if (DBG_MERGE) {
4859 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4860 + subscriberId + " to " + number);
4861 }
4862
4863 if (TextUtils.isEmpty(iccId)) {
4864 return false;
4865 }
4866
4867 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4868
4869 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4870 if (alphaTag == null) {
4871 editor.remove(alphaTagPrefKey);
4872 } else {
4873 editor.putString(alphaTagPrefKey, alphaTag);
4874 }
4875
4876 // Record both the line number and IMSI for this ICCID, since we need to
4877 // track all merged IMSIs based on line number
4878 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4879 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4880 if (number == null) {
4881 editor.remove(numberPrefKey);
4882 editor.remove(subscriberPrefKey);
4883 } else {
4884 editor.putString(numberPrefKey, number);
4885 editor.putString(subscriberPrefKey, subscriberId);
4886 }
4887
4888 editor.commit();
4889 return true;
4890 } finally {
4891 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004892 }
Derek Tan7226c842014-07-02 17:42:23 -07004893 }
4894
4895 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004896 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004897 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004899 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004900 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004901 return null;
4902 }
Derek Tan97ebb422014-09-05 16:55:38 -07004903
Malcolm Chend965c8b2018-02-28 15:00:40 -08004904 final long identity = Binder.clearCallingIdentity();
4905 try {
4906 String iccId = getIccId(subId);
4907 if (iccId != null) {
4908 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4909 if (DBG_MERGE) {
4910 log("getLine1NumberForDisplay returning "
4911 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4912 }
4913 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004914 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004915 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4916 return null;
4917 } finally {
4918 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004919 }
Derek Tan7226c842014-07-02 17:42:23 -07004920 }
4921
4922 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004923 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004924 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004925 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004926 return null;
4927 }
Derek Tan97ebb422014-09-05 16:55:38 -07004928
Malcolm Chend965c8b2018-02-28 15:00:40 -08004929 final long identity = Binder.clearCallingIdentity();
4930 try {
4931 String iccId = getIccId(subId);
4932 if (iccId != null) {
4933 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4934 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4935 }
4936 return null;
4937 } finally {
4938 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004939 }
Derek Tan7226c842014-07-02 17:42:23 -07004940 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004941
4942 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004943 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004944 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4945 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004946 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004947 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4948 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004949 return null;
4950 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004951
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004952 final long identity = Binder.clearCallingIdentity();
4953 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004954 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004955 final TelephonyManager tele = TelephonyManager.from(context);
4956 final SubscriptionManager sub = SubscriptionManager.from(context);
4957
4958 // Figure out what subscribers are currently active
4959 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4960 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4961 // the process, where TelephonyManager was instantiated.
4962 // Otherwise AppOps check will fail.
4963
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004964 final int[] subIds = sub.getActiveSubscriptionIdList();
4965 for (int subId : subIds) {
4966 activeSubscriberIds.add(tele.getSubscriberId(subId));
4967 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004968
4969 // First pass, find a number override for an active subscriber
4970 String mergeNumber = null;
4971 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4972 for (String key : prefs.keySet()) {
4973 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4974 final String subscriberId = (String) prefs.get(key);
4975 if (activeSubscriberIds.contains(subscriberId)) {
4976 final String iccId = key.substring(
4977 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4978 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4979 mergeNumber = (String) prefs.get(numberKey);
4980 if (DBG_MERGE) {
4981 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4982 + " for active subscriber " + subscriberId);
4983 }
4984 if (!TextUtils.isEmpty(mergeNumber)) {
4985 break;
4986 }
4987 }
4988 }
4989 }
4990
4991 // Shortcut when no active merged subscribers
4992 if (TextUtils.isEmpty(mergeNumber)) {
4993 return null;
4994 }
4995
4996 // Second pass, find all subscribers under that line override
4997 final ArraySet<String> result = new ArraySet<>();
4998 for (String key : prefs.keySet()) {
4999 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5000 final String number = (String) prefs.get(key);
5001 if (mergeNumber.equals(number)) {
5002 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5003 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5004 final String subscriberId = (String) prefs.get(subscriberKey);
5005 if (!TextUtils.isEmpty(subscriberId)) {
5006 result.add(subscriberId);
5007 }
5008 }
5009 }
5010 }
5011
5012 final String[] resultArray = result.toArray(new String[result.size()]);
5013 Arrays.sort(resultArray);
5014 if (DBG_MERGE) {
5015 Slog.d(LOG_TAG,
5016 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5017 }
5018 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005019 } finally {
5020 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005021 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005022 }
5023
5024 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005025 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005026 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5027 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005028
5029 final long identity = Binder.clearCallingIdentity();
5030 try {
5031 final Phone phone = getPhone(subId);
5032 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5033 } finally {
5034 Binder.restoreCallingIdentity(identity);
5035 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005036 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005037
5038 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005039 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005040 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5041 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005042 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005043
5044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 final Phone phone = getPhone(subId);
5047 if (phone == null) {
5048 return false;
5049 }
5050 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5051 cdmaNonRoamingList);
5052 } finally {
5053 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005054 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005055 }
5056
5057 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005058 @Deprecated
5059 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5060 enforceModifyPermission();
5061
5062 int returnValue = 0;
5063 try {
vagdevie435a3e2018-08-15 16:01:53 -07005064 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005065 if(result.exception == null) {
5066 if (result.result != null) {
5067 byte[] responseData = (byte[])(result.result);
5068 if(responseData.length > oemResp.length) {
5069 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5070 responseData.length + "bytes. Buffer Size is " +
5071 oemResp.length + "bytes.");
5072 }
5073 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5074 returnValue = responseData.length;
5075 }
5076 } else {
5077 CommandException ex = (CommandException) result.exception;
5078 returnValue = ex.getCommandError().ordinal();
5079 if(returnValue > 0) returnValue *= -1;
5080 }
5081 } catch (RuntimeException e) {
5082 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5083 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5084 if(returnValue > 0) returnValue *= -1;
5085 }
5086
5087 return returnValue;
5088 }
5089
5090 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005091 public void setRadioCapability(RadioAccessFamily[] rafs) {
5092 try {
5093 ProxyController.getInstance().setRadioCapability(rafs);
5094 } catch (RuntimeException e) {
5095 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5096 }
5097 }
5098
5099 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005100 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005101 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005102 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005103 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005104 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005105 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005106 final long identity = Binder.clearCallingIdentity();
5107 try {
chen xufeeed752018-10-26 14:17:57 -07005108 TelephonyPermissions
5109 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5110 mApp, phone.getSubId(), "getRadioAccessFamily");
5111 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005112 } finally {
5113 Binder.restoreCallingIdentity(identity);
5114 }
chen xufeeed752018-10-26 14:17:57 -07005115 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005116 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005117
5118 @Override
5119 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005120 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005121 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005122
5123 final long identity = Binder.clearCallingIdentity();
5124 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005125 ImsManager.getInstance(defaultPhone.getContext(),
5126 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005127 } finally {
5128 Binder.restoreCallingIdentity(identity);
5129 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005130 }
5131
5132 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005133 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005134 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005135 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005136 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005137 return false;
5138 }
Svet Ganovb320e182015-04-16 12:30:10 -07005139
Malcolm Chend965c8b2018-02-28 15:00:40 -08005140 final long identity = Binder.clearCallingIdentity();
5141 try {
5142 // Check the user preference and the system-level IMS setting. Even if the user has
5143 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5144 // In the long run, we may instead need to check if there exists a connection service
5145 // which can support video calling.
5146 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005147 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005148 return imsManager.isVtEnabledByPlatform()
5149 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5150 && imsManager.isVtEnabledByUser();
5151 } finally {
5152 Binder.restoreCallingIdentity(identity);
5153 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005154 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005155
Andrew Leea1239f22015-03-02 17:44:07 -08005156 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005157 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5159 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5160 return false;
5161 }
5162
5163 final long identity = Binder.clearCallingIdentity();
5164 try {
5165 CarrierConfigManager configManager =
5166 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005167 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005168 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5169 } finally {
5170 Binder.restoreCallingIdentity(identity);
5171 }
Andrew Leea1239f22015-03-02 17:44:07 -08005172 }
5173
5174 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005175 public boolean isWorldPhone(int subId, String callingPackage) {
5176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5177 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5178 return false;
5179 }
5180
5181 final long identity = Binder.clearCallingIdentity();
5182 try {
5183 CarrierConfigManager configManager =
5184 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005185 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005186 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5187 } finally {
5188 Binder.restoreCallingIdentity(identity);
5189 }
Andrew Leea1239f22015-03-02 17:44:07 -08005190 }
5191
Andrew Lee9431b832015-03-09 18:46:45 -07005192 @Override
5193 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005194 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005195 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005196 }
5197
5198 @Override
5199 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005200 final long identity = Binder.clearCallingIdentity();
5201 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005202 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005203 } finally {
5204 Binder.restoreCallingIdentity(identity);
5205 }
Andrew Lee9431b832015-03-09 18:46:45 -07005206 }
5207
Hall Liuf6668912018-10-31 17:05:23 -07005208 /**
5209 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5210 * support for the feature and device firmware support.
5211 *
5212 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5213 */
5214 @Override
5215 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005216 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005217 final Phone phone = getPhone(subscriptionId);
5218 if (phone == null) {
5219 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5220 return false;
5221 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005222 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005223 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005224 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5225 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005226 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005227 return isCarrierSupported && isDeviceSupported;
5228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
Hall Liu98187582018-01-22 19:15:32 -08005231 }
5232
Hall Liuf6668912018-10-31 17:05:23 -07005233 /**
5234 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5235 * both also support RTT.
5236 */
5237 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005238 final long identity = Binder.clearCallingIdentity();
5239 try {
Hall Liuf6668912018-10-31 17:05:23 -07005240 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005241 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005245 }
5246
Sanket Padawe7310cc72015-01-14 09:53:20 -08005247 /**
5248 * Returns the unique device ID of phone, for example, the IMEI for
5249 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5250 *
5251 * <p>Requires Permission:
5252 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5253 */
5254 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005255 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005256 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005257 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005258 return null;
5259 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005260 int subId = phone.getSubId();
5261 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5262 mApp, subId, callingPackage, "getDeviceId")) {
5263 return null;
5264 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005265
5266 final long identity = Binder.clearCallingIdentity();
5267 try {
5268 return phone.getDeviceId();
5269 } finally {
5270 Binder.restoreCallingIdentity(identity);
5271 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005272 }
5273
Ping Sunc67b7c22016-03-02 19:16:45 +08005274 /**
5275 * {@hide}
5276 * Returns the IMS Registration Status on a particular subid
5277 *
5278 * @param subId
5279 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005280 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005281 Phone phone = getPhone(subId);
5282 if (phone != null) {
5283 return phone.isImsRegistered();
5284 } else {
5285 return false;
5286 }
5287 }
5288
Santos Cordon7a1885b2015-02-03 11:15:19 -08005289 @Override
5290 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005291 final long identity = Binder.clearCallingIdentity();
5292 try {
5293 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005297 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005298
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005299 /**
5300 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005301 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005302 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005303 final long identity = Binder.clearCallingIdentity();
5304 try {
5305 Phone phone = getPhone(subId);
5306 if (phone != null) {
5307 return phone.isWifiCallingEnabled();
5308 } else {
5309 return false;
5310 }
5311 } finally {
5312 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005313 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005314 }
5315
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005316 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005317 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005318 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005319 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005320 final long identity = Binder.clearCallingIdentity();
5321 try {
5322 Phone phone = getPhone(subId);
5323 if (phone != null) {
5324 return phone.isVideoEnabled();
5325 } else {
5326 return false;
5327 }
5328 } finally {
5329 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005330 }
5331 }
5332
5333 /**
5334 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5335 * defined in {@link ImsRegistrationImplBase}.
5336 */
5337 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005338 final long identity = Binder.clearCallingIdentity();
5339 try {
5340 Phone phone = getPhone(subId);
5341 if (phone != null) {
5342 return phone.getImsRegistrationTech();
5343 } else {
5344 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5345 }
5346 } finally {
5347 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005348 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005349 }
5350
Stuart Scott8eef64f2015-04-08 15:13:54 -07005351 @Override
5352 public void factoryReset(int subId) {
5353 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005354 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5355 return;
5356 }
5357
Svet Ganovcc087f82015-05-12 20:35:54 -07005358 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005359
Svet Ganovcc087f82015-05-12 20:35:54 -07005360 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005361 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5362 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005363 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005364 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005365 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005366 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5367 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005368 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005369 // There has been issues when Sms raw table somehow stores orphan
5370 // fragments. They lead to garbled message when new fragments come
5371 // in and combined with those stale ones. In case this happens again,
5372 // user can reset all network settings which will clean up this table.
5373 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005374 } finally {
5375 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005376 }
5377 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005378
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005379 private void cleanUpSmsRawTable(Context context) {
5380 ContentResolver resolver = context.getContentResolver();
5381 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5382 resolver.delete(uri, null, null);
5383 }
5384
Narayan Kamath1c496c22015-04-16 14:40:19 +01005385 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005386 public String getSimLocaleForSubscriber(int subId) {
5387 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5388 final Phone phone = getPhone(subId);
5389 if (phone == null) {
5390 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005391 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005392 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005393 final long identity = Binder.clearCallingIdentity();
5394 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005395 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5396 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005397 // Try and fetch the locale from the carrier properties or from the SIM language
5398 // preferences (EF-PL and EF-LI)...
5399 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005400 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005401 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5402 if (localeFromDefaultSim != null) {
5403 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5404 if (DBG) log("Using locale from subId: " + subId + " locale: "
5405 + localeFromDefaultSim);
5406 return localeFromDefaultSim.toLanguageTag();
5407 } else {
5408 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005409 }
5410 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005411
Malcolm Chend965c8b2018-02-28 15:00:40 -08005412 // The SIM language preferences only store a language (e.g. fr = French), not an
5413 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5414 // the SIM and carrier preferences does not include a country we add the country
5415 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005416 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005417 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005418 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005419 return mccLocale.toLanguageTag();
5420 }
5421
5422 if (DBG) log("No locale found - returning null");
5423 return null;
5424 } finally {
5425 Binder.restoreCallingIdentity(identity);
5426 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005427 }
5428
5429 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005430 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005431 }
5432
Malcolm Chend965c8b2018-02-28 15:00:40 -08005433 /**
5434 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5435 */
5436 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005437 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005438 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005439
Chenjie Yu1ba97252018-01-11 18:16:20 -08005440 private final ModemActivityInfo mLastModemActivityInfo =
5441 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5442
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005443 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005444 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5445 * representing the state of the modem.
5446 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005447 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5448 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005449 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005450 */
5451 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005452 public void requestModemActivityInfo(ResultReceiver result) {
5453 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005454 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005455
5456 final long identity = Binder.clearCallingIdentity();
5457 try {
5458 ModemActivityInfo ret = null;
5459 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005460 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5461 CMD_GET_MODEM_ACTIVITY_INFO,
5462 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005463 if (isModemActivityInfoValid(info)) {
5464 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5465 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5466 mergedTxTimeMs[i] =
5467 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5468 }
5469 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5470 mLastModemActivityInfo.setSleepTimeMillis(
5471 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5472 mLastModemActivityInfo.setIdleTimeMillis(
5473 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5474 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5475 mLastModemActivityInfo.setRxTimeMillis(
5476 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5477 mLastModemActivityInfo.setEnergyUsed(
5478 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005479 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005480 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5481 mLastModemActivityInfo.getSleepTimeMillis(),
5482 mLastModemActivityInfo.getIdleTimeMillis(),
5483 mLastModemActivityInfo.getTxTimeMillis(),
5484 mLastModemActivityInfo.getRxTimeMillis(),
5485 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005486 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005487 Bundle bundle = new Bundle();
5488 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5489 result.send(0, bundle);
5490 } finally {
5491 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005492 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005493 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005494
Siddharth Rayf5d29552018-06-17 15:02:38 -07005495 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5496 // less than total activity duration.
5497 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5498 if (info == null) {
5499 return false;
5500 }
5501 int activityDurationMs =
5502 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5503 int totalTxTimeMs = 0;
5504 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5505 totalTxTimeMs += info.getTxTimeMillis()[i];
5506 }
5507 return (info.isValid()
5508 && (info.getSleepTimeMillis() <= activityDurationMs)
5509 && (info.getIdleTimeMillis() <= activityDurationMs)
5510 && (info.getRxTimeMillis() <= activityDurationMs)
5511 && (totalTxTimeMs <= activityDurationMs));
5512 }
5513
Jack Yu85bd38a2015-11-09 11:34:32 -08005514 /**
5515 * {@hide}
5516 * Returns the service state information on specified subscription.
5517 */
5518 @Override
5519 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005520 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005521 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005522 return null;
5523 }
5524
Hall Liuf19c44f2018-11-27 14:38:17 -08005525 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5526 LocationAccessPolicy.checkLocationPermission(mApp,
5527 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5528 .setCallingPackage(callingPackage)
5529 .setCallingPid(Binder.getCallingPid())
5530 .setCallingUid(Binder.getCallingUid())
5531 .setMethod("getServiceStateForSubscriber")
5532 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5533 .build());
5534
5535 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5536 LocationAccessPolicy.checkLocationPermission(mApp,
5537 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5538 .setCallingPackage(callingPackage)
5539 .setCallingPid(Binder.getCallingPid())
5540 .setCallingUid(Binder.getCallingUid())
5541 .setMethod("getServiceStateForSubscriber")
5542 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5543 .build());
5544 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5545 boolean hasFinePermission =
5546 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5547 boolean hasCoarsePermission =
5548 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5549
Malcolm Chend965c8b2018-02-28 15:00:40 -08005550 final long identity = Binder.clearCallingIdentity();
5551 try {
5552 final Phone phone = getPhone(subId);
5553 if (phone == null) {
5554 return null;
5555 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005556
Hall Liuf19c44f2018-11-27 14:38:17 -08005557 ServiceState ss = phone.getServiceState();
5558
5559 // Scrub out the location info in ServiceState depending on what level of access
5560 // the caller has.
5561 if (hasFinePermission) return ss;
5562 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5563 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005564 } finally {
5565 Binder.restoreCallingIdentity(identity);
5566 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005567 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005568
5569 /**
5570 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5571 *
5572 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5573 * voicemail ringtone.
5574 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5575 * PhoneAccount.
5576 */
5577 @Override
5578 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005579 final long identity = Binder.clearCallingIdentity();
5580 try {
5581 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5582 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005583 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005584 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005585
Malcolm Chend965c8b2018-02-28 15:00:40 -08005586 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5587 } finally {
5588 Binder.restoreCallingIdentity(identity);
5589 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005590 }
5591
5592 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005593 * Sets the per-account voicemail ringtone.
5594 *
5595 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5596 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5597 *
5598 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5599 * voicemail ringtone.
5600 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5601 * PhoneAccount.
5602 */
5603 @Override
5604 public void setVoicemailRingtoneUri(String callingPackage,
5605 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005606 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5608 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005609 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5611 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5612 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005613 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005614
5615 final long identity = Binder.clearCallingIdentity();
5616 try {
5617 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5618 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005619 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005620 }
5621 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5622 } finally {
5623 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005624 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005625 }
5626
5627 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005628 * Returns whether vibration is set for voicemail notification in Phone settings.
5629 *
5630 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5631 * voicemail vibration setting.
5632 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5633 */
5634 @Override
5635 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005636 final long identity = Binder.clearCallingIdentity();
5637 try {
5638 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5639 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005640 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005641 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005642
Malcolm Chend965c8b2018-02-28 15:00:40 -08005643 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5644 } finally {
5645 Binder.restoreCallingIdentity(identity);
5646 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005647 }
5648
Youhan Wange64578a2016-05-02 15:32:42 -07005649 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005650 * Sets the per-account voicemail vibration.
5651 *
5652 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5653 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5654 *
5655 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5656 * voicemail vibration setting.
5657 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5658 * specific PhoneAccount.
5659 */
5660 @Override
5661 public void setVoicemailVibrationEnabled(String callingPackage,
5662 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005663 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005664 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5665 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005666 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5668 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5669 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005670 }
5671
Malcolm Chend965c8b2018-02-28 15:00:40 -08005672 final long identity = Binder.clearCallingIdentity();
5673 try {
5674 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5675 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005676 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005677 }
5678 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5679 } finally {
5680 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005681 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005682 }
5683
5684 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005685 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5686 *
5687 * @throws SecurityException if the caller does not have the required permission
5688 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005689 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005690 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005691 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005692 }
5693
5694 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005695 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5696 * permission.
5697 *
5698 * @throws SecurityException if the caller does not have the required permission
5699 */
5700 private void enforceSendSmsPermission() {
5701 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5702 }
5703
5704 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005705 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005706 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005707 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005708 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005709 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005710 final long identity = Binder.clearCallingIdentity();
5711 try {
5712 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005713 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005714 if (componentName == null) {
5715 throw new SecurityException(
5716 "Caller not current active visual voicemail package[null]");
5717 }
5718 String vvmPackage = componentName.getPackageName();
5719 if (!callingPackage.equals(vvmPackage)) {
5720 throw new SecurityException("Caller not current active visual voicemail package["
5721 + vvmPackage + "]");
5722 }
5723 } finally {
5724 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005725 }
5726 }
5727
5728 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005729 * Return the application ID for the app type.
5730 *
5731 * @param subId the subscription ID that this request applies to.
5732 * @param appType the uicc app type.
5733 * @return Application ID for specificied app type, or null if no uicc.
5734 */
5735 @Override
5736 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005737 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005738 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005739
5740 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005741 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005742 if (phone == null) {
5743 return null;
5744 }
5745 String aid = null;
5746 try {
5747 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5748 .getApplicationByType(appType).getAid();
5749 } catch (Exception e) {
5750 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5751 }
5752 return aid;
5753 } finally {
5754 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005755 }
Youhan Wange64578a2016-05-02 15:32:42 -07005756 }
5757
Youhan Wang4001d252016-05-11 10:29:41 -07005758 /**
5759 * Return the Electronic Serial Number.
5760 *
5761 * @param subId the subscription ID that this request applies to.
5762 * @return ESN or null if error.
5763 */
5764 @Override
5765 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005766 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005767 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005768
5769 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005770 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005771 if (phone == null) {
5772 return null;
5773 }
5774 String esn = null;
5775 try {
5776 esn = phone.getEsn();
5777 } catch (Exception e) {
5778 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5779 }
5780 return esn;
5781 } finally {
5782 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005783 }
Youhan Wang4001d252016-05-11 10:29:41 -07005784 }
5785
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005786 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005787 * Return the Preferred Roaming List Version.
5788 *
5789 * @param subId the subscription ID that this request applies to.
5790 * @return PRLVersion or null if error.
5791 */
5792 @Override
5793 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005794 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005795 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005796
5797 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005798 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005799 if (phone == null) {
5800 return null;
5801 }
5802 String cdmaPrlVersion = null;
5803 try {
5804 cdmaPrlVersion = phone.getCdmaPrlVersion();
5805 } catch (Exception e) {
5806 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5807 }
5808 return cdmaPrlVersion;
5809 } finally {
5810 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005811 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005812 }
5813
5814 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005815 * Get snapshot of Telephony histograms
5816 * @return List of Telephony histograms
5817 * @hide
5818 */
5819 @Override
5820 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5822 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005823
5824 final long identity = Binder.clearCallingIdentity();
5825 try {
5826 return RIL.getTelephonyRILTimingHistograms();
5827 } finally {
5828 Binder.restoreCallingIdentity(identity);
5829 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005830 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005831
5832 /**
5833 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005834 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5835 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005836 * Require system privileges. In the future we may add this to carrier APIs.
5837 *
Michele Berionne0963c862018-11-27 18:57:59 -08005838 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005839 */
5840 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005841 @TelephonyManager.SetCarrierRestrictionResult
5842 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005843 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005844 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005845
Michele Berionne0963c862018-11-27 18:57:59 -08005846 if (carrierRestrictionRules == null) {
5847 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005848 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005849
Malcolm Chend965c8b2018-02-28 15:00:40 -08005850 final long identity = Binder.clearCallingIdentity();
5851 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005852 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005853 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005854 } finally {
5855 Binder.restoreCallingIdentity(identity);
5856 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005857 }
5858
5859 /**
5860 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005861 * Get the allowed carrier list and the excluded carrier list, including the priority between
5862 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005863 * Require system privileges. In the future we may add this to carrier APIs.
5864 *
Michele Berionne0963c862018-11-27 18:57:59 -08005865 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005866 */
5867 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005868 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005869 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005870 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005871
5872 final long identity = Binder.clearCallingIdentity();
5873 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005874 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5875 if (response instanceof CarrierRestrictionRules) {
5876 return (CarrierRestrictionRules) response;
5877 }
5878 // Response is an Exception of some kind,
5879 // which is signalled to the user as a NULL retval
5880 return null;
5881 } catch (Exception e) {
5882 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5883 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005884 } finally {
5885 Binder.restoreCallingIdentity(identity);
5886 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005887 }
5888
fionaxu59545b42016-05-25 15:53:37 -07005889 /**
5890 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5891 * @param subId the subscription ID that this action applies to.
5892 * @param enabled control enable or disable metered apns.
5893 * {@hide}
5894 */
5895 @Override
5896 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5897 enforceModifyPermission();
5898 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005899
5900 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005901 if (phone == null) {
5902 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5903 return;
5904 }
5905 try {
5906 phone.carrierActionSetMeteredApnsEnabled(enabled);
5907 } catch (Exception e) {
5908 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005909 } finally {
5910 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005911 }
5912 }
5913
5914 /**
5915 * Action set from carrier signalling broadcast receivers to enable/disable radio
5916 * @param subId the subscription ID that this action applies to.
5917 * @param enabled control enable or disable radio.
5918 * {@hide}
5919 */
5920 @Override
5921 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5922 enforceModifyPermission();
5923 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005924
5925 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005926 if (phone == null) {
5927 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5928 return;
5929 }
5930 try {
5931 phone.carrierActionSetRadioEnabled(enabled);
5932 } catch (Exception e) {
5933 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005934 } finally {
5935 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005936 }
5937 }
5938
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005939 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005940 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5941 * network status based on which carrier apps could apply actions accordingly,
5942 * enable/disable default url handler for example.
5943 *
5944 * @param subId the subscription ID that this action applies to.
5945 * @param report control start/stop reporting the default network status.
5946 * {@hide}
5947 */
5948 @Override
5949 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5950 enforceModifyPermission();
5951 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005952
5953 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005954 if (phone == null) {
5955 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5956 return;
5957 }
5958 try {
5959 phone.carrierActionReportDefaultNetworkStatus(report);
5960 } catch (Exception e) {
5961 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005962 } finally {
5963 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005964 }
5965 }
5966
5967 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005968 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5969 * bug report is being generated.
5970 */
5971 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005972 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005973 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5974 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005975 writer.println("Permission Denial: can't dump Phone from pid="
5976 + Binder.getCallingPid()
5977 + ", uid=" + Binder.getCallingUid()
5978 + "without permission "
5979 + android.Manifest.permission.DUMP);
5980 return;
5981 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005982 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005983 }
Jack Yueb89b242016-06-22 13:27:47 -07005984
Brad Ebingerdac2f002018-04-03 15:17:52 -07005985 @Override
5986 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5987 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5988 throws RemoteException {
5989 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5990 }
5991
Jack Yueb89b242016-06-22 13:27:47 -07005992 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005993 * Get aggregated video call data usage since boot.
5994 *
5995 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5996 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005997 * {@hide}
5998 */
5999 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006000 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006001 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6002 null);
6003
Malcolm Chend965c8b2018-02-28 15:00:40 -08006004 final long identity = Binder.clearCallingIdentity();
6005 try {
6006 // NetworkStatsService keeps tracking the active network interface and identity. It
6007 // records the delta with the corresponding network identity.
6008 // We just return the total video call data usage snapshot since boot.
6009 Phone phone = getPhone(subId);
6010 if (phone != null) {
6011 return phone.getVtDataUsage(perUidStats);
6012 }
6013 return null;
6014 } finally {
6015 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006016 }
Jack Yueb89b242016-06-22 13:27:47 -07006017 }
Jack Yu75ab2952016-07-08 14:29:33 -07006018
6019 /**
6020 * Policy control of data connection. Usually used when data limit is passed.
6021 * @param enabled True if enabling the data, otherwise disabling.
6022 * @param subId Subscription index
6023 * {@hide}
6024 */
6025 @Override
6026 public void setPolicyDataEnabled(boolean enabled, int subId) {
6027 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006028
6029 final long identity = Binder.clearCallingIdentity();
6030 try {
6031 Phone phone = getPhone(subId);
6032 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006033 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006034 }
6035 } finally {
6036 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006037 }
6038 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006039
6040 /**
6041 * Get Client request stats
6042 * @return List of Client Request Stats
6043 * @hide
6044 */
6045 @Override
6046 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006048 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006049 return null;
6050 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006051 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006052
Malcolm Chend965c8b2018-02-28 15:00:40 -08006053 final long identity = Binder.clearCallingIdentity();
6054 try {
6055 if (phone != null) {
6056 return phone.getClientRequestStats();
6057 }
6058
6059 return null;
6060 } finally {
6061 Binder.restoreCallingIdentity(identity);
6062 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006063 }
6064
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006065 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006066 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006067 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006068 }
Jack Yueb4124c2017-02-16 15:32:43 -08006069
6070 /**
Grace Chen70990072017-03-24 17:21:30 -07006071 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006072 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006073 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006074 * @param state State of SIM (power down, power up, pass through)
6075 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6076 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6077 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006078 *
6079 **/
6080 @Override
Grace Chen70990072017-03-24 17:21:30 -07006081 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006082 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006083 Phone phone = PhoneFactory.getPhone(slotIndex);
6084
vagdevie435a3e2018-08-15 16:01:53 -07006085 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6086
Malcolm Chend965c8b2018-02-28 15:00:40 -08006087 final long identity = Binder.clearCallingIdentity();
6088 try {
6089 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006090 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006091 }
6092 } finally {
6093 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006094 }
6095 }
Shuo Qiandd210312017-04-12 22:11:33 +00006096
Tyler Gunn65d45c22017-06-05 11:22:26 -07006097 private boolean isUssdApiAllowed(int subId) {
6098 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006099 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006100 if (configManager == null) {
6101 return false;
6102 }
6103 PersistableBundle pb = configManager.getConfigForSubId(subId);
6104 if (pb == null) {
6105 return false;
6106 }
6107 return pb.getBoolean(
6108 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6109 }
6110
Shuo Qiandd210312017-04-12 22:11:33 +00006111 /**
6112 * Check if phone is in emergency callback mode
6113 * @return true if phone is in emergency callback mode
6114 * @param subId sub id
6115 */
goneil9c5f4872017-12-05 14:07:56 -08006116 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006117 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006118 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006119 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006120
6121 final long identity = Binder.clearCallingIdentity();
6122 try {
6123 if (phone != null) {
6124 return phone.isInEcm();
6125 } else {
6126 return false;
6127 }
6128 } finally {
6129 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006130 }
6131 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006132
6133 /**
6134 * Get the current signal strength information for the given subscription.
6135 * Because this information is not updated when the device is in a low power state
6136 * it should not be relied-upon to be current.
6137 * @param subId Subscription index
6138 * @return the most recent cached signal strength info from the modem
6139 */
6140 @Override
6141 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006142 final long identity = Binder.clearCallingIdentity();
6143 try {
6144 Phone p = getPhone(subId);
6145 if (p == null) {
6146 return null;
6147 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006148
Malcolm Chend965c8b2018-02-28 15:00:40 -08006149 return p.getSignalStrength();
6150 } finally {
6151 Binder.restoreCallingIdentity(identity);
6152 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006153 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006154
Pengquan Meng9140aec2018-08-22 14:49:57 -07006155 /**
chen xu907e5a22018-10-11 13:21:04 -07006156 * Get the current modem radio state for the given slot.
6157 * @param slotIndex slot index.
6158 * @param callingPackage the name of the package making the call.
6159 * @return the current radio power state from the modem
6160 */
6161 @Override
6162 public int getRadioPowerState(int slotIndex, String callingPackage) {
6163 Phone phone = PhoneFactory.getPhone(slotIndex);
6164 if (phone != null) {
6165 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6166 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6167 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6168 }
6169
6170 final long identity = Binder.clearCallingIdentity();
6171 try {
6172 return phone.getRadioPowerState();
6173 } finally {
6174 Binder.restoreCallingIdentity(identity);
6175 }
6176 }
6177 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6178 }
6179
6180 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006181 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6182 *
6183 * <p>Requires one of the following permissions:
6184 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6185 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6186 * privileges.
6187 *
6188 * @param subId subscription id
6189 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6190 * {@code false}.
6191 */
6192 @Override
6193 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006194 boolean isEnabled = false;
6195 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006196 try {
6197 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07006198 null /* message */);
6199 Phone phone = getPhone(subId);
6200 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006201 } catch (Exception e) {
6202 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6203 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006204 } finally {
6205 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006206 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006207 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006208 }
6209
6210
6211 /**
6212 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6213 *
6214 * <p> Requires permission:
6215 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6216 * privileges.
6217 *
6218 * @param subId subscription id
6219 * @param isEnabled {@code true} means enable, {@code false} means disable.
6220 */
6221 @Override
6222 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006223 final long identity = Binder.clearCallingIdentity();
6224 try {
6225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6226 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07006227
Pengquan Meng0c05b502018-09-06 09:59:22 -07006228 Phone phone = getPhone(subId);
6229 if (phone != null) {
6230 phone.setDataRoamingEnabled(isEnabled);
6231 }
6232 } finally {
6233 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006234 }
6235 }
6236
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006237 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006238 public boolean isManualNetworkSelectionAllowed(int subId) {
6239 boolean isAllowed = true;
6240 final long identity = Binder.clearCallingIdentity();
6241 try {
6242 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6243 mApp, subId, "isManualNetworkSelectionAllowed");
6244 Phone phone = getPhone(subId);
6245 if (phone != null) {
6246 isAllowed = phone.isCspPlmnEnabled();
6247 }
6248 } finally {
6249 Binder.restoreCallingIdentity(identity);
6250 }
6251 return isAllowed;
6252 }
6253
6254 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006255 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu53fdb782019-02-12 17:54:02 -08006256 try {
6257 enforceReadPrivilegedPermission("getUiccCardsInfo");
6258 } catch (SecurityException e) {
6259 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6260 // has carrier privileges on an active UICC
6261 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6262 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6263 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6264 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006265 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006266
6267 final long identity = Binder.clearCallingIdentity();
6268 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006269 UiccController uiccController = UiccController.getInstance();
6270 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6271
6272 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6273 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6274 // Remove private info if the caller doesn't have access
6275 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6276 for (UiccCardInfo cardInfo : cardInfos) {
6277 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6278 UiccProfile profile = card.getUiccProfile();
6279 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6280 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6281 filteredInfos.add(cardInfo.getUnprivileged());
6282 } else {
6283 filteredInfos.add(cardInfo);
6284 }
6285 }
6286 return filteredInfos;
6287 }
6288 return cardInfos;
6289 } catch (PackageManager.NameNotFoundException e) {
6290 // This should not happen since we pass the package info in from TelephonyManager
6291 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006292 } finally {
6293 Binder.restoreCallingIdentity(identity);
6294 }
6295 }
6296
6297 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006298 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006299 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006300
Malcolm Chend965c8b2018-02-28 15:00:40 -08006301 final long identity = Binder.clearCallingIdentity();
6302 try {
6303 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6304 if (slots == null) {
6305 Rlog.i(LOG_TAG, "slots is null.");
6306 return null;
6307 }
6308
6309 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6310 for (int i = 0; i < slots.length; i++) {
6311 UiccSlot slot = slots[i];
6312 if (slot == null) {
6313 continue;
6314 }
6315
6316 String cardId;
6317 UiccCard card = slot.getUiccCard();
6318 if (card != null) {
6319 cardId = card.getCardId();
6320 } else {
6321 cardId = slot.getIccId();
6322 }
6323
6324 int cardState = 0;
6325 switch (slot.getCardState()) {
6326 case CARDSTATE_ABSENT:
6327 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6328 break;
6329 case CARDSTATE_PRESENT:
6330 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6331 break;
6332 case CARDSTATE_ERROR:
6333 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6334 break;
6335 case CARDSTATE_RESTRICTED:
6336 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6337 break;
6338 default:
6339 break;
6340
6341 }
6342
6343 infos[i] = new UiccSlotInfo(
6344 slot.isActive(),
6345 slot.isEuicc(),
6346 cardId,
6347 cardState,
6348 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006349 slot.isExtendedApduSupported(),
6350 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006351 }
6352 return infos;
6353 } finally {
6354 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006355 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006356 }
6357
6358 @Override
6359 public boolean switchSlots(int[] physicalSlots) {
6360 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006361
6362 final long identity = Binder.clearCallingIdentity();
6363 try {
6364 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6365 } finally {
6366 Binder.restoreCallingIdentity(identity);
6367 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006368 }
Jack Yu4c988042018-02-27 15:30:01 -08006369
6370 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006371 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006372 final long identity = Binder.clearCallingIdentity();
6373 try {
6374 return UiccController.getInstance().getCardIdForDefaultEuicc();
6375 } finally {
6376 Binder.restoreCallingIdentity(identity);
6377 }
6378 }
6379
6380 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006381 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6382 enforceModifyPermission();
6383 final Phone phone = getPhone(subId);
6384 if (phone == null) {
6385 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6386 return;
6387 }
6388
Malcolm Chend965c8b2018-02-28 15:00:40 -08006389 final long identity = Binder.clearCallingIdentity();
6390 try {
6391 phone.setRadioIndicationUpdateMode(filters, mode);
6392 } finally {
6393 Binder.restoreCallingIdentity(identity);
6394 }
Jack Yu4c988042018-02-27 15:30:01 -08006395 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006396
6397 /**
goneil47ffb6e2018-04-06 15:40:58 -07006398 * A test API to reload the UICC profile.
6399 *
6400 * <p>Requires that the calling app has permission
6401 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6402 * @hide
6403 */
6404 @Override
6405 public void refreshUiccProfile(int subId) {
6406 enforceModifyPermission();
6407
6408 final long identity = Binder.clearCallingIdentity();
6409 try {
6410 Phone phone = getPhone(subId);
6411 if (phone == null) {
6412 return;
6413 }
6414 UiccCard uiccCard = phone.getUiccCard();
6415 if (uiccCard == null) {
6416 return;
6417 }
6418 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6419 if (uiccProfile == null) {
6420 return;
6421 }
6422 uiccProfile.refresh();
6423 } finally {
6424 Binder.restoreCallingIdentity(identity);
6425 }
6426 }
6427
6428 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006429 * Returns false if the mobile data is disabled by default, otherwise return true.
6430 */
6431 private boolean getDefaultDataEnabled() {
6432 return "true".equalsIgnoreCase(
6433 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6434 }
6435
6436 /**
6437 * Returns true if the data roaming is enabled by default, i.e the system property
6438 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6439 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6440 */
6441 private boolean getDefaultDataRoamingEnabled(int subId) {
6442 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006443 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006444 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6445 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6446 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6447 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6448 return isDataRoamingEnabled;
6449 }
6450
6451 /**
6452 * Returns the default network type for the given {@code subId}, if the default network type is
6453 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6454 */
6455 private int getDefaultNetworkType(int subId) {
6456 return Integer.parseInt(
6457 TelephonyManager.getTelephonyProperty(
6458 mSubscriptionController.getPhoneId(subId),
6459 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6460 String.valueOf(Phone.PREFERRED_NT_MODE)));
6461 }
fionaxua13278b2018-03-21 00:08:13 -07006462
6463 @Override
6464 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6465 gid1, String gid2, String plmn, String spn) {
6466 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006467
6468 final long identity = Binder.clearCallingIdentity();
6469 try {
6470 final Phone phone = getPhone(subId);
6471 if (phone == null) {
6472 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6473 return;
6474 }
6475 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6476 } finally {
6477 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006478 }
fionaxua13278b2018-03-21 00:08:13 -07006479 }
6480
6481 @Override
6482 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006483 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006484
6485 final long identity = Binder.clearCallingIdentity();
6486 try {
6487 final Phone phone = getPhone(subId);
6488 if (phone == null) {
6489 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6490 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6491 }
6492 return phone.getCarrierIdListVersion();
6493 } finally {
6494 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006495 }
fionaxua13278b2018-03-21 00:08:13 -07006496 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006497
6498 @Override
6499 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6500 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6501 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6502 return -1;
6503 }
6504
6505 final long identity = Binder.clearCallingIdentity();
6506 try {
6507 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6508 } finally {
6509 Binder.restoreCallingIdentity(identity);
6510 }
6511 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006512
6513 @Override
6514 public int getCdmaRoamingMode(int subId) {
6515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6516 mApp, subId, "getCdmaRoamingMode");
6517
6518 final long identity = Binder.clearCallingIdentity();
6519 try {
6520 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6521 } finally {
6522 Binder.restoreCallingIdentity(identity);
6523 }
6524 }
6525
6526 @Override
6527 public boolean setCdmaRoamingMode(int subId, int mode) {
6528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6529 mApp, subId, "setCdmaRoamingMode");
6530
6531 final long identity = Binder.clearCallingIdentity();
6532 try {
6533 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6534 } finally {
6535 Binder.restoreCallingIdentity(identity);
6536 }
6537 }
6538
6539 @Override
6540 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6542 mApp, subId, "setCdmaSubscriptionMode");
6543
6544 final long identity = Binder.clearCallingIdentity();
6545 try {
6546 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6547 } finally {
6548 Binder.restoreCallingIdentity(identity);
6549 }
6550 }
chen xu7ee67862018-10-30 22:27:10 -07006551
sqian2fff4a32018-11-05 14:18:37 -08006552 private void ensureUserRunning(int userId) {
6553 if (!mUserManager.isUserRunning(userId)) {
6554 throw new IllegalStateException("User " + userId + " does not exist or not running");
6555 }
6556 }
6557
6558 /**
6559 * Returns a list of SMS apps on a given user.
6560 *
6561 * Only the shell user (UID 2000 or 0) can call it.
6562 * Target user must be running.
6563 */
6564 @Override
6565 public String[] getSmsApps(int userId) {
6566 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6567 ensureUserRunning(userId);
6568
6569 final Collection<SmsApplicationData> apps =
6570 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6571
6572 String[] ret = new String[apps.size()];
6573 int i = 0;
6574 for (SmsApplicationData app : apps) {
6575 ret[i++] = app.mPackageName;
6576 }
6577 return ret;
6578 }
6579
6580 /**
6581 * Returns the default SMS app package name on a given user.
6582 *
6583 * Only the shell user (UID 2000 or 0) can call it.
6584 * Target user must be running.
6585 */
6586 @Override
6587 public String getDefaultSmsApp(int userId) {
6588 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6589 ensureUserRunning(userId);
6590
6591 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6592 /* updateIfNeeded= */ true, userId);
6593 return cn == null ? null : cn.getPackageName();
6594 }
6595
6596 /**
6597 * Set a package as the default SMS app on a given user.
6598 *
6599 * Only the shell user (UID 2000 or 0) can call it.
6600 * Target user must be running.
6601 */
6602 @Override
6603 public void setDefaultSmsApp(int userId, String packageName) {
6604 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6605 ensureUserRunning(userId);
6606
6607 boolean found = false;
6608 for (String pkg : getSmsApps(userId)) {
6609 if (TextUtils.equals(packageName, pkg)) {
6610 found = true;
6611 break;
6612 }
6613 }
6614 if (!found) {
6615 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6616 }
6617
6618 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6619 }
6620
chen xu7ee67862018-10-30 22:27:10 -07006621 @Override
sqian65eefe12019-02-22 15:55:18 -08006622 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006623 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006624 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006625 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006626 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6627 }
6628 final long identity = Binder.clearCallingIdentity();
6629 try {
sqian991b35e2018-12-12 16:48:18 -08006630 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6631 for (Phone phone: PhoneFactory.getPhones()) {
6632 if (phone.getEmergencyNumberTracker() != null
6633 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6634 emergencyNumberListInternal.put(
6635 phone.getSubId(),
6636 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6637 }
sqian03bca152018-12-05 18:48:28 -08006638 }
sqian991b35e2018-12-12 16:48:18 -08006639 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006640 } finally {
6641 Binder.restoreCallingIdentity(identity);
6642 }
sqian04b86072018-11-07 14:02:21 -08006643 }
6644
6645 @Override
sqian65eefe12019-02-22 15:55:18 -08006646 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006647 final Phone defaultPhone = getDefaultPhone();
6648 if (!exactMatch) {
6649 TelephonyPermissions
6650 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006651 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006652 }
6653 final long identity = Binder.clearCallingIdentity();
6654 try {
sqian991b35e2018-12-12 16:48:18 -08006655 for (Phone phone: PhoneFactory.getPhones()) {
6656 if (phone.getEmergencyNumberTracker() != null
6657 && phone.getEmergencyNumberTracker() != null) {
6658 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6659 number, exactMatch)) {
6660 return true;
sqian03bca152018-12-05 18:48:28 -08006661 }
6662 }
sqian03bca152018-12-05 18:48:28 -08006663 }
6664 return false;
6665 } finally {
6666 Binder.restoreCallingIdentity(identity);
6667 }
6668 }
6669
sqian9d4df8b2019-01-15 18:32:07 -08006670 /**
6671 * Update emergency number list for test mode.
6672 */
6673 @Override
6674 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6675 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6676 "updateEmergencyNumberListTestMode");
6677
6678 final long identity = Binder.clearCallingIdentity();
6679 try {
6680 for (Phone phone: PhoneFactory.getPhones()) {
6681 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6682 if (tracker != null) {
6683 tracker.executeEmergencyNumberTestModeCommand(action, num);
6684 }
6685 }
6686 } finally {
6687 Binder.restoreCallingIdentity(identity);
6688 }
6689 }
6690
6691 /**
6692 * Get the full emergency number list for test mode.
6693 */
6694 @Override
6695 public List<String> getEmergencyNumberListTestMode() {
6696 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6697 "getEmergencyNumberListTestMode");
6698
6699 final long identity = Binder.clearCallingIdentity();
6700 try {
6701 Set<String> emergencyNumbers = new HashSet<>();
6702 for (Phone phone: PhoneFactory.getPhones()) {
6703 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6704 if (tracker != null) {
6705 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6706 emergencyNumbers.add(num.getNumber());
6707 }
6708 }
6709 }
6710 return new ArrayList<>(emergencyNumbers);
6711 } finally {
6712 Binder.restoreCallingIdentity(identity);
6713 }
6714 }
6715
sqian04b86072018-11-07 14:02:21 -08006716 @Override
chen xu7ee67862018-10-30 22:27:10 -07006717 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6718 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6719 Phone phone = getPhone(subId);
6720 if (phone == null) {
6721 return null;
6722 }
6723 final long identity = Binder.clearCallingIdentity();
6724 try {
6725 UiccProfile profile = UiccController.getInstance()
6726 .getUiccProfileForPhone(phone.getPhoneId());
6727 if (profile != null) {
6728 return profile.getCertsFromCarrierPrivilegeAccessRules();
6729 }
6730 } finally {
6731 Binder.restoreCallingIdentity(identity);
6732 }
6733 return null;
6734 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006735
6736 /**
6737 * Enable or disable a modem stack.
6738 */
6739 @Override
6740 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6741 enforceModifyPermission();
6742
6743 final long identity = Binder.clearCallingIdentity();
6744 try {
6745 Phone phone = PhoneFactory.getPhone(slotIndex);
6746 if (phone == null) {
6747 return false;
6748 } else {
6749 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6750 }
6751 } finally {
6752 Binder.restoreCallingIdentity(identity);
6753 }
6754 }
Micheled3107c52018-12-21 15:00:11 -08006755
6756 @Override
Michele2fb0f222019-03-19 14:58:42 -07006757 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006758 enforceModifyPermission();
6759
6760 final long identity = Binder.clearCallingIdentity();
6761 try {
6762 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006763 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006764 .commit();
6765 } finally {
6766 Binder.restoreCallingIdentity(identity);
6767 }
6768 }
6769
6770 @Override
Michele2fb0f222019-03-19 14:58:42 -07006771 @TelephonyManager.IsMultiSimSupportedResult
6772 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006773 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006774 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6775 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006776 }
Micheled3107c52018-12-21 15:00:11 -08006777
6778 final long identity = Binder.clearCallingIdentity();
6779 try {
Michele2fb0f222019-03-19 14:58:42 -07006780 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006781 } finally {
6782 Binder.restoreCallingIdentity(identity);
6783 }
6784 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006785
Michele2fb0f222019-03-19 14:58:42 -07006786 @TelephonyManager.IsMultiSimSupportedResult
6787 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006788 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6789 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6790 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006791 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6792 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006793 }
6794 // Check if the hardware supports multisim functionality. If usage of multisim is not
6795 // supported by the modem, indicate that it is restricted.
6796 PhoneCapability staticCapability =
6797 mPhoneConfigurationManager.getStaticPhoneCapability();
6798 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006799 loge("isMultiSimSupportedInternal: no static configuration available");
6800 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006801 }
6802 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006803 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6804 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006805 }
6806 // Check if support of multiple SIMs is restricted by carrier
6807 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006808 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006809 }
6810
Michele2fb0f222019-03-19 14:58:42 -07006811 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006812 }
6813
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006814 /**
6815 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006816 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6817 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6818 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006819 * @param numOfSims number of active sims we want to switch to
6820 */
6821 @Override
6822 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006823 if (numOfSims == 1) {
6824 enforceModifyPermission();
6825 } else {
6826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6827 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6828 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006829 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006830
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006831 try {
Michele30b57b22019-03-01 12:01:14 -08006832 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006833 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006834 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6835 return;
6836 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006837 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6838 } finally {
6839 Binder.restoreCallingIdentity(identity);
6840 }
6841 }
6842
6843 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006844 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006845 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006846 */
6847 @Override
6848 public boolean isRebootRequiredForModemConfigChange() {
6849 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6850 final long identity = Binder.clearCallingIdentity();
6851 try {
6852 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6853 } finally {
6854 Binder.restoreCallingIdentity(identity);
6855 }
6856 }
6857
Pengquan Meng92d253b2019-02-06 11:12:53 -08006858 private void updateModemStateMetrics() {
6859 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6860 // TODO: check the state for each modem if the api is ready.
6861 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6862 }
6863
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006864 @Override
6865 public int[] getSlotsMapping() {
6866 enforceReadPrivilegedPermission("getSlotsMapping");
6867
6868 final long identity = Binder.clearCallingIdentity();
6869 try {
6870 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6871 // All logical slots should have a mapping to a physical slot.
6872 int[] logicalSlotsMapping = new int[phoneCount];
6873 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6874 for (int i = 0; i < slotInfos.length; i++) {
6875 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6876 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6877 }
6878 }
6879 return logicalSlotsMapping;
6880 } finally {
6881 Binder.restoreCallingIdentity(identity);
6882 }
6883 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006884
6885 /**
6886 * Get the IRadio HAL Version
6887 */
6888 @Override
6889 public int getRadioHalVersion() {
6890 Phone phone = getDefaultPhone();
6891 if (phone == null) return -1;
6892 HalVersion hv = phone.getHalVersion();
6893 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6894 return hv.major * 100 + hv.minor;
6895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006896}