blob: 1631b64fd792ac14e5080fe3fdfea134da5eb5d5 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
38import android.os.Bundle;
39import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Looper;
42import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070044import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080045import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070046import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070048import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070049import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070051import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070052import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070053import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080054import android.provider.Settings;
Santos Cordon7a1885b2015-02-03 11:15:19 -080055import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080056import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070057import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070058import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080059import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070061import android.telephony.CellInfoGsm;
62import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070063import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070064import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070065import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070066import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080067import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070068import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080069import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070070import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080071import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070072import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080075import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070076import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080077import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070079import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080081import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000082import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070083import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070084import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070085import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080086import android.telephony.data.ApnSetting;
87import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070088import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080089import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -070090import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080091import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070092import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080093import android.telephony.ims.aidl.IImsMmTelFeature;
94import android.telephony.ims.aidl.IImsRcsFeature;
95import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -070096import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080097import android.telephony.ims.feature.MmTelFeature;
98import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080099import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800101import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800103import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800104import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800105
Brad Ebinger35c841c2018-10-01 10:40:55 -0700106import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700107import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800108import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700109import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700110import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700111import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800112import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700113import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700114import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import com.android.internal.telephony.DefaultPhoneNotifier;
Hall Liud892bec2018-11-30 14:51:45 -0800116import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800118import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700119import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100120import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700121import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700122import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700124import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800125import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700126import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700127import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700128import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700129import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700130import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700131import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700132import com.android.internal.telephony.SmsApplication;
133import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800134import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800135import com.android.internal.telephony.TelephonyPermissions;
sqianf4ca7ed2019-01-15 18:32:07 -0800136import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700137import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700138import com.android.internal.telephony.uicc.IccIoResult;
139import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800140import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700141import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800142import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700143import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800144import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000145import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700146import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800147import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700148import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800149import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700150import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700151import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800152
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700153import java.io.FileDescriptor;
154import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800155import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800157import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700158import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800159import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800160import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800161import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100162import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800163import java.util.Map;
sqianf4ca7ed2019-01-15 18:32:07 -0800164import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165
166/**
167 * Implementation of the ITelephony interface.
168 */
Santos Cordon117fee72014-05-16 17:56:12 -0700169public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170 private static final String LOG_TAG = "PhoneInterfaceManager";
171 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
172 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800173 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174
175 // Message codes used with mMainThreadHandler
176 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700177 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
178 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700179 private static final int CMD_OPEN_CHANNEL = 9;
180 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
181 private static final int CMD_CLOSE_CHANNEL = 11;
182 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800183 private static final int CMD_NV_READ_ITEM = 13;
184 private static final int EVENT_NV_READ_ITEM_DONE = 14;
185 private static final int CMD_NV_WRITE_ITEM = 15;
186 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
187 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
188 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700189 private static final int CMD_RESET_MODEM_CONFIG = 19;
190 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800191 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
192 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
193 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
194 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800195 private static final int CMD_SEND_ENVELOPE = 25;
196 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000197 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
198 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700199 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
200 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
201 private static final int CMD_EXCHANGE_SIM_IO = 31;
202 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800203 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
204 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700205 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
206 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700207 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
208 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700209 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
210 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
211 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
212 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700213 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
214 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
215 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
216 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700217 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800218 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
219 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000220 private static final int CMD_SWITCH_SLOTS = 50;
221 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700222 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
223 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
224 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
225 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
226 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
227 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
228 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
229 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700230 private static final int CMD_GET_ALL_CELL_INFO = 60;
231 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
232 private static final int CMD_GET_CELL_LOCATION = 62;
233 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700234 private static final int CMD_MODEM_REBOOT = 64;
235 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700236 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
237 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800238 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
239 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800241 // Parameters of select command.
242 private static final int SELECT_COMMAND = 0xA4;
243 private static final int SELECT_P1 = 0x04;
244 private static final int SELECT_P2 = 0;
245 private static final int SELECT_P3 = 0x10;
246
Pengquan Meng85728fb2018-03-12 16:31:21 -0700247 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
248 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
249 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
250
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251 /** The singleton instance. */
252 private static PhoneInterfaceManager sInstance;
253
Wink Saville3ab207e2014-11-20 13:07:20 -0800254 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800255 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700256 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800257 private AppOpsManager mAppOps;
258 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800259 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800260 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700261 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262
Derek Tan97ebb422014-09-05 16:55:38 -0700263 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
264 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800265 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800266 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700267
Michelecea4cf22018-12-21 15:00:11 -0800268 // String to store multi SIM allowed
269 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
270
Derek Tan740e1672017-06-27 14:56:27 -0700271 // The AID of ISD-R.
272 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
273
yinxub1bed742017-04-17 11:45:04 -0700274 private NetworkScanRequestTracker mNetworkScanRequestTracker;
275
David Kelly5e06a7f2018-03-12 14:10:59 +0000276 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
277 private static final int MANUFACTURER_CODE_LENGTH = 8;
278
Derek Tan89e89d42014-07-08 17:00:10 -0700279 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700280 * A request object to use for transmitting data to an ICC.
281 */
282 private static final class IccAPDUArgument {
283 public int channel, cla, command, p1, p2, p3;
284 public String data;
285
286 public IccAPDUArgument(int channel, int cla, int command,
287 int p1, int p2, int p3, String data) {
288 this.channel = channel;
289 this.cla = cla;
290 this.command = command;
291 this.p1 = p1;
292 this.p2 = p2;
293 this.p3 = p3;
294 this.data = data;
295 }
296 }
297
298 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700299 * A request object to use for transmitting data to an ICC.
300 */
301 private static final class ManualNetworkSelectionArgument {
302 public OperatorInfo operatorInfo;
303 public boolean persistSelection;
304
305 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
306 this.operatorInfo = operatorInfo;
307 this.persistSelection = persistSelection;
308 }
309 }
310
311 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
313 * request after sending. The main thread will notify the request when it is complete.
314 */
315 private static final class MainThreadRequest {
316 /** The argument to use for the request */
317 public Object argument;
318 /** The result of the request that is run on the main thread */
319 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800320 // The subscriber id that this request applies to. Defaults to
321 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
322 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700323
Nathan Harold92bed182018-10-12 18:16:49 -0700324 // In cases where subId is unavailable, the caller needs to specify the phone.
325 public Phone phone;
326
vagdeviaf9a5b92018-08-15 16:01:53 -0700327 public WorkSource workSource;
328
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 public MainThreadRequest(Object argument) {
330 this.argument = argument;
331 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800332
Nathan Harold92bed182018-10-12 18:16:49 -0700333 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
334 this.argument = argument;
335 if (phone != null) {
336 this.phone = phone;
337 }
338 this.workSource = workSource;
339 }
340
vagdeviaf9a5b92018-08-15 16:01:53 -0700341 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800342 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800343 if (subId != null) {
344 this.subId = subId;
345 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700346 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 }
349
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800350 private static final class IncomingThirdPartyCallArgs {
351 public final ComponentName component;
352 public final String callId;
353 public final String callerDisplayName;
354
355 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
356 String callerDisplayName) {
357 this.component = component;
358 this.callId = callId;
359 this.callerDisplayName = callerDisplayName;
360 }
361 }
362
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 /**
364 * A handler that processes messages on the main thread in the phone process. Since many
365 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
366 * inbound binder threads to the main thread in the phone process. The Binder thread
367 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
368 * on, which will be notified when the operation completes and will contain the result of the
369 * request.
370 *
371 * <p>If a MainThreadRequest object is provided in the msg.obj field,
372 * note that request.result must be set to something non-null for the calling thread to
373 * unblock.
374 */
375 private final class MainThreadHandler extends Handler {
376 @Override
377 public void handleMessage(Message msg) {
378 MainThreadRequest request;
379 Message onCompleted;
380 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800381 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700382 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800383 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
385 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700386 case CMD_HANDLE_USSD_REQUEST: {
387 request = (MainThreadRequest) msg.obj;
388 final Phone phone = getPhoneFromRequest(request);
389 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
390 String ussdRequest = ussdObject.first;
391 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700392
Pengquan Menga1bb6272018-09-06 09:59:22 -0700393 if (!isUssdApiAllowed(request.subId)) {
394 // Carrier does not support use of this API, return failure.
395 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
396 UssdResponse response = new UssdResponse(ussdRequest, null);
397 Bundle returnData = new Bundle();
398 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
399 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700400
Pengquan Menga1bb6272018-09-06 09:59:22 -0700401 request.result = true;
402 notifyRequester(request);
403 return;
404 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700405
Pengquan Menga1bb6272018-09-06 09:59:22 -0700406 try {
407 request.result = phone != null
408 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
409 } catch (CallStateException cse) {
410 request.result = false;
411 }
412 // Wake up the requesting thread
413 notifyRequester(request);
414 break;
pkanwar32d516d2016-10-14 19:37:38 -0700415 }
416
Yorke Lee716f67e2015-06-17 15:39:16 -0700417 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700419 final Phone phone = getPhoneFromRequest(request);
420 request.result = phone != null ?
421 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
422 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700424 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700430 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800431 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700432 if (uiccCard == null) {
433 loge("iccTransmitApduLogicalChannel: No UICC");
434 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700435 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700436 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
438 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700439 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 iccArgument.channel, iccArgument.cla, iccArgument.command,
441 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700443 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 break;
445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 ar = (AsyncResult) msg.obj;
448 request = (MainThreadRequest) ar.userObj;
449 if (ar.exception == null && ar.result != null) {
450 request.result = ar.result;
451 } else {
452 request.result = new IccIoResult(0x6F, 0, (byte[])null);
453 if (ar.result == null) {
454 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800455 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800457 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700458 } else {
459 loge("iccTransmitApduLogicalChannel: Unknown exception");
460 }
461 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700462 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 break;
464
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
466 request = (MainThreadRequest) msg.obj;
467 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800468 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700469 if (uiccCard == null) {
470 loge("iccTransmitApduBasicChannel: No UICC");
471 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700472 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700473 } else {
474 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
475 request);
476 uiccCard.iccTransmitApduBasicChannel(
477 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
478 iccArgument.p3, iccArgument.data, onCompleted);
479 }
480 break;
481
482 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
483 ar = (AsyncResult) msg.obj;
484 request = (MainThreadRequest) ar.userObj;
485 if (ar.exception == null && ar.result != null) {
486 request.result = ar.result;
487 } else {
488 request.result = new IccIoResult(0x6F, 0, (byte[])null);
489 if (ar.result == null) {
490 loge("iccTransmitApduBasicChannel: Empty response");
491 } else if (ar.exception instanceof CommandException) {
492 loge("iccTransmitApduBasicChannel: CommandException: " +
493 ar.exception);
494 } else {
495 loge("iccTransmitApduBasicChannel: Unknown exception");
496 }
497 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700498 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 break;
500
501 case CMD_EXCHANGE_SIM_IO:
502 request = (MainThreadRequest) msg.obj;
503 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800504 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 if (uiccCard == null) {
506 loge("iccExchangeSimIO: No UICC");
507 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700508 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 } else {
510 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
511 request);
512 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
513 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
514 iccArgument.data, onCompleted);
515 }
516 break;
517
518 case EVENT_EXCHANGE_SIM_IO_DONE:
519 ar = (AsyncResult) msg.obj;
520 request = (MainThreadRequest) ar.userObj;
521 if (ar.exception == null && ar.result != null) {
522 request.result = ar.result;
523 } else {
524 request.result = new IccIoResult(0x6f, 0, (byte[])null);
525 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 break;
528
Derek Tan4d5e5c12014-02-04 11:54:58 -0800529 case CMD_SEND_ENVELOPE:
530 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800531 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700532 if (uiccCard == null) {
533 loge("sendEnvelopeWithStatus: No UICC");
534 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700535 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700536 } else {
537 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
538 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
539 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800540 break;
541
542 case EVENT_SEND_ENVELOPE_DONE:
543 ar = (AsyncResult) msg.obj;
544 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700545 if (ar.exception == null && ar.result != null) {
546 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700548 request.result = new IccIoResult(0x6F, 0, (byte[])null);
549 if (ar.result == null) {
550 loge("sendEnvelopeWithStatus: Empty response");
551 } else if (ar.exception instanceof CommandException) {
552 loge("sendEnvelopeWithStatus: CommandException: " +
553 ar.exception);
554 } else {
555 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
556 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800557 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800559 break;
560
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 case CMD_OPEN_CHANNEL:
562 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800564 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 if (uiccCard == null) {
566 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800567 request.result = new IccOpenLogicalChannelResponse(-1,
568 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800572 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
573 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700574 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 break;
576
577 case EVENT_OPEN_CHANNEL_DONE:
578 ar = (AsyncResult) msg.obj;
579 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700580 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 int[] result = (int[]) ar.result;
583 int channelId = result[0];
584 byte[] selectResponse = null;
585 if (result.length > 1) {
586 selectResponse = new byte[result.length - 1];
587 for (int i = 1; i < result.length; ++i) {
588 selectResponse[i - 1] = (byte) result[i];
589 }
590 }
591 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700592 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 if (ar.result == null) {
595 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 if (ar.exception != null) {
598 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
599 }
600
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700601 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700602 if (ar.exception instanceof CommandException) {
603 CommandException.Error error =
604 ((CommandException) (ar.exception)).getCommandError();
605 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700606 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700607 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700608 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 }
610 }
611 openChannelResp = new IccOpenLogicalChannelResponse(
612 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700614 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 break;
617
618 case CMD_CLOSE_CHANNEL:
619 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800620 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700621 if (uiccCard == null) {
622 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900623 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700625 } else {
626 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
627 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
628 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 break;
630
631 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800632 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
633 break;
634
635 case CMD_NV_READ_ITEM:
636 request = (MainThreadRequest) msg.obj;
637 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800638 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
639 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800640 break;
641
642 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 ar = (AsyncResult) msg.obj;
644 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800645 if (ar.exception == null && ar.result != null) {
646 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800648 request.result = "";
649 if (ar.result == null) {
650 loge("nvReadItem: Empty response");
651 } else if (ar.exception instanceof CommandException) {
652 loge("nvReadItem: CommandException: " +
653 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800655 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 }
657 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 break;
660
Jake Hambye994d462014-02-03 13:10:13 -0800661 case CMD_NV_WRITE_ITEM:
662 request = (MainThreadRequest) msg.obj;
663 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
664 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800665 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700666 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800667 break;
668
669 case EVENT_NV_WRITE_ITEM_DONE:
670 handleNullReturnEvent(msg, "nvWriteItem");
671 break;
672
673 case CMD_NV_WRITE_CDMA_PRL:
674 request = (MainThreadRequest) msg.obj;
675 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800676 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800677 break;
678
679 case EVENT_NV_WRITE_CDMA_PRL_DONE:
680 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
681 break;
682
chen xu6dac5ab2018-10-26 17:39:23 -0700683 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800684 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700685 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800686 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800687 break;
688
chen xu6dac5ab2018-10-26 17:39:23 -0700689 case EVENT_RESET_MODEM_CONFIG_DONE:
690 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800691 break;
692
Jake Hamby7c27be32014-03-03 13:25:59 -0800693 case CMD_GET_PREFERRED_NETWORK_TYPE:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700696 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800697 break;
698
699 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
700 ar = (AsyncResult) msg.obj;
701 request = (MainThreadRequest) ar.userObj;
702 if (ar.exception == null && ar.result != null) {
703 request.result = ar.result; // Integer
704 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800705 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800706 if (ar.result == null) {
707 loge("getPreferredNetworkType: Empty response");
708 } else if (ar.exception instanceof CommandException) {
709 loge("getPreferredNetworkType: CommandException: " +
710 ar.exception);
711 } else {
712 loge("getPreferredNetworkType: Unknown exception");
713 }
714 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700715 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800716 break;
717
718 case CMD_SET_PREFERRED_NETWORK_TYPE:
719 request = (MainThreadRequest) msg.obj;
720 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
721 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700722 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 break;
724
725 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
726 handleNullReturnEvent(msg, "setPreferredNetworkType");
727 break;
728
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000729 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
730 request = (MainThreadRequest)msg.obj;
731 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800732 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000733 break;
734
735 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
736 ar = (AsyncResult)msg.obj;
737 request = (MainThreadRequest)ar.userObj;
738 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700739 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000740 break;
741
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800742 case CMD_SET_VOICEMAIL_NUMBER:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
745 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800746 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
747 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800748 break;
749
750 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
751 handleNullReturnEvent(msg, "setVoicemailNumber");
752 break;
753
Stuart Scott54788802015-03-30 13:18:01 -0700754 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
757 request);
758 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
759 break;
760
761 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
762 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
763 break;
764
Shishir Agrawal302c8692015-06-19 13:49:39 -0700765 case CMD_PERFORM_NETWORK_SCAN:
766 request = (MainThreadRequest) msg.obj;
767 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
768 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
769 break;
770
771 case EVENT_PERFORM_NETWORK_SCAN_DONE:
772 ar = (AsyncResult) msg.obj;
773 request = (MainThreadRequest) ar.userObj;
774 CellNetworkScanResult cellScanResult;
775 if (ar.exception == null && ar.result != null) {
776 cellScanResult = new CellNetworkScanResult(
777 CellNetworkScanResult.STATUS_SUCCESS,
778 (List<OperatorInfo>) ar.result);
779 } else {
780 if (ar.result == null) {
781 loge("getCellNetworkScanResults: Empty response");
782 }
783 if (ar.exception != null) {
784 loge("getCellNetworkScanResults: Exception: " + ar.exception);
785 }
786 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
787 if (ar.exception instanceof CommandException) {
788 CommandException.Error error =
789 ((CommandException) (ar.exception)).getCommandError();
790 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
791 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
792 } else if (error == CommandException.Error.GENERIC_FAILURE) {
793 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
794 }
795 }
796 cellScanResult = new CellNetworkScanResult(errorCode, null);
797 }
798 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700799 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700800 break;
801
802 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
803 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700804 ManualNetworkSelectionArgument selArg =
805 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700806 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
807 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700808 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
809 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700810 break;
811
812 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700813 ar = (AsyncResult) msg.obj;
814 request = (MainThreadRequest) ar.userObj;
815 if (ar.exception == null) {
816 request.result = true;
817 } else {
818 request.result = false;
819 loge("setNetworkSelectionModeManual " + ar.exception);
820 }
821 notifyRequester(request);
822 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700823 break;
824
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700825 case CMD_GET_MODEM_ACTIVITY_INFO:
826 request = (MainThreadRequest) msg.obj;
827 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800828 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700829 break;
830
831 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
832 ar = (AsyncResult) msg.obj;
833 request = (MainThreadRequest) ar.userObj;
834 if (ar.exception == null && ar.result != null) {
835 request.result = ar.result;
836 } else {
837 if (ar.result == null) {
838 loge("queryModemActivityInfo: Empty response");
839 } else if (ar.exception instanceof CommandException) {
840 loge("queryModemActivityInfo: CommandException: " +
841 ar.exception);
842 } else {
843 loge("queryModemActivityInfo: Unknown exception");
844 }
845 }
Amit Mahajand4766222016-01-28 15:28:28 -0800846 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
847 if (request.result == null) {
848 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
849 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700850 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700851 break;
852
Meng Wang1a7c35a2016-05-05 20:56:15 -0700853 case CMD_SET_ALLOWED_CARRIERS:
854 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800855 CarrierRestrictionRules argument =
856 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700857 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800858 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700859 break;
860
861 case EVENT_SET_ALLOWED_CARRIERS_DONE:
862 ar = (AsyncResult) msg.obj;
863 request = (MainThreadRequest) ar.userObj;
864 if (ar.exception == null && ar.result != null) {
865 request.result = ar.result;
866 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800867 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
868 if (ar.exception instanceof CommandException) {
869 loge("setAllowedCarriers: CommandException: " + ar.exception);
870 CommandException.Error error =
871 ((CommandException) (ar.exception)).getCommandError();
872 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
873 request.result =
874 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
875 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700876 } else {
877 loge("setAllowedCarriers: Unknown exception");
878 }
879 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700880 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700881 break;
882
883 case CMD_GET_ALLOWED_CARRIERS:
884 request = (MainThreadRequest) msg.obj;
885 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800886 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700887 break;
888
889 case EVENT_GET_ALLOWED_CARRIERS_DONE:
890 ar = (AsyncResult) msg.obj;
891 request = (MainThreadRequest) ar.userObj;
892 if (ar.exception == null && ar.result != null) {
893 request.result = ar.result;
894 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800895 request.result = new IllegalStateException(
896 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700897 if (ar.result == null) {
898 loge("getAllowedCarriers: Empty response");
899 } else if (ar.exception instanceof CommandException) {
900 loge("getAllowedCarriers: CommandException: " +
901 ar.exception);
902 } else {
903 loge("getAllowedCarriers: Unknown exception");
904 }
905 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700906 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700907 break;
908
Nathan Haroldb3014052017-01-25 15:57:32 -0800909 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result;
914 } else {
915 request.result = new IllegalArgumentException(
916 "Failed to retrieve Forbidden Plmns");
917 if (ar.result == null) {
918 loge("getForbiddenPlmns: Empty response");
919 } else {
920 loge("getForbiddenPlmns: Unknown exception");
921 }
922 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700923 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800924 break;
925
926 case CMD_GET_FORBIDDEN_PLMNS:
927 request = (MainThreadRequest) msg.obj;
928 uiccCard = getUiccCardFromRequest(request);
929 if (uiccCard == null) {
930 loge("getForbiddenPlmns() UiccCard is null");
931 request.result = new IllegalArgumentException(
932 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700933 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800934 break;
935 }
936 Integer appType = (Integer) request.argument;
937 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
938 if (uiccApp == null) {
939 loge("getForbiddenPlmns() no app with specified type -- "
940 + appType);
941 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700942 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800943 break;
944 } else {
945 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
946 + " specified type -- " + appType);
947 }
948 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
949 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
950 onCompleted);
951 break;
952
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000953 case CMD_SWITCH_SLOTS:
954 request = (MainThreadRequest) msg.obj;
955 int[] physicalSlots = (int[]) request.argument;
956 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
957 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
958 break;
959
960 case EVENT_SWITCH_SLOTS_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700964 notifyRequester(request);
965 break;
966 case CMD_GET_NETWORK_SELECTION_MODE:
967 request = (MainThreadRequest) msg.obj;
968 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
969 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
970 break;
971
972 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 if (ar.exception != null) {
976 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
977 } else {
978 int mode = ((int[]) ar.result)[0];
979 if (mode == 0) {
980 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
981 } else {
982 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
983 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000984 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700985 notifyRequester(request);
986 break;
987 case CMD_GET_CDMA_ROAMING_MODE:
988 request = (MainThreadRequest) msg.obj;
989 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
990 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
991 break;
992 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 if (ar.exception != null) {
996 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
997 } else {
998 request.result = ((int[]) ar.result)[0];
999 }
1000 notifyRequester(request);
1001 break;
1002 case CMD_SET_CDMA_ROAMING_MODE:
1003 request = (MainThreadRequest) msg.obj;
1004 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1005 int mode = (int) request.argument;
1006 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1007 break;
1008 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
1011 request.result = ar.exception == null;
1012 notifyRequester(request);
1013 break;
1014 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1015 request = (MainThreadRequest) msg.obj;
1016 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1017 int subscriptionMode = (int) request.argument;
1018 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1019 break;
1020 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
1023 request.result = ar.exception == null;
1024 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001025 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001026 case CMD_GET_ALL_CELL_INFO:
1027 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001028 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001029 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001030 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001031 case EVENT_GET_ALL_CELL_INFO_DONE:
1032 ar = (AsyncResult) msg.obj;
1033 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001034 // If a timeout occurs, the response will be null
1035 request.result = (ar.exception == null && ar.result != null)
1036 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001037 synchronized (request) {
1038 request.notifyAll();
1039 }
1040 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001041 case CMD_REQUEST_CELL_INFO_UPDATE:
1042 request = (MainThreadRequest) msg.obj;
1043 request.phone.requestCellInfoUpdate(request.workSource,
1044 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1045 break;
1046 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1047 ar = (AsyncResult) msg.obj;
1048 request = (MainThreadRequest) ar.userObj;
1049 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1050 try {
1051 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001052 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001053 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1054 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001055 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001056 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001057 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001058 } else {
1059 // use the result as returned
1060 cb.onCellInfo((List<CellInfo>) ar.result);
1061 }
1062 } catch (RemoteException re) {
1063 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1064 }
1065 break;
1066 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001067 request = (MainThreadRequest) msg.obj;
1068 WorkSource ws = (WorkSource) request.argument;
1069 Phone phone = getPhoneFromRequest(request);
1070 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1071 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001072 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001073 ar = (AsyncResult) msg.obj;
1074 request = (MainThreadRequest) ar.userObj;
1075 if (ar.exception == null) {
1076 request.result = ar.result;
1077 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001078 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001079 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1080 ? new CdmaCellLocation() : new GsmCellLocation();
1081 }
1082
1083 synchronized (request) {
1084 request.notifyAll();
1085 }
1086 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001087 case CMD_MODEM_REBOOT:
1088 request = (MainThreadRequest) msg.obj;
1089 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001090 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001091 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001092 case EVENT_CMD_MODEM_REBOOT_DONE:
1093 handleNullReturnEvent(msg, "rebootModem");
1094 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001095 case CMD_REQUEST_ENABLE_MODEM:
1096 request = (MainThreadRequest) msg.obj;
1097 boolean enable = (boolean) request.argument;
1098 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
1099 PhoneConfigurationManager.getInstance()
1100 .enablePhone(request.phone, enable, onCompleted);
1101 break;
1102 case EVENT_ENABLE_MODEM_DONE:
1103 ar = (AsyncResult) msg.obj;
1104 request = (MainThreadRequest) ar.userObj;
1105 request.result = (ar.exception == null);
1106 notifyRequester(request);
1107 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001108 default:
1109 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1110 break;
1111 }
1112 }
Jake Hambye994d462014-02-03 13:10:13 -08001113
Pengquan Menga1bb6272018-09-06 09:59:22 -07001114 private void notifyRequester(MainThreadRequest request) {
1115 synchronized (request) {
1116 request.notifyAll();
1117 }
1118 }
1119
Jake Hambye994d462014-02-03 13:10:13 -08001120 private void handleNullReturnEvent(Message msg, String command) {
1121 AsyncResult ar = (AsyncResult) msg.obj;
1122 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1123 if (ar.exception == null) {
1124 request.result = true;
1125 } else {
1126 request.result = false;
1127 if (ar.exception instanceof CommandException) {
1128 loge(command + ": CommandException: " + ar.exception);
1129 } else {
1130 loge(command + ": Unknown exception");
1131 }
1132 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001133 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001135 }
1136
1137 /**
1138 * Posts the specified command to be executed on the main thread,
1139 * waits for the request to complete, and returns the result.
1140 * @see #sendRequestAsync
1141 */
1142 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001143 return sendRequest(
1144 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001145 }
1146
1147 /**
1148 * Posts the specified command to be executed on the main thread,
1149 * waits for the request to complete, and returns the result.
1150 * @see #sendRequestAsync
1151 */
1152 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1153 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001154 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001155 }
1156
1157 /**
1158 * Posts the specified command to be executed on the main thread,
1159 * waits for the request to complete, and returns the result.
1160 * @see #sendRequestAsync
1161 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001162 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001163 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001164 }
1165
1166 /**
1167 * Posts the specified command to be executed on the main thread,
1168 * waits for the request to complete, and returns the result.
1169 * @see #sendRequestAsync
1170 */
Nathan Harold92bed182018-10-12 18:16:49 -07001171 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1172 return sendRequest(command, argument, subId, null, workSource);
1173 }
1174
1175 /**
1176 * Posts the specified command to be executed on the main thread,
1177 * waits for the request to complete, and returns the result.
1178 * @see #sendRequestAsync
1179 */
1180 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1181 return sendRequest(
1182 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1183 }
1184
1185 /**
1186 * Posts the specified command to be executed on the main thread,
1187 * waits for the request to complete, and returns the result.
1188 * @see #sendRequestAsync
1189 */
1190 private Object sendRequest(
1191 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1193 throw new RuntimeException("This method will deadlock if called from the main thread.");
1194 }
1195
Nathan Harold92bed182018-10-12 18:16:49 -07001196 MainThreadRequest request = null;
1197 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1198 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1199 } else if (phone != null) {
1200 request = new MainThreadRequest(argument, phone, workSource);
1201 } else {
1202 request = new MainThreadRequest(argument, subId, workSource);
1203 }
1204
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001205 Message msg = mMainThreadHandler.obtainMessage(command, request);
1206 msg.sendToTarget();
1207
1208 // Wait for the request to complete
1209 synchronized (request) {
1210 while (request.result == null) {
1211 try {
1212 request.wait();
1213 } catch (InterruptedException e) {
1214 // Do nothing, go back and wait until the request is complete
1215 }
1216 }
1217 }
1218 return request.result;
1219 }
1220
1221 /**
1222 * Asynchronous ("fire and forget") version of sendRequest():
1223 * Posts the specified command to be executed on the main thread, and
1224 * returns immediately.
1225 * @see #sendRequest
1226 */
1227 private void sendRequestAsync(int command) {
1228 mMainThreadHandler.sendEmptyMessage(command);
1229 }
1230
1231 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001232 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001233 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001234 */
1235 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001236 sendRequestAsync(command, argument, null, null);
1237 }
1238
1239 /**
1240 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1241 * @see {@link #sendRequest(int,Object)}
1242 */
1243 private void sendRequestAsync(
1244 int command, Object argument, Phone phone, WorkSource workSource) {
1245 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001246 Message msg = mMainThreadHandler.obtainMessage(command, request);
1247 msg.sendToTarget();
1248 }
1249
1250 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001251 * Initialize the singleton PhoneInterfaceManager instance.
1252 * This is only done once, at startup, from PhoneApp.onCreate().
1253 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001254 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001255 synchronized (PhoneInterfaceManager.class) {
1256 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001257 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 } else {
1259 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1260 }
1261 return sInstance;
1262 }
1263 }
1264
1265 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001266 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001267 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001268 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001269 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001270 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1271 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001272 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001273 mTelephonySharedPreferences =
1274 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001275 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001276 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001277
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 publish();
1279 }
1280
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001281 private Phone getDefaultPhone() {
1282 Phone thePhone = getPhone(getDefaultSubscription());
1283 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1284 }
1285
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 private void publish() {
1287 if (DBG) log("publish: " + this);
1288
1289 ServiceManager.addService("phone", this);
1290 }
1291
Stuart Scott584921c2015-01-15 17:10:34 -08001292 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001293 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001294 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001295 }
1296
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001297 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1298 Phone phone = getPhoneFromRequest(request);
1299 return phone == null ? null :
1300 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1301 }
1302
Wink Saville36469e72014-06-11 15:17:00 -07001303 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001304 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001305 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307
1308 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001309 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001310 }
1311
Wink Savilleb564aae2014-10-23 10:18:09 -07001312 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 if (DBG) log("dial: " + number);
1314 // No permission check needed here: This is just a wrapper around the
1315 // ACTION_DIAL intent, which is available to any app since it puts up
1316 // the UI before it does anything.
1317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001318 final long identity = Binder.clearCallingIdentity();
1319 try {
1320 String url = createTelUrl(number);
1321 if (url == null) {
1322 return;
1323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001325 // PENDING: should we just silently fail if phone is offhook or ringing?
1326 PhoneConstants.State state = mCM.getState(subId);
1327 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1328 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1329 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1330 mApp.startActivity(intent);
1331 }
1332 } finally {
1333 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001334 }
1335 }
1336
1337 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001338 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001339 }
1340
Wink Savilleb564aae2014-10-23 10:18:09 -07001341 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 if (DBG) log("call: " + number);
1343
1344 // This is just a wrapper around the ACTION_CALL intent, but we still
1345 // need to do a permission check since we're calling startActivity()
1346 // from the context of the phone app.
1347 enforceCallPermission();
1348
1349 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1350 != AppOpsManager.MODE_ALLOWED) {
1351 return;
1352 }
1353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001354 final long identity = Binder.clearCallingIdentity();
1355 try {
1356 String url = createTelUrl(number);
1357 if (url == null) {
1358 return;
1359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001361 boolean isValid = false;
1362 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1363 if (slist != null) {
1364 for (SubscriptionInfo subInfoRecord : slist) {
1365 if (subInfoRecord.getSubscriptionId() == subId) {
1366 isValid = true;
1367 break;
1368 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001369 }
Wink Saville08874612014-08-31 19:19:58 -07001370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001371 if (!isValid) {
1372 return;
1373 }
Wink Saville08874612014-08-31 19:19:58 -07001374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001375 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1376 intent.putExtra(SUBSCRIPTION_KEY, subId);
1377 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1378 mApp.startActivity(intent);
1379 } finally {
1380 Binder.restoreCallingIdentity(identity);
1381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 }
1383
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001385 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001386 }
1387
Wink Savilleb564aae2014-10-23 10:18:09 -07001388 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001389 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001390 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1391 }
1392
1393 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001394 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001395 }
1396
Wink Savilleb564aae2014-10-23 10:18:09 -07001397 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001398 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001399 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1400 }
1401
1402 /** {@hide} */
1403 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001404 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001405 }
1406
Wink Savilleb564aae2014-10-23 10:18:09 -07001407 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001408 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001409
1410 final long identity = Binder.clearCallingIdentity();
1411 try {
1412 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1413 checkSimPin.start();
1414 return checkSimPin.unlockSim(null, pin);
1415 } finally {
1416 Binder.restoreCallingIdentity(identity);
1417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001418 }
1419
Wink Saville9de0f752013-10-22 19:04:03 -07001420 /** {@hide} */
1421 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001422 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001423 }
1424
Wink Savilleb564aae2014-10-23 10:18:09 -07001425 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001427
1428 final long identity = Binder.clearCallingIdentity();
1429 try {
1430 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1431 checkSimPuk.start();
1432 return checkSimPuk.unlockSim(puk, pin);
1433 } finally {
1434 Binder.restoreCallingIdentity(identity);
1435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001436 }
1437
1438 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001439 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440 * a synchronous one.
1441 */
1442 private static class UnlockSim extends Thread {
1443
1444 private final IccCard mSimCard;
1445
1446 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001447 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1448 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449
1450 // For replies from SimCard interface
1451 private Handler mHandler;
1452
1453 // For async handler to identify request type
1454 private static final int SUPPLY_PIN_COMPLETE = 100;
1455
1456 public UnlockSim(IccCard simCard) {
1457 mSimCard = simCard;
1458 }
1459
1460 @Override
1461 public void run() {
1462 Looper.prepare();
1463 synchronized (UnlockSim.this) {
1464 mHandler = new Handler() {
1465 @Override
1466 public void handleMessage(Message msg) {
1467 AsyncResult ar = (AsyncResult) msg.obj;
1468 switch (msg.what) {
1469 case SUPPLY_PIN_COMPLETE:
1470 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1471 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001472 mRetryCount = msg.arg1;
1473 if (ar.exception != null) {
1474 if (ar.exception instanceof CommandException &&
1475 ((CommandException)(ar.exception)).getCommandError()
1476 == CommandException.Error.PASSWORD_INCORRECT) {
1477 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1478 } else {
1479 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1480 }
1481 } else {
1482 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001484 mDone = true;
1485 UnlockSim.this.notifyAll();
1486 }
1487 break;
1488 }
1489 }
1490 };
1491 UnlockSim.this.notifyAll();
1492 }
1493 Looper.loop();
1494 }
1495
1496 /*
1497 * Use PIN or PUK to unlock SIM card
1498 *
1499 * If PUK is null, unlock SIM card with PIN
1500 *
1501 * If PUK is not null, unlock SIM card with PUK and set PIN code
1502 */
Wink Saville9de0f752013-10-22 19:04:03 -07001503 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504
1505 while (mHandler == null) {
1506 try {
1507 wait();
1508 } catch (InterruptedException e) {
1509 Thread.currentThread().interrupt();
1510 }
1511 }
1512 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1513
1514 if (puk == null) {
1515 mSimCard.supplyPin(pin, callback);
1516 } else {
1517 mSimCard.supplyPuk(puk, pin, callback);
1518 }
1519
1520 while (!mDone) {
1521 try {
1522 Log.d(LOG_TAG, "wait for done");
1523 wait();
1524 } catch (InterruptedException e) {
1525 // Restore the interrupted status
1526 Thread.currentThread().interrupt();
1527 }
1528 }
1529 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001530 int[] resultArray = new int[2];
1531 resultArray[0] = mResult;
1532 resultArray[1] = mRetryCount;
1533 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534 }
1535 }
1536
1537 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001538 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001539
1540 }
1541
Wink Savilleb564aae2014-10-23 10:18:09 -07001542 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 // No permission check needed here: this call is harmless, and it's
1544 // needed for the ServiceState.requestStateUpdate() call (which is
1545 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001546 final long identity = Binder.clearCallingIdentity();
1547 try {
1548 final Phone phone = getPhone(subId);
1549 if (phone != null) {
1550 phone.updateServiceLocation();
1551 }
1552 } finally {
1553 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 }
1556
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001557 @Override
1558 public boolean isRadioOn(String callingPackage) {
1559 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001560 }
1561
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001562 @Override
1563 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001565 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001566 return false;
1567 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001568
1569 final long identity = Binder.clearCallingIdentity();
1570 try {
1571 return isRadioOnForSubscriber(subId);
1572 } finally {
1573 Binder.restoreCallingIdentity(identity);
1574 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001575 }
1576
1577 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001578 final long identity = Binder.clearCallingIdentity();
1579 try {
1580 final Phone phone = getPhone(subId);
1581 if (phone != null) {
1582 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1583 } else {
1584 return false;
1585 }
1586 } finally {
1587 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 }
1590
1591 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001592 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593 }
Wink Saville36469e72014-06-11 15:17:00 -07001594
Wink Savilleb564aae2014-10-23 10:18:09 -07001595 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001597
1598 final long identity = Binder.clearCallingIdentity();
1599 try {
1600 final Phone phone = getPhone(subId);
1601 if (phone != null) {
1602 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1603 }
1604 } finally {
1605 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001606 }
Wink Saville36469e72014-06-11 15:17:00 -07001607 }
1608
1609 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001610 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001611 }
1612
Wink Savilleb564aae2014-10-23 10:18:09 -07001613 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001614 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001615
1616 final long identity = Binder.clearCallingIdentity();
1617 try {
1618 final Phone phone = getPhone(subId);
1619 if (phone == null) {
1620 return false;
1621 }
1622 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1623 toggleRadioOnOffForSubscriber(subId);
1624 }
1625 return true;
1626 } finally {
1627 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 }
Wink Saville36469e72014-06-11 15:17:00 -07001630
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001631 public boolean needMobileRadioShutdown() {
1632 /*
1633 * If any of the Radios are available, it will need to be
1634 * shutdown. So return true if any Radio is available.
1635 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001636 final long identity = Binder.clearCallingIdentity();
1637 try {
1638 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1639 Phone phone = PhoneFactory.getPhone(i);
1640 if (phone != null && phone.isRadioAvailable()) return true;
1641 }
1642 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1643 return false;
1644 } finally {
1645 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001646 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001647 }
1648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001649 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001650 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001651 enforceModifyPermission();
1652
1653 final long identity = Binder.clearCallingIdentity();
1654 try {
1655 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1656 logv("Shutting down Phone " + i);
1657 shutdownRadioUsingPhoneId(i);
1658 }
1659 } finally {
1660 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001661 }
1662 }
1663
1664 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001665 Phone phone = PhoneFactory.getPhone(phoneId);
1666 if (phone != null && phone.isRadioAvailable()) {
1667 phone.shutdownRadio();
1668 }
1669 }
1670
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001672 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001673
1674 final long identity = Binder.clearCallingIdentity();
1675 try {
1676 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1677 if (defaultPhone != null) {
1678 defaultPhone.setRadioPower(turnOn);
1679 return true;
1680 } else {
1681 loge("There's no default phone.");
1682 return false;
1683 }
1684 } finally {
1685 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001686 }
Wink Saville36469e72014-06-11 15:17:00 -07001687 }
1688
Wink Savilleb564aae2014-10-23 10:18:09 -07001689 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001691
1692 final long identity = Binder.clearCallingIdentity();
1693 try {
1694 final Phone phone = getPhone(subId);
1695 if (phone != null) {
1696 phone.setRadioPower(turnOn);
1697 return true;
1698 } else {
1699 return false;
1700 }
1701 } finally {
1702 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 }
1705
Wink Saville36469e72014-06-11 15:17:00 -07001706 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001707 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 public boolean enableDataConnectivity() {
1709 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001710
1711 final long identity = Binder.clearCallingIdentity();
1712 try {
1713 int subId = mSubscriptionController.getDefaultDataSubId();
1714 final Phone phone = getPhone(subId);
1715 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001716 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001717 return true;
1718 } else {
1719 return false;
1720 }
1721 } finally {
1722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 }
1725
Wink Saville36469e72014-06-11 15:17:00 -07001726 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001727 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 public boolean disableDataConnectivity() {
1729 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001730
1731 final long identity = Binder.clearCallingIdentity();
1732 try {
1733 int subId = mSubscriptionController.getDefaultDataSubId();
1734 final Phone phone = getPhone(subId);
1735 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001736 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001737 return true;
1738 } else {
1739 return false;
1740 }
1741 } finally {
1742 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 }
1745
Sanket Padawe356d7632015-06-22 14:03:32 -07001746 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001747 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001748 final long identity = Binder.clearCallingIdentity();
1749 try {
1750 final Phone phone = getPhone(subId);
1751 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001752 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001753 } else {
1754 return false;
1755 }
1756 } finally {
1757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001758 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 }
1760
1761 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001762 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001763 }
1764
pkanwarae03a6b2016-11-06 20:37:09 -08001765 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001766 enforceCallPermission();
1767
1768 final long identity = Binder.clearCallingIdentity();
1769 try {
1770 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1771 return;
1772 }
1773 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1774 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1775 } finally {
1776 Binder.restoreCallingIdentity(identity);
1777 }
pkanwar32d516d2016-10-14 19:37:38 -07001778 };
1779
Wink Savilleb564aae2014-10-23 10:18:09 -07001780 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001782
1783 final long identity = Binder.clearCallingIdentity();
1784 try {
1785 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1786 return false;
1787 }
1788 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1789 } finally {
1790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 }
1793
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001795 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001796 }
1797
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001798 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799 final long identity = Binder.clearCallingIdentity();
1800 try {
1801 Phone phone = PhoneFactory.getPhone(slotIndex);
1802 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1803 PhoneConstantConversions.convertCallState(phone.getState());
1804 } finally {
1805 Binder.restoreCallingIdentity(identity);
1806 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 }
1808
Sanket Padawe356d7632015-06-22 14:03:32 -07001809 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001811 final long identity = Binder.clearCallingIdentity();
1812 try {
1813 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1814 if (phone != null) {
1815 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1816 } else {
1817 return PhoneConstantConversions.convertDataState(
1818 PhoneConstants.DataState.DISCONNECTED);
1819 }
1820 } finally {
1821 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001822 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 }
1824
Sanket Padawe356d7632015-06-22 14:03:32 -07001825 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001827 final long identity = Binder.clearCallingIdentity();
1828 try {
1829 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1830 if (phone != null) {
1831 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1832 } else {
1833 return TelephonyManager.DATA_ACTIVITY_NONE;
1834 }
1835 } finally {
1836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 }
1839
1840 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001841 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001842 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001843 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001844 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1845 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001846 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 }
1848
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001849 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001850 final long identity = Binder.clearCallingIdentity();
1851 try {
1852 if (DBG_LOC) log("getCellLocation: is active user");
1853 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001854 int subId = mSubscriptionController.getDefaultDataSubId();
1855 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1856 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001857 return data;
1858 } finally {
1859 Binder.restoreCallingIdentity(identity);
1860 }
Svetoslav64fad262015-04-14 14:35:21 -07001861 }
1862
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001864 public String getNetworkCountryIsoForPhone(int phoneId) {
1865 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1866 // registered cell info, so return a NULL country instead.
1867 final long identity = Binder.clearCallingIdentity();
1868 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001869 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1870 // Get default phone in this case.
1871 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1872 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001873 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001874 // Todo: fix this when we can get the actual cellular network info when the device
1875 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001876 if (TelephonyManager.NETWORK_TYPE_IWLAN
1877 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1878 return "";
1879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001880 Phone phone = PhoneFactory.getPhone(phoneId);
1881 if (phone != null) {
1882 ServiceStateTracker sst = phone.getServiceStateTracker();
1883 if (sst != null) {
1884 LocaleTracker lt = sst.getLocaleTracker();
1885 if (lt != null) {
1886 return lt.getCurrentCountry();
1887 }
1888 }
1889 }
1890 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001891 } finally {
1892 Binder.restoreCallingIdentity(identity);
1893 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001894 }
1895
1896 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001898 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001899 }
1900
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001902 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 mApp.enforceCallingOrSelfPermission(
1904 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001905
1906 final long identity = Binder.clearCallingIdentity();
1907 try {
1908 final Phone phone = getPhone(subId);
1909 if (phone != null) {
1910 phone.enableLocationUpdates();
1911 }
1912 } finally {
1913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 }
1916
1917 @Override
1918 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001919 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001920 }
1921
Sanket Padawe356d7632015-06-22 14:03:32 -07001922 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001923 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 mApp.enforceCallingOrSelfPermission(
1925 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001926
1927 final long identity = Binder.clearCallingIdentity();
1928 try {
1929 final Phone phone = getPhone(subId);
1930 if (phone != null) {
1931 phone.disableLocationUpdates();
1932 }
1933 } finally {
1934 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
Nathan Harold31d7ff32018-10-15 20:20:30 -07001938 /**
1939 * Returns the target SDK version number for a given package name.
1940 *
1941 * @return target SDK if the package is found or INT_MAX.
1942 */
1943 private int getTargetSdk(String packageName) {
1944 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001945 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1946 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001947 if (ai != null) return ai.targetSdkVersion;
1948 } catch (PackageManager.NameNotFoundException unexpected) {
1949 }
1950 return Integer.MAX_VALUE;
1951 }
1952
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 @Override
1954 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001955 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1956 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001957 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1958 throw new SecurityException(
1959 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1960 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001961
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1963 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1964 return null;
1965 }
Svetoslav64fad262015-04-14 14:35:21 -07001966
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001967 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968
Nathan Haroldf180aac2018-06-01 18:43:55 -07001969 List<CellInfo> info = getAllCellInfo(callingPackage);
1970 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971
Nathan Haroldf180aac2018-06-01 18:43:55 -07001972 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1973 for (CellInfo ci : info) {
1974 if (ci instanceof CellInfoGsm) {
1975 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1976 } else if (ci instanceof CellInfoWcdma) {
1977 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1978 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001980 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 }
1982
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001983 private List<CellInfo> getCachedCellInfo() {
1984 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1985 for (Phone phone : PhoneFactory.getPhones()) {
1986 List<CellInfo> info = phone.getAllCellInfo();
1987 if (info != null) cellInfos.addAll(info);
1988 }
1989 return cellInfos;
1990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991
1992 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001993 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001994 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001995 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001996 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001997 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001998 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 }
2000
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002001 final int targetSdk = getTargetSdk(callingPackage);
2002 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2003 return getCachedCellInfo();
2004 }
2005
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002006 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002007 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002008 final long identity = Binder.clearCallingIdentity();
2009 try {
2010 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2011 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002012 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002013 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002014 if (info != null) cellInfos.addAll(info);
2015 }
2016 return cellInfos;
2017 } finally {
2018 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 }
2020 }
2021
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002022 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002023 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2024 requestCellInfoUpdateInternal(
2025 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2026 }
2027
2028 @Override
2029 public void requestCellInfoUpdateWithWorkSource(
2030 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2031 enforceModifyPermission();
2032 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2033 }
2034
2035 private void requestCellInfoUpdateInternal(
2036 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002037 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002038 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002039 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2040 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002041 return;
2042 }
2043
2044 final Phone phone = getPhone(subId);
2045 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2046
2047 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2048 }
2049
2050 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002052 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002053 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054
2055 final long identity = Binder.clearCallingIdentity();
2056 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002057 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002058 } finally {
2059 Binder.restoreCallingIdentity(identity);
2060 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002061 }
2062
Shishir Agrawala9f32182016-04-12 12:00:16 -07002063 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002064 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002065 Phone phone = PhoneFactory.getPhone(slotIndex);
2066 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002067 return null;
2068 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002069 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002070 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2071 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002072 return null;
2073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002074
2075 final long identity = Binder.clearCallingIdentity();
2076 try {
2077 return phone.getImei();
2078 } finally {
2079 Binder.restoreCallingIdentity(identity);
2080 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002081 }
2082
2083 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002084 public String getTypeAllocationCodeForSlot(int slotIndex) {
2085 Phone phone = PhoneFactory.getPhone(slotIndex);
2086 String tac = null;
2087 if (phone != null) {
2088 String imei = phone.getImei();
2089 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2090 }
2091 return tac;
2092 }
2093
2094 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002095 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002096 Phone phone = PhoneFactory.getPhone(slotIndex);
2097 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002098 return null;
2099 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002100
Jeff Davidson913390f2018-02-23 17:11:49 -08002101 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002102 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2103 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002104 return null;
2105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002106
2107 final long identity = Binder.clearCallingIdentity();
2108 try {
2109 return phone.getMeid();
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
2112 }
Jack Yu2af8d712017-03-15 17:14:14 -07002113 }
2114
2115 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002116 public String getManufacturerCodeForSlot(int slotIndex) {
2117 Phone phone = PhoneFactory.getPhone(slotIndex);
2118 String manufacturerCode = null;
2119 if (phone != null) {
2120 String meid = phone.getMeid();
2121 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2122 }
2123 return manufacturerCode;
2124 }
2125
2126 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002127 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002128 Phone phone = PhoneFactory.getPhone(slotIndex);
2129 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002130 return null;
2131 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002132 int subId = phone.getSubId();
2133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2134 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2135 return null;
2136 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002137
2138 final long identity = Binder.clearCallingIdentity();
2139 try {
2140 return phone.getDeviceSvn();
2141 } finally {
2142 Binder.restoreCallingIdentity(identity);
2143 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002144 }
2145
fionaxu43304da2017-11-27 22:51:16 -08002146 @Override
2147 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002148 final long identity = Binder.clearCallingIdentity();
2149 try {
2150 final Phone phone = getPhone(subId);
2151 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2152 } finally {
2153 Binder.restoreCallingIdentity(identity);
2154 }
fionaxu43304da2017-11-27 22:51:16 -08002155 }
2156
2157 @Override
2158 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002159 final long identity = Binder.clearCallingIdentity();
2160 try {
2161 final Phone phone = getPhone(subId);
2162 return phone == null ? null : phone.getCarrierName();
2163 } finally {
2164 Binder.restoreCallingIdentity(identity);
2165 }
fionaxu43304da2017-11-27 22:51:16 -08002166 }
2167
calvinpanffe225e2018-11-01 19:43:06 +08002168 @Override
chen xu25637222018-11-04 17:17:00 -08002169 public int getSubscriptionPreciseCarrierId(int subId) {
2170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 final Phone phone = getPhone(subId);
2173 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2174 : phone.getPreciseCarrierId();
2175 } finally {
2176 Binder.restoreCallingIdentity(identity);
2177 }
2178 }
2179
2180 @Override
2181 public String getSubscriptionPreciseCarrierName(int subId) {
2182 final long identity = Binder.clearCallingIdentity();
2183 try {
2184 final Phone phone = getPhone(subId);
2185 return phone == null ? null : phone.getPreciseCarrierName();
2186 } finally {
2187 Binder.restoreCallingIdentity(identity);
2188 }
2189 }
2190
chen xu651eec72018-11-11 19:03:44 -08002191 @Override
chen xu864e11c2018-12-06 22:10:03 -08002192 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2193 if (!isSubscriptionMccMnc) {
2194 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2195 }
chen xu651eec72018-11-11 19:03:44 -08002196 final Phone phone = PhoneFactory.getPhone(slotIndex);
2197 if (phone == null) {
2198 return TelephonyManager.UNKNOWN_CARRIER_ID;
2199 }
2200 final long identity = Binder.clearCallingIdentity();
2201 try {
2202 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2203 } finally {
2204 Binder.restoreCallingIdentity(identity);
2205 }
2206 }
2207
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208 //
2209 // Internal helper methods.
2210 //
2211
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002212 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2214 *
2215 * @throws SecurityException if the caller does not have the required permission
2216 */
2217 private void enforceModifyPermission() {
2218 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2219 }
2220
2221 /**
2222 * Make sure the caller has the CALL_PHONE permission.
2223 *
2224 * @throws SecurityException if the caller does not have the required permission
2225 */
2226 private void enforceCallPermission() {
2227 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2228 }
2229
Stuart Scott8eef64f2015-04-08 15:13:54 -07002230 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002231 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002232 "ConnectivityService");
2233 }
2234
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 private String createTelUrl(String number) {
2236 if (TextUtils.isEmpty(number)) {
2237 return null;
2238 }
2239
Jake Hambye994d462014-02-03 13:10:13 -08002240 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 }
2242
Ihab Awadf9e92732013-12-05 18:02:52 -08002243 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2245 }
2246
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002247 private static void logv(String msg) {
2248 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2249 }
2250
Ihab Awadf9e92732013-12-05 18:02:52 -08002251 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2253 }
2254
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002255 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002257 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002258 }
2259
Sanket Padawe356d7632015-06-22 14:03:32 -07002260 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002261 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002262 final long identity = Binder.clearCallingIdentity();
2263 try {
2264 final Phone phone = PhoneFactory.getPhone(slotIndex);
2265 if (phone == null) {
2266 return PhoneConstants.PHONE_TYPE_NONE;
2267 } else {
2268 return phone.getPhoneType();
2269 }
2270 } finally {
2271 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 }
2274
2275 /**
2276 * Returns the CDMA ERI icon index to display
2277 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002278 @Override
2279 public int getCdmaEriIconIndex(String callingPackage) {
2280 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002281 }
2282
Sanket Padawe356d7632015-06-22 14:03:32 -07002283 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002284 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002286 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002287 return -1;
2288 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002289
2290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 final Phone phone = getPhone(subId);
2293 if (phone != null) {
2294 return phone.getCdmaEriIconIndex();
2295 } else {
2296 return -1;
2297 }
2298 } finally {
2299 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
2303 /**
2304 * Returns the CDMA ERI icon mode,
2305 * 0 - ON
2306 * 1 - FLASHING
2307 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002308 @Override
2309 public int getCdmaEriIconMode(String callingPackage) {
2310 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002311 }
2312
Sanket Padawe356d7632015-06-22 14:03:32 -07002313 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002314 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002316 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002317 return -1;
2318 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002319
2320 final long identity = Binder.clearCallingIdentity();
2321 try {
2322 final Phone phone = getPhone(subId);
2323 if (phone != null) {
2324 return phone.getCdmaEriIconMode();
2325 } else {
2326 return -1;
2327 }
2328 } finally {
2329 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 }
2332
2333 /**
2334 * Returns the CDMA ERI text,
2335 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002336 @Override
2337 public String getCdmaEriText(String callingPackage) {
2338 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002339 }
2340
Sanket Padawe356d7632015-06-22 14:03:32 -07002341 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002342 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002344 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002345 return null;
2346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 final Phone phone = getPhone(subId);
2351 if (phone != null) {
2352 return phone.getCdmaEriText();
2353 } else {
2354 return null;
2355 }
2356 } finally {
2357 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 }
2360
2361 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002362 * Returns the CDMA MDN.
2363 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002364 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002365 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2367 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002368
2369 final long identity = Binder.clearCallingIdentity();
2370 try {
2371 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002372 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002373 return phone.getLine1Number();
2374 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002375 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002376 return null;
2377 }
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002380 }
2381 }
2382
2383 /**
2384 * Returns the CDMA MIN.
2385 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002386 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002387 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2389 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002390
2391 final long identity = Binder.clearCallingIdentity();
2392 try {
2393 final Phone phone = getPhone(subId);
2394 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2395 return phone.getCdmaMin();
2396 } else {
2397 return null;
2398 }
2399 } finally {
2400 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002401 }
2402 }
2403
Hall Liud892bec2018-11-30 14:51:45 -08002404 @Override
2405 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2406 INumberVerificationCallback callback, String callingPackage) {
2407 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2408 != PERMISSION_GRANTED) {
2409 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2410 }
2411 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2412
2413 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2414 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2415 throw new SecurityException("Calling package must be configured in the device config");
2416 }
2417
2418 if (range == null) {
2419 throw new NullPointerException("Range must be non-null");
2420 }
2421
2422 timeoutMillis = Math.min(timeoutMillis,
2423 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2424
2425 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2426 }
2427
Junda Liuca05d5d2014-08-14 22:36:34 -07002428 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 * Returns true if CDMA provisioning needs to run.
2430 */
2431 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002432 final long identity = Binder.clearCallingIdentity();
2433 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002434 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002435 } finally {
2436 Binder.restoreCallingIdentity(identity);
2437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002438 }
2439
2440 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002441 * Sets the voice mail number of a given subId.
2442 */
2443 @Override
2444 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002445 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446
2447 final long identity = Binder.clearCallingIdentity();
2448 try {
2449 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2450 new Pair<String, String>(alphaTag, number), new Integer(subId));
2451 return success;
2452 } finally {
2453 Binder.restoreCallingIdentity(identity);
2454 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002455 }
2456
Ta-wei Yen87c49842016-05-13 21:19:52 -07002457 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002458 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2459 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002460 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002461 if (!TextUtils.equals(callingPackage, systemDialer)) {
2462 throw new SecurityException("caller must be system dialer");
2463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002464
2465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2468 if (phoneAccountHandle == null) {
2469 return null;
2470 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002471 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472 } finally {
2473 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002474 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002475 }
2476
2477 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002478 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002479 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002480 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002481 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002482 return null;
2483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002485 final long identity = Binder.clearCallingIdentity();
2486 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002487 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002488 } finally {
2489 Binder.restoreCallingIdentity(identity);
2490 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002491 }
2492
2493 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002494 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2495 VisualVoicemailSmsFilterSettings settings) {
2496 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002497
2498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002501 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002502 } finally {
2503 Binder.restoreCallingIdentity(identity);
2504 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002505 }
2506
2507 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002508 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2509 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510
2511 final long identity = Binder.clearCallingIdentity();
2512 try {
2513 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002514 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002515 } finally {
2516 Binder.restoreCallingIdentity(identity);
2517 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002518 }
2519
2520 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002521 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2522 String callingPackage, int subId) {
2523 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524
2525 final long identity = Binder.clearCallingIdentity();
2526 try {
2527 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002528 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002529 } finally {
2530 Binder.restoreCallingIdentity(identity);
2531 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002532 }
2533
2534 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002535 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002536 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002537
2538 final long identity = Binder.clearCallingIdentity();
2539 try {
2540 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002541 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542 } finally {
2543 Binder.restoreCallingIdentity(identity);
2544 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002545 }
2546
2547 @Override
2548 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2549 String number, int port, String text, PendingIntent sentIntent) {
2550 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002551 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002552 enforceSendSmsPermission();
2553 // Make the calls as the phone process.
2554 final long identity = Binder.clearCallingIdentity();
2555 try {
2556 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2557 if (port == 0) {
2558 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2559 sentIntent, null, false);
2560 } else {
2561 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2562 smsManager.sendDataMessageWithSelfPermissions(number, null,
2563 (short) port, data, sentIntent, null);
2564 }
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
2567 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002568 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002569 /**
fionaxu0152e512016-11-14 13:36:14 -08002570 * Sets the voice activation state of a given subId.
2571 */
2572 @Override
2573 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2575 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002576
2577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 final Phone phone = getPhone(subId);
2580 if (phone != null) {
2581 phone.setVoiceActivationState(activationState);
2582 } else {
2583 loge("setVoiceActivationState fails with invalid subId: " + subId);
2584 }
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002587 }
2588 }
2589
2590 /**
2591 * Sets the data activation state of a given subId.
2592 */
2593 @Override
2594 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2596 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597
2598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 final Phone phone = getPhone(subId);
2601 if (phone != null) {
2602 phone.setDataActivationState(activationState);
2603 } else {
2604 loge("setVoiceActivationState fails with invalid subId: " + subId);
2605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002608 }
2609 }
2610
2611 /**
2612 * Returns the voice activation state of a given subId.
2613 */
2614 @Override
2615 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002616 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617
fionaxu0152e512016-11-14 13:36:14 -08002618 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 final long identity = Binder.clearCallingIdentity();
2620 try {
2621 if (phone != null) {
2622 return phone.getVoiceActivationState();
2623 } else {
2624 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2625 }
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002628 }
2629 }
2630
2631 /**
2632 * Returns the data activation state of a given subId.
2633 */
2634 @Override
2635 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002636 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002637
fionaxu0152e512016-11-14 13:36:14 -08002638 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 if (phone != null) {
2642 return phone.getDataActivationState();
2643 } else {
2644 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2645 }
2646 } finally {
2647 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002648 }
2649 }
2650
2651 /**
Wink Saville36469e72014-06-11 15:17:00 -07002652 * Returns the unread count of voicemails for a subId
2653 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002654 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002655 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2657 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2658 return 0;
2659 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 final long identity = Binder.clearCallingIdentity();
2661 try {
2662 final Phone phone = getPhone(subId);
2663 if (phone != null) {
2664 return phone.getVoiceMessageCount();
2665 } else {
2666 return 0;
2667 }
2668 } finally {
2669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002671 }
2672
2673 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002674 * returns true, if the device is in a state where both voice and data
2675 * are supported simultaneously. This can change based on location or network condition.
2676 */
2677 @Override
2678 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679 final long identity = Binder.clearCallingIdentity();
2680 try {
2681 final Phone phone = getPhone(subId);
2682 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
2685 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002686 }
2687
2688 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002689 * Send the dialer code if called from the current default dialer or the caller has
2690 * carrier privilege.
2691 * @param inputCode The dialer code to send
2692 */
2693 @Override
2694 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002695 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002697 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2698 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002699 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002700 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2701 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002702 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703
2704 final long identity = Binder.clearCallingIdentity();
2705 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002706 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707 } finally {
2708 Binder.restoreCallingIdentity(identity);
2709 }
fionaxu235cc5e2017-03-06 22:25:57 -08002710 }
2711
2712 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002713 * Returns the data network type.
2714 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 *
2716 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2717 */
2718 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002719 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 final Phone phone = getPhone(getDefaultSubscription());
2723 if (phone != null) {
2724 return phone.getServiceState().getDataNetworkType();
2725 } else {
2726 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2727 }
2728 } finally {
2729 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002730 }
Wink Saville36469e72014-06-11 15:17:00 -07002731 }
2732
Pengquan Menga1bb6272018-09-06 09:59:22 -07002733 @Override
2734 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002735 if (!isActiveSubscription(subId)) {
2736 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2737 }
2738
Pengquan Menga1bb6272018-09-06 09:59:22 -07002739 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2740 }
2741
Brad Ebinger35c841c2018-10-01 10:40:55 -07002742 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002743 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2744 throws RemoteException {
2745 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002746 final long token = Binder.clearCallingIdentity();
2747 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002748 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002749 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002750 .addRegistrationCallbackForSubscription(c, subId);
2751 } finally {
2752 Binder.restoreCallingIdentity(token);
2753 }
2754 }
2755
2756 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002757 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2758 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2760 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2761 }
2762 Binder.withCleanCallingIdentity(() -> {
2763 try {
2764 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002765 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002766 .removeRegistrationCallbackForSubscription(c, subId);
2767 } catch (IllegalArgumentException e) {
2768 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2769 + "is inactive, ignoring unregister.");
2770 // If the subscription is no longer active, just return, since the callback
2771 // will already have been removed internally.
2772 }
2773 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002774 }
2775
2776 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002777 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2778 throws RemoteException {
2779 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002780 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2781 final long token = Binder.clearCallingIdentity();
2782 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002783 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002784 .addCapabilitiesCallbackForSubscription(c, subId);
2785 } finally {
2786 Binder.restoreCallingIdentity(token);
2787 }
2788 }
2789
2790 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002791 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2792 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002793
2794 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2795 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2796 }
2797 Binder.withCleanCallingIdentity(() -> {
2798 try {
2799 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002800 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002801 .removeCapabilitiesCallbackForSubscription(c, subId);
2802 } catch (IllegalArgumentException e) {
2803 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2804 + "is inactive, ignoring unregister.");
2805 // If the subscription is no longer active, just return, since the callback
2806 // will already have been removed internally.
2807 }
2808 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002809 }
2810
2811 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002812 public boolean isCapable(int subId, int capability, int regTech) {
2813 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002814 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2815 final long token = Binder.clearCallingIdentity();
2816 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002817 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002818 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2819 } catch (ImsException e) {
2820 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2821 return false;
2822 } finally {
2823 Binder.restoreCallingIdentity(token);
2824 }
2825 }
2826
2827 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002828 public boolean isAvailable(int subId, int capability, int regTech) {
2829 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002830 final long token = Binder.clearCallingIdentity();
2831 try {
2832 Phone phone = getPhone(subId);
2833 if (phone == null) return false;
2834 return phone.isImsCapabilityAvailable(capability, regTech);
2835 } finally {
2836 Binder.restoreCallingIdentity(token);
2837 }
2838 }
2839
2840 @Override
2841 public boolean isAdvancedCallingSettingEnabled(int subId) {
2842 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2843 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2844 final long token = Binder.clearCallingIdentity();
2845 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002846 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002847 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2848 } finally {
2849 Binder.restoreCallingIdentity(token);
2850 }
2851 }
2852
2853 @Override
2854 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2856 "setAdvancedCallingSetting");
2857 final long identity = Binder.clearCallingIdentity();
2858 try {
2859 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002860 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002861 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
2864 }
2865 }
2866
2867 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002868 public boolean isVtSettingEnabled(int subId) {
2869 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002870 final long identity = Binder.clearCallingIdentity();
2871 try {
2872 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002873 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002874 getSlotIndexOrException(subId)).isVtEnabledByUser();
2875 } finally {
2876 Binder.restoreCallingIdentity(identity);
2877 }
2878 }
2879
2880 @Override
2881 public void setVtSetting(int subId, boolean isEnabled) {
2882 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2883 "setVtSetting");
2884 final long identity = Binder.clearCallingIdentity();
2885 try {
2886 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002887 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002888 } finally {
2889 Binder.restoreCallingIdentity(identity);
2890 }
2891 }
2892
2893 @Override
2894 public boolean isVoWiFiSettingEnabled(int subId) {
2895 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2896 final long identity = Binder.clearCallingIdentity();
2897 try {
2898 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002899 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002900 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2901 } finally {
2902 Binder.restoreCallingIdentity(identity);
2903 }
2904 }
2905
2906 @Override
2907 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2909 "setVoWiFiSetting");
2910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002913 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002914 } finally {
2915 Binder.restoreCallingIdentity(identity);
2916 }
2917 }
2918
2919 @Override
2920 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2921 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2922 final long identity = Binder.clearCallingIdentity();
2923 try {
2924 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002925 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002926 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2927 } finally {
2928 Binder.restoreCallingIdentity(identity);
2929 }
2930 }
2931
2932 @Override
2933 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2935 "setVoWiFiRoamingSetting");
2936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002939 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002940 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2941 } finally {
2942 Binder.restoreCallingIdentity(identity);
2943 }
2944 }
2945
2946 @Override
2947 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2949 "setVoWiFiNonPersistent");
2950 final long identity = Binder.clearCallingIdentity();
2951 try {
2952 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08002953 boolean isRoaming = TelephonyManager.from(
2954 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002955 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08002956 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002957 } finally {
2958 Binder.restoreCallingIdentity(identity);
2959 }
2960 }
2961
2962 @Override
2963 public int getVoWiFiModeSetting(int subId) {
2964 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002968 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002969 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2970 } finally {
2971 Binder.restoreCallingIdentity(identity);
2972 }
2973 }
2974
2975 @Override
2976 public void setVoWiFiModeSetting(int subId, int mode) {
2977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2978 "setVoWiFiModeSetting");
2979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002982 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002983 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2984 } finally {
2985 Binder.restoreCallingIdentity(identity);
2986 }
2987 }
2988
2989 @Override
2990 public int getVoWiFiRoamingModeSetting(int subId) {
2991 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002995 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002996 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2997 } finally {
2998 Binder.restoreCallingIdentity(identity);
2999 }
3000 }
3001
3002 @Override
3003 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3005 "setVoWiFiRoamingModeSetting");
3006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003009 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003010 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
3014 }
3015
3016 @Override
3017 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3019 "setRttCapabilityEnabled");
3020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003023 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003024 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
3027 }
3028 }
3029
3030 @Override
3031 public boolean isTtyOverVolteEnabled(int subId) {
3032 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003036 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003037 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
3041 }
3042
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003043 @Override
3044 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3045 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003049 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003050 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003051 } finally {
3052 Binder.restoreCallingIdentity(identity);
3053 }
3054 }
3055
3056 @Override
3057 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3058 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3059 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003060 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3061 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3062 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003063 try {
3064 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003065 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003066 .removeProvisioningCallbackForSubscription(callback, subId);
3067 } catch (IllegalArgumentException e) {
3068 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3069 + "is inactive, ignoring unregister.");
3070 // If the subscription is no longer active, just return, since the callback will already
3071 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003072 } finally {
3073 Binder.restoreCallingIdentity(identity);
3074 }
3075 }
3076
3077 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003078 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3079 boolean isProvisioned) {
3080 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3081 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3082 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3083 }
3084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3085 "setProvisioningStatusForCapability");
3086 final long identity = Binder.clearCallingIdentity();
3087 try {
3088 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3089 Phone phone = getPhone(subId);
3090 if (phone == null) {
3091 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3092 + subId);
3093 return;
3094 }
3095 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3096 return;
3097 }
3098
3099 // this capability requires provisioning, route to the correct API.
3100 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3101 switch (capability) {
3102 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3103 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3104 ims.setVolteProvisioned(isProvisioned);
3105 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3106 ims.setWfcProvisioned(isProvisioned);
3107 }
3108 break;
3109 }
3110 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3111 // There is currently no difference in VT provisioning type.
3112 ims.setVtProvisioned(isProvisioned);
3113 break;
3114 }
3115 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3116 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3117 // change the capability of the feature instead if needed.
3118 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3119 == isProvisioned) {
3120 // No change in provisioning.
3121 return;
3122 }
3123 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3124 try {
3125 ims.changeMmTelCapability(capability, tech, isProvisioned);
3126 } catch (ImsException e) {
3127 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3128 + ", Exception" + e.getMessage());
3129 }
3130 break;
3131 }
3132 default: {
3133 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3134 + capability + "', which does not require provisioning.");
3135 }
3136 }
3137
3138 } finally {
3139 Binder.restoreCallingIdentity(identity);
3140 }
3141 }
3142
3143 @Override
3144 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3145 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3146 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3147 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3148 }
3149 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3153 Phone phone = getPhone(subId);
3154 if (phone == null) {
3155 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3156 + subId);
3157 // We will fail with "true" as the provisioning status because this is the default
3158 // if we do not require provisioning.
3159 return true;
3160 }
3161
3162 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3163 return true;
3164 }
3165
3166 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3167 switch (capability) {
3168 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3169 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3170 return ims.isVolteProvisionedOnDevice();
3171 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3172 return ims.isWfcProvisionedOnDevice();
3173 }
3174 // This should never happen, since we are checking tech above to make sure it
3175 // is either LTE or IWLAN.
3176 throw new IllegalArgumentException("Invalid radio technology for voice "
3177 + "capability.");
3178 }
3179 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3180 // There is currently no difference in VT provisioning type.
3181 return ims.isVtProvisionedOnDevice();
3182 }
3183 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3184 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3185 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3186 }
3187 default: {
3188 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3189 + capability + "', which does not require provisioning.");
3190 }
3191 }
3192
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
3196 }
3197
3198 @Override
3199 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3200 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3201 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3202 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3203 }
3204 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3205 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3206 return (provisionedBits & capability) > 0;
3207 }
3208
3209 @Override
3210 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3211 boolean isProvisioned) {
3212 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3213 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3214 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3215 }
3216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3217 "setProvisioningStatusForCapability");
3218 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3219 // If the current provisioning status for capability already matches isProvisioned,
3220 // do nothing.
3221 if (((provisionedBits & capability) > 0) == isProvisioned) {
3222 return;
3223 }
3224 if (isProvisioned) {
3225 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3226 } else {
3227 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3228 }
3229 }
3230
3231 /**
3232 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3233 * technology. The bitfield should mirror the bitfield defined by
3234 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3235 */
3236 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3237 String key = getMmTelProvisioningKey(subId, tech);
3238 // Default is no capabilities are provisioned.
3239 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3240 }
3241
3242 /**
3243 * Sets the MmTel capability provisioning bitfield (defined by
3244 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3245 * technology specified.
3246 *
3247 * Note: This is a synchronous command and should not be called on UI thread.
3248 */
3249 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3250 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3251 String key = getMmTelProvisioningKey(subId, tech);
3252 editor.putInt(key, newField);
3253 editor.commit();
3254 }
3255
3256 private static String getMmTelProvisioningKey(int subId, int tech) {
3257 // resulting key is provision_ims_mmtel_{subId}_{tech}
3258 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3259 }
3260
3261 /**
3262 * Query CarrierConfig to see if the specified capability requires provisioning for the
3263 * carrier associated with the subscription id.
3264 */
3265 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3266 int capability) {
3267 CarrierConfigManager configManager = new CarrierConfigManager(context);
3268 PersistableBundle c = configManager.getConfigForSubId(subId);
3269 boolean requireUtProvisioning = c.getBoolean(
3270 // By default, this config is true (even if there is no SIM). We also check to make
3271 // sure the subscription needs provisioning here, so we do not need to check for
3272 // the no-SIM case, where we would normally shortcut this to false.
3273 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3274 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3275 false);
3276 boolean requireVoiceVtProvisioning = c.getBoolean(
3277 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3278
3279 // First check to make sure that the capability requires provisioning.
3280 switch (capability) {
3281 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3282 // intentional fallthrough
3283 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3284 if (requireVoiceVtProvisioning) {
3285 // Voice and Video requires provisioning
3286 return true;
3287 }
3288 break;
3289 }
3290 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3291 if (requireUtProvisioning) {
3292 // UT requires provisioning
3293 return true;
3294 }
3295 break;
3296 }
3297 }
3298 return false;
3299 }
3300
3301 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003302 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003303 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3304 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3305 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003306 enforceReadPrivilegedPermission("getImsProvisioningInt");
3307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003310 int slotId = getSlotIndex(subId);
3311 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3312 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3313 + subId + "' for key:" + key);
3314 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3315 }
3316 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003317 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003318 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3319 + subId + "' for key:" + key);
3320 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
3324 }
3325
3326 @Override
3327 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003328 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3329 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3330 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003331 enforceReadPrivilegedPermission("getImsProvisioningString");
3332 final long identity = Binder.clearCallingIdentity();
3333 try {
3334 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003335 int slotId = getSlotIndex(subId);
3336 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3337 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3338 + subId + "' for key:" + key);
3339 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3340 }
3341 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003342 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003343 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3344 + subId + "' for key:" + key);
3345 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003346 } finally {
3347 Binder.restoreCallingIdentity(identity);
3348 }
3349 }
3350
3351 @Override
3352 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003353 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3354 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3355 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3357 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003361 int slotId = getSlotIndex(subId);
3362 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3363 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3364 + subId + "' for key:" + key);
3365 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3366 }
3367 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003368 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003369 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3370 + "' for key:" + key);
3371 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003372 } finally {
3373 Binder.restoreCallingIdentity(identity);
3374 }
3375 }
3376
3377 @Override
3378 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003379 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3380 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3381 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3383 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003384 final long identity = Binder.clearCallingIdentity();
3385 try {
3386 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003387 int slotId = getSlotIndex(subId);
3388 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3389 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3390 + subId + "' for key:" + key);
3391 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3392 }
3393 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003394 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003395 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3396 + "' for key:" + key);
3397 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003398 } finally {
3399 Binder.restoreCallingIdentity(identity);
3400 }
3401 }
3402
Brad Ebinger35c841c2018-10-01 10:40:55 -07003403 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3404 int slotId = SubscriptionManager.getSlotIndex(subId);
3405 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3406 throw new IllegalArgumentException("Invalid Subscription Id.");
3407 }
3408 return slotId;
3409 }
3410
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003411 private int getSlotIndex(int subId) {
3412 int slotId = SubscriptionManager.getSlotIndex(subId);
3413 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3414 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3415 }
3416 return slotId;
3417 }
3418
Wink Saville36469e72014-06-11 15:17:00 -07003419 /**
3420 * Returns the network type for a subId
3421 */
3422 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003423 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003424 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003425 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003426 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3427 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 final long identity = Binder.clearCallingIdentity();
3430 try {
3431 final Phone phone = getPhone(subId);
3432 if (phone != null) {
3433 return phone.getServiceState().getDataNetworkType();
3434 } else {
3435 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3436 }
3437 } finally {
3438 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003440 }
3441
3442 /**
3443 * Returns the data network type
3444 */
3445 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003446 public int getDataNetworkType(String callingPackage) {
3447 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003448 }
3449
3450 /**
3451 * Returns the data network type for a subId
3452 */
3453 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003454 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003455 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003456 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003457 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3458 }
3459
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003460 final long identity = Binder.clearCallingIdentity();
3461 try {
3462 final Phone phone = getPhone(subId);
3463 if (phone != null) {
3464 return phone.getServiceState().getDataNetworkType();
3465 } else {
3466 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3467 }
3468 } finally {
3469 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003470 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003471 }
3472
3473 /**
Wink Saville36469e72014-06-11 15:17:00 -07003474 * Returns the Voice network type for a subId
3475 */
3476 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003477 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003478 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003479 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003480 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3481 }
3482
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003483 final long identity = Binder.clearCallingIdentity();
3484 try {
3485 final Phone phone = getPhone(subId);
3486 if (phone != null) {
3487 return phone.getServiceState().getVoiceNetworkType();
3488 } else {
3489 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3490 }
3491 } finally {
3492 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003493 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003494 }
3495
3496 /**
3497 * @return true if a ICC card is present
3498 */
3499 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003500 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003501 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3502 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003503 }
3504
3505 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003506 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003507 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003508 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003509 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003510 final long identity = Binder.clearCallingIdentity();
3511 try {
3512 final Phone phone = PhoneFactory.getPhone(slotIndex);
3513 if (phone != null) {
3514 return phone.getIccCard().hasIccCard();
3515 } else {
3516 return false;
3517 }
3518 } finally {
3519 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003521 }
3522
3523 /**
3524 * Return if the current radio is LTE on CDMA. This
3525 * is a tri-state return value as for a period of time
3526 * the mode may be unknown.
3527 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003528 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003529 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003530 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003531 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003532 @Override
3533 public int getLteOnCdmaMode(String callingPackage) {
3534 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003535 }
3536
Sanket Padawe356d7632015-06-22 14:03:32 -07003537 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003538 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003540 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003541 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3542 }
3543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 final Phone phone = getPhone(subId);
3547 if (phone == null) {
3548 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3549 } else {
3550 return phone.getLteOnCdmaMode();
3551 }
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003554 }
Wink Saville36469e72014-06-11 15:17:00 -07003555 }
3556
Wink Saville36469e72014-06-11 15:17:00 -07003557 /**
3558 * {@hide}
3559 * Returns Default subId, 0 in the case of single standby.
3560 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003561 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003562 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003563 }
3564
Shishir Agrawala9f32182016-04-12 12:00:16 -07003565 private int getSlotForDefaultSubscription() {
3566 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3567 }
3568
Wink Savilleb564aae2014-10-23 10:18:09 -07003569 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003570 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003571 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003572
Pengquan Menge92a50d2018-09-21 15:54:48 -07003573 private boolean isActiveSubscription(int subId) {
3574 return mSubscriptionController.isActiveSubId(subId);
3575 }
3576
Ihab Awadf2177b72013-11-25 13:33:23 -08003577 /**
3578 * @see android.telephony.TelephonyManager.WifiCallingChoices
3579 */
3580 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581 final long identity = Binder.clearCallingIdentity();
3582 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003583 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003584 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3585 getWhenToMakeWifiCallsDefaultPreference());
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
3588 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003589 }
3590
3591 /**
3592 * @see android.telephony.TelephonyManager.WifiCallingChoices
3593 */
3594 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595 final long identity = Binder.clearCallingIdentity();
3596 try {
3597 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003598 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003599 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3600 } finally {
3601 Binder.restoreCallingIdentity(identity);
3602 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003603 }
3604
Sailesh Nepald1e68152013-12-12 19:08:02 -08003605 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003606 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003607 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003608 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003609
Shishir Agrawal566b7612013-10-28 14:41:00 -07003610 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003611 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3612 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3614 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003615 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003616
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003617 final long identity = Binder.clearCallingIdentity();
3618 try {
3619 if (TextUtils.equals(ISDR_AID, aid)) {
3620 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003621 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3622 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003623 if (bestComponent == null
3624 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3625 loge("The calling package is not allowed to access ISD-R.");
3626 throw new SecurityException(
3627 "The calling package is not allowed to access ISD-R.");
3628 }
Derek Tan740e1672017-06-27 14:56:27 -07003629 }
Derek Tan740e1672017-06-27 14:56:27 -07003630
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003631 if (DBG) {
3632 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3633 }
3634 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3635 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3636 if (DBG) log("iccOpenLogicalChannel: " + response);
3637 return response;
3638 } finally {
3639 Binder.restoreCallingIdentity(identity);
3640 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003641 }
3642
3643 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003644 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3646 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3651 if (channel < 0) {
3652 return false;
3653 }
3654 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3655 if (DBG) log("iccCloseLogicalChannel: " + success);
3656 return success;
3657 } finally {
3658 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003659 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003660 }
3661
3662 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003663 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003664 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3666 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003667
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 if (DBG) {
3671 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3672 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3673 + p3 + " data=" + data);
3674 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003676 if (channel < 0) {
3677 return "";
3678 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003680 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3681 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3682 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003683
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003684 // Append the returned status code to the end of the response payload.
3685 String s = Integer.toHexString(
3686 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3687 if (response.payload != null) {
3688 s = IccUtils.bytesToHexString(response.payload) + s;
3689 }
3690 return s;
3691 } finally {
3692 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003693 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003694 }
Jake Hambye994d462014-02-03 13:10:13 -08003695
Evan Charltonc66da362014-05-16 14:06:40 -07003696 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003697 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3698 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3700 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003701 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003702
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3706 && TextUtils.equals(ISDR_AID, data)) {
3707 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003708 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3709 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710 if (bestComponent == null
3711 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3712 loge("The calling package is not allowed to select ISD-R.");
3713 throw new SecurityException(
3714 "The calling package is not allowed to select ISD-R.");
3715 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003716 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003718 if (DBG) {
3719 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3720 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3721 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3724 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3725 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727 // Append the returned status code to the end of the response payload.
3728 String s = Integer.toHexString(
3729 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3730 if (response.payload != null) {
3731 s = IccUtils.bytesToHexString(response.payload) + s;
3732 }
3733 return s;
3734 } finally {
3735 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003736 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003737 }
3738
3739 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003740 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003741 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3743 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003745 final long identity = Binder.clearCallingIdentity();
3746 try {
3747 if (DBG) {
3748 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3749 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3750 }
3751
3752 IccIoResult response =
3753 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3754 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3755 subId);
3756
3757 if (DBG) {
3758 log("Exchange SIM_IO [R]" + response);
3759 }
3760
3761 byte[] result = null;
3762 int length = 2;
3763 if (response.payload != null) {
3764 length = 2 + response.payload.length;
3765 result = new byte[length];
3766 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3767 } else {
3768 result = new byte[length];
3769 }
3770
3771 result[length - 1] = (byte) response.sw2;
3772 result[length - 2] = (byte) response.sw1;
3773 return result;
3774 } finally {
3775 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003776 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003777 }
3778
Nathan Haroldb3014052017-01-25 15:57:32 -08003779 /**
3780 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3781 * on a particular subscription
3782 */
sqianb6e41952018-03-12 14:54:01 -07003783 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3784 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3785 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3786 return null;
3787 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003788
3789 final long identity = Binder.clearCallingIdentity();
3790 try {
3791 if (appType != TelephonyManager.APPTYPE_USIM
3792 && appType != TelephonyManager.APPTYPE_SIM) {
3793 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3794 return null;
3795 }
3796 Object response = sendRequest(
3797 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3798 if (response instanceof String[]) {
3799 return (String[]) response;
3800 }
3801 // Response is an Exception of some kind,
3802 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003803 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804 } finally {
3805 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003806 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003807 }
3808
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003809 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003810 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3812 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3817 if (response.payload == null) {
3818 return "";
3819 }
Evan Charltonc66da362014-05-16 14:06:40 -07003820
Malcolm Chenaa4a8532018-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 s = IccUtils.bytesToHexString(response.payload) + s;
3825 return s;
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
3828 }
Evan Charltonc66da362014-05-16 14:06:40 -07003829 }
3830
Jake Hambye994d462014-02-03 13:10:13 -08003831 /**
3832 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3833 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3834 *
3835 * @param itemID the ID of the item to read
3836 * @return the NV item as a String, or null on error.
3837 */
3838 @Override
3839 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003840 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3842 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003843
3844 final long identity = Binder.clearCallingIdentity();
3845 try {
3846 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003847 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3849 return value;
3850 } finally {
3851 Binder.restoreCallingIdentity(identity);
3852 }
Jake Hambye994d462014-02-03 13:10:13 -08003853 }
3854
3855 /**
3856 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3857 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3858 *
3859 * @param itemID the ID of the item to read
3860 * @param itemValue the value to write, as a String
3861 * @return true on success; false on any failure
3862 */
3863 @Override
3864 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003865 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3867 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003868
3869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3872 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003873 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003874 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3875 return success;
3876 } finally {
3877 Binder.restoreCallingIdentity(identity);
3878 }
Jake Hambye994d462014-02-03 13:10:13 -08003879 }
3880
3881 /**
3882 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3883 * Used for device configuration by some CDMA operators.
3884 *
3885 * @param preferredRoamingList byte array containing the new PRL
3886 * @return true on success; false on any failure
3887 */
3888 @Override
3889 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3891 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003892
3893 final long identity = Binder.clearCallingIdentity();
3894 try {
3895 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3896 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3897 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3898 return success;
3899 } finally {
3900 Binder.restoreCallingIdentity(identity);
3901 }
Jake Hambye994d462014-02-03 13:10:13 -08003902 }
3903
3904 /**
chen xu6dac5ab2018-10-26 17:39:23 -07003905 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003906 * Used for device configuration by some CDMA operators.
3907 *
chen xu6dac5ab2018-10-26 17:39:23 -07003908 * @param slotIndex - device slot.
3909 *
Jake Hambye994d462014-02-03 13:10:13 -08003910 * @return true on success; false on any failure
3911 */
3912 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07003913 public boolean resetModemConfig(int slotIndex) {
3914 Phone phone = PhoneFactory.getPhone(slotIndex);
3915 if (phone != null) {
3916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3917 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003918
chen xu6dac5ab2018-10-26 17:39:23 -07003919 final long identity = Binder.clearCallingIdentity();
3920 try {
3921 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3922 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3923 return success;
3924 } finally {
3925 Binder.restoreCallingIdentity(identity);
3926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003927 }
chen xu6dac5ab2018-10-26 17:39:23 -07003928 return false;
3929 }
3930
3931 /**
3932 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3933 *
3934 * @param slotIndex - device slot.
3935 *
3936 * @return true on success; false on any failure
3937 */
3938 @Override
3939 public boolean rebootModem(int slotIndex) {
3940 Phone phone = PhoneFactory.getPhone(slotIndex);
3941 if (phone != null) {
3942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3943 mApp, phone.getSubId(), "rebootModem");
3944
3945 final long identity = Binder.clearCallingIdentity();
3946 try {
3947 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3948 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3949 return success;
3950 } finally {
3951 Binder.restoreCallingIdentity(identity);
3952 }
3953 }
3954 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003955 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003956
Svet Ganovb320e182015-04-16 12:30:10 -07003957 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003958 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003959 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003960 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003961 return new String[0];
3962 }
3963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003964 final long identity = Binder.clearCallingIdentity();
3965 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003966 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003967 } finally {
3968 Binder.restoreCallingIdentity(identity);
3969 }
Wink Saville36469e72014-06-11 15:17:00 -07003970 }
3971
Brad Ebinger51f743a2017-01-23 13:50:20 -08003972 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003973 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3974 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003975 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003976 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003977 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978
3979 final long identity = Binder.clearCallingIdentity();
3980 try {
3981 PhoneFactory.getImsResolver().enableIms(slotId);
3982 } finally {
3983 Binder.restoreCallingIdentity(identity);
3984 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003985 }
3986
3987 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003988 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3989 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003990 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003991 public void disableIms(int slotId) {
3992 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003993
3994 final long identity = Binder.clearCallingIdentity();
3995 try {
3996 PhoneFactory.getImsResolver().disableIms(slotId);
3997 } finally {
3998 Binder.restoreCallingIdentity(identity);
3999 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004000 }
4001
4002 /**
4003 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4004 * feature or {@link null} if the service is not available. If the feature is available, the
4005 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4006 */
4007 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004008 IImsServiceFeatureCallback callback) {
4009 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004010
4011 final long identity = Binder.clearCallingIdentity();
4012 try {
4013 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
4014 } finally {
4015 Binder.restoreCallingIdentity(identity);
4016 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004017 }
4018
4019 /**
4020 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4021 * feature during emergency calling or {@link null} if the service is not available. If the
4022 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4023 * listener for feature updates.
4024 */
4025 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4026 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004027
4028 final long identity = Binder.clearCallingIdentity();
4029 try {
4030 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
4031 } finally {
4032 Binder.restoreCallingIdentity(identity);
4033 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004034 }
4035
Brad Ebinger5f64b052017-12-14 14:26:15 -08004036 /**
4037 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
4038 * specified.
4039 */
4040 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4041 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042
4043 final long identity = Binder.clearCallingIdentity();
4044 try {
4045 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
4046 } finally {
4047 Binder.restoreCallingIdentity(identity);
4048 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004049 }
4050
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004051 /**
4052 * Returns the {@link IImsConfig} structure associated with the slotId and feature
4053 * specified.
4054 */
4055 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4056 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004057
4058 final long identity = Binder.clearCallingIdentity();
4059 try {
4060 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
4061 } finally {
4062 Binder.restoreCallingIdentity(identity);
4063 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004064 }
4065
Brad Ebinger884c07b2018-02-15 16:17:40 -08004066 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004067 * Sets the ImsService Package Name that Telephony will bind to.
4068 *
4069 * @param slotId the slot ID that the ImsService should bind for.
4070 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4071 * ImsService is the device default ImsService.
4072 * @param packageName The package name of the application that contains the ImsService to bind
4073 * to.
4074 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4075 * @hide
4076 */
4077 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004078 int[] subIds = SubscriptionManager.getSubId(slotId);
4079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4080 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4081 "setImsService");
4082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
4086 isCarrierImsService, packageName);
4087 } finally {
4088 Binder.restoreCallingIdentity(identity);
4089 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004090 }
4091
4092 /**
4093 * Return the ImsService configuration.
4094 *
4095 * @param slotId The slot that the ImsService is associated with.
4096 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4097 * the device default.
4098 * @return the package name of the ImsService configuration.
4099 */
4100 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004101 int[] subIds = SubscriptionManager.getSubId(slotId);
4102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4103 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4104 "getImsService");
4105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004106 final long identity = Binder.clearCallingIdentity();
4107 try {
4108 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
4109 isCarrierImsService);
4110 } finally {
4111 Binder.restoreCallingIdentity(identity);
4112 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004113 }
4114
Wink Saville36469e72014-06-11 15:17:00 -07004115 public void setImsRegistrationState(boolean registered) {
4116 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117
4118 final long identity = Binder.clearCallingIdentity();
4119 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004120 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121 } finally {
4122 Binder.restoreCallingIdentity(identity);
4123 }
Wink Saville36469e72014-06-11 15:17:00 -07004124 }
4125
4126 /**
Stuart Scott54788802015-03-30 13:18:01 -07004127 * Set the network selection mode to automatic.
4128 *
4129 */
4130 @Override
4131 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004132 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4133 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004134
Pengquan Menge92a50d2018-09-21 15:54:48 -07004135 if (!isActiveSubscription(subId)) {
4136 return;
4137 }
4138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004139 final long identity = Binder.clearCallingIdentity();
4140 try {
4141 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4142 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4143 } finally {
4144 Binder.restoreCallingIdentity(identity);
4145 }
Stuart Scott54788802015-03-30 13:18:01 -07004146 }
4147
Pengquan Mengea84e042018-09-20 14:57:26 -07004148 /**
4149 * Ask the radio to connect to the input network and change selection mode to manual.
4150 *
4151 * @param subId the id of the subscription.
4152 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4153 * the operator to attach to.
4154 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4155 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4156 * normal network selection next time.
4157 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004158 */
4159 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004160 public boolean setNetworkSelectionModeManual(
4161 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4163 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004164
4165 if (!isActiveSubscription(subId)) {
4166 return false;
4167 }
4168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004169 final long identity = Binder.clearCallingIdentity();
4170 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004171 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004172 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004173 if (DBG) {
4174 log("setNetworkSelectionModeManual: subId: " + subId
4175 + " operator: " + operatorInfo);
4176 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4178 } finally {
4179 Binder.restoreCallingIdentity(identity);
4180 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004181 }
4182
4183 /**
4184 * Scans for available networks.
4185 */
4186 @Override
4187 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4189 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004190
Pengquan Menga1bb6272018-09-06 09:59:22 -07004191 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004192 try {
4193 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004194 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004196 } finally {
4197 Binder.restoreCallingIdentity(identity);
4198 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004199 }
4200
4201 /**
yinxub1bed742017-04-17 11:45:04 -07004202 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004203 *
yinxub1bed742017-04-17 11:45:04 -07004204 * @param subId id of the subscription
4205 * @param request contains the radio access networks with bands/channels to scan
4206 * @param messenger callback messenger for scan results or errors
4207 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004208 * @return the id of the requested scan which can be used to stop the scan.
4209 */
4210 @Override
4211 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
4212 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4214 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215
4216 final long identity = Binder.clearCallingIdentity();
4217 try {
4218 return mNetworkScanRequestTracker.startNetworkScan(
4219 request, messenger, binder, getPhone(subId));
4220 } finally {
4221 Binder.restoreCallingIdentity(identity);
4222 }
yinxu504e1392017-04-12 16:03:22 -07004223 }
4224
4225 /**
4226 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004227 *
4228 * @param subId id of the subscription
4229 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004230 */
4231 @Override
4232 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4234 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004235
4236 final long identity = Binder.clearCallingIdentity();
4237 try {
4238 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
yinxu504e1392017-04-12 16:03:22 -07004242 }
4243
4244 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004245 * Get the calculated preferred network type.
4246 * Used for debugging incorrect network type.
4247 *
4248 * @return the preferred network type, defined in RILConstants.java.
4249 */
4250 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004251 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004252 final Phone defaultPhone = getDefaultPhone();
4253 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4254 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004255 return RILConstants.PREFERRED_NETWORK_MODE;
4256 }
4257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004258 final long identity = Binder.clearCallingIdentity();
4259 try {
4260 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004261 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004262 } finally {
4263 Binder.restoreCallingIdentity(identity);
4264 }
Junda Liu84d15a22014-07-02 11:21:04 -07004265 }
4266
4267 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004268 * Get the preferred network type.
4269 * Used for device configuration by some CDMA operators.
4270 *
4271 * @return the preferred network type, defined in RILConstants.java.
4272 */
4273 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004274 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004275 TelephonyPermissions
4276 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4277 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278
4279 final long identity = Binder.clearCallingIdentity();
4280 try {
4281 if (DBG) log("getPreferredNetworkType");
4282 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4283 int networkType = (result != null ? result[0] : -1);
4284 if (DBG) log("getPreferredNetworkType: " + networkType);
4285 return networkType;
4286 } finally {
4287 Binder.restoreCallingIdentity(identity);
4288 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004289 }
4290
4291 /**
4292 * Set the preferred network type.
4293 * Used for device configuration by some CDMA operators.
4294 *
4295 * @param networkType the preferred network type, defined in RILConstants.java.
4296 * @return true on success; false on any failure.
4297 */
4298 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004299 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4301 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004302
4303 final long identity = Binder.clearCallingIdentity();
4304 try {
4305 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4306 Boolean success = (Boolean) sendRequest(
4307 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4308 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4309 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004310 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004311 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4312 }
4313 return success;
4314 } finally {
4315 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004316 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004317 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004318
4319 /**
Junda Liu475951f2014-11-07 16:45:03 -08004320 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu3cda1cd2018-10-30 17:41:31 -07004321 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004322 * tethering.
4323 *
4324 * @return 0: Not required. 1: required. 2: Not set.
4325 * @hide
4326 */
4327 @Override
4328 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004329 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330
4331 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004332 final Phone defaultPhone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004333 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004334 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004335 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu3cda1cd2018-10-30 17:41:31 -07004336 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004337 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004338 dunRequired = 1;
4339 }
4340 return dunRequired;
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004343 }
Junda Liu475951f2014-11-07 16:45:03 -08004344 }
4345
4346 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004347 * Set mobile data enabled
4348 * Used by the user through settings etc to turn on/off mobile data
4349 *
4350 * @param enable {@code true} turn turn data on, else {@code false}
4351 */
4352 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004353 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4355 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356
4357 final long identity = Binder.clearCallingIdentity();
4358 try {
4359 int phoneId = mSubscriptionController.getPhoneId(subId);
4360 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4361 Phone phone = PhoneFactory.getPhone(phoneId);
4362 if (phone != null) {
4363 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004364 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004365 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004366 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367 }
4368 } finally {
4369 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004370 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004371 }
4372
4373 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004374 * Get the user enabled state of Mobile Data.
4375 *
4376 * TODO: remove and use isUserDataEnabled.
4377 * This can't be removed now because some vendor codes
4378 * calls through ITelephony directly while they should
4379 * use TelephonyManager.
4380 *
4381 * @return true on enabled
4382 */
4383 @Override
4384 public boolean getDataEnabled(int subId) {
4385 return isUserDataEnabled(subId);
4386 }
4387
4388 /**
4389 * Get whether mobile data is enabled per user setting.
4390 *
4391 * There are other factors deciding whether mobile data is actually enabled, but they are
4392 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004393 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004394 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004395 *
4396 * @return {@code true} if data is enabled else {@code false}
4397 */
4398 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004399 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004400 try {
4401 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4402 null);
4403 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4405 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004406 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407
4408 final long identity = Binder.clearCallingIdentity();
4409 try {
4410 int phoneId = mSubscriptionController.getPhoneId(subId);
4411 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4412 Phone phone = PhoneFactory.getPhone(phoneId);
4413 if (phone != null) {
4414 boolean retVal = phone.isUserDataEnabled();
4415 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4416 return retVal;
4417 } else {
4418 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4419 return false;
4420 }
4421 } finally {
4422 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004423 }
4424 }
4425
4426 /**
4427 * Get whether mobile data is enabled.
4428 *
4429 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4430 * whether mobile data is actually enabled.
4431 *
4432 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4433 *
4434 * @return {@code true} if data is enabled else {@code false}
4435 */
4436 @Override
4437 public boolean isDataEnabled(int subId) {
4438 try {
4439 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4440 null);
4441 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4443 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445
4446 final long identity = Binder.clearCallingIdentity();
4447 try {
4448 int phoneId = mSubscriptionController.getPhoneId(subId);
4449 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4450 Phone phone = PhoneFactory.getPhone(phoneId);
4451 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004452 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004453 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4454 return retVal;
4455 } else {
4456 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4457 return false;
4458 }
4459 } finally {
4460 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004461 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004462 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004463
4464 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004465 public int getCarrierPrivilegeStatus(int subId) {
4466 final Phone phone = getPhone(subId);
4467 if (phone == null) {
4468 loge("getCarrierPrivilegeStatus: Invalid subId");
4469 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4470 }
4471 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004472 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004473 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004474 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4475 }
4476 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004477 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004478 }
Junda Liu29340342014-07-10 15:23:27 -07004479
4480 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004481 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4482 final Phone phone = getPhone(subId);
4483 if (phone == null) {
4484 loge("getCarrierPrivilegeStatus: Invalid subId");
4485 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4486 }
4487 UiccProfile profile =
4488 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4489 if (profile == null) {
4490 loge("getCarrierPrivilegeStatus: No UICC");
4491 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4492 }
4493 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4494 }
4495
4496 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004497 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004498 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004499 if (TextUtils.isEmpty(pkgName))
4500 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004501 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004502 if (card == null) {
4503 loge("checkCarrierPrivilegesForPackage: No UICC");
4504 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4505 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004506 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4507 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004508 }
4509
4510 @Override
4511 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004512 if (TextUtils.isEmpty(pkgName))
4513 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004514 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4515 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4516 UiccCard card = UiccController.getInstance().getUiccCard(i);
4517 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004518 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004519 continue;
4520 }
4521
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004522 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004523 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4524 break;
4525 }
4526 }
4527
4528 return result;
Junda Liu29340342014-07-10 15:23:27 -07004529 }
Derek Tan89e89d42014-07-08 17:00:10 -07004530
4531 @Override
Junda Liue64de782015-04-16 17:19:16 -07004532 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4533 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4534 loge("phoneId " + phoneId + " is not valid.");
4535 return null;
4536 }
4537 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004538 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004539 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004540 return null ;
4541 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004542 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004543 }
4544
Amith Yamasani6e118872016-02-19 12:53:51 -08004545 @Override
4546 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004547 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004548 List<String> privilegedPackages = new ArrayList<>();
4549 List<PackageInfo> packages = null;
4550 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4551 UiccCard card = UiccController.getInstance().getUiccCard(i);
4552 if (card == null) {
4553 // No UICC in that slot.
4554 continue;
4555 }
4556 if (card.hasCarrierPrivilegeRules()) {
4557 if (packages == null) {
4558 // Only check packages in user 0 for now
4559 packages = pm.getInstalledPackagesAsUser(
4560 PackageManager.MATCH_DISABLED_COMPONENTS
4561 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4562 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4563 }
4564 for (int p = packages.size() - 1; p >= 0; p--) {
4565 PackageInfo pkgInfo = packages.get(p);
4566 if (pkgInfo != null && pkgInfo.packageName != null
4567 && card.getCarrierPrivilegeStatus(pkgInfo)
4568 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4569 privilegedPackages.add(pkgInfo.packageName);
4570 }
4571 }
4572 }
4573 }
4574 return privilegedPackages;
4575 }
4576
Wink Savilleb564aae2014-10-23 10:18:09 -07004577 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004578 final Phone phone = getPhone(subId);
4579 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004580 if (card == null) {
4581 loge("getIccId: No UICC");
4582 return null;
4583 }
4584 String iccId = card.getIccId();
4585 if (TextUtils.isEmpty(iccId)) {
4586 loge("getIccId: ICC ID is null or empty.");
4587 return null;
4588 }
4589 return iccId;
4590 }
4591
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004592 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004593 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4594 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004595 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4596 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004597
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004598 final long identity = Binder.clearCallingIdentity();
4599 try {
4600 final String iccId = getIccId(subId);
4601 final Phone phone = getPhone(subId);
4602 if (phone == null) {
4603 return false;
4604 }
4605 final String subscriberId = phone.getSubscriberId();
4606
4607 if (DBG_MERGE) {
4608 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4609 + subscriberId + " to " + number);
4610 }
4611
4612 if (TextUtils.isEmpty(iccId)) {
4613 return false;
4614 }
4615
4616 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4617
4618 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4619 if (alphaTag == null) {
4620 editor.remove(alphaTagPrefKey);
4621 } else {
4622 editor.putString(alphaTagPrefKey, alphaTag);
4623 }
4624
4625 // Record both the line number and IMSI for this ICCID, since we need to
4626 // track all merged IMSIs based on line number
4627 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4628 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4629 if (number == null) {
4630 editor.remove(numberPrefKey);
4631 editor.remove(subscriberPrefKey);
4632 } else {
4633 editor.putString(numberPrefKey, number);
4634 editor.putString(subscriberPrefKey, subscriberId);
4635 }
4636
4637 editor.commit();
4638 return true;
4639 } finally {
4640 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004641 }
Derek Tan7226c842014-07-02 17:42:23 -07004642 }
4643
4644 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004645 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004646 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004647 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004648 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004649 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004650 return null;
4651 }
Derek Tan97ebb422014-09-05 16:55:38 -07004652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 final long identity = Binder.clearCallingIdentity();
4654 try {
4655 String iccId = getIccId(subId);
4656 if (iccId != null) {
4657 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4658 if (DBG_MERGE) {
4659 log("getLine1NumberForDisplay returning "
4660 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4661 }
4662 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4665 return null;
4666 } finally {
4667 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004668 }
Derek Tan7226c842014-07-02 17:42:23 -07004669 }
4670
4671 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004672 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004673 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004674 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004675 return null;
4676 }
Derek Tan97ebb422014-09-05 16:55:38 -07004677
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004678 final long identity = Binder.clearCallingIdentity();
4679 try {
4680 String iccId = getIccId(subId);
4681 if (iccId != null) {
4682 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4683 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4684 }
4685 return null;
4686 } finally {
4687 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004688 }
Derek Tan7226c842014-07-02 17:42:23 -07004689 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004690
4691 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004692 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004693 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4694 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004696 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4697 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004698 return null;
4699 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004700
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004701 final long identity = Binder.clearCallingIdentity();
4702 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004703 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704 final TelephonyManager tele = TelephonyManager.from(context);
4705 final SubscriptionManager sub = SubscriptionManager.from(context);
4706
4707 // Figure out what subscribers are currently active
4708 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4709 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4710 // the process, where TelephonyManager was instantiated.
4711 // Otherwise AppOps check will fail.
4712
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004713 final int[] subIds = sub.getActiveSubscriptionIdList();
4714 for (int subId : subIds) {
4715 activeSubscriberIds.add(tele.getSubscriberId(subId));
4716 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004717
4718 // First pass, find a number override for an active subscriber
4719 String mergeNumber = null;
4720 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4721 for (String key : prefs.keySet()) {
4722 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4723 final String subscriberId = (String) prefs.get(key);
4724 if (activeSubscriberIds.contains(subscriberId)) {
4725 final String iccId = key.substring(
4726 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4727 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4728 mergeNumber = (String) prefs.get(numberKey);
4729 if (DBG_MERGE) {
4730 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4731 + " for active subscriber " + subscriberId);
4732 }
4733 if (!TextUtils.isEmpty(mergeNumber)) {
4734 break;
4735 }
4736 }
4737 }
4738 }
4739
4740 // Shortcut when no active merged subscribers
4741 if (TextUtils.isEmpty(mergeNumber)) {
4742 return null;
4743 }
4744
4745 // Second pass, find all subscribers under that line override
4746 final ArraySet<String> result = new ArraySet<>();
4747 for (String key : prefs.keySet()) {
4748 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4749 final String number = (String) prefs.get(key);
4750 if (mergeNumber.equals(number)) {
4751 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4752 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4753 final String subscriberId = (String) prefs.get(subscriberKey);
4754 if (!TextUtils.isEmpty(subscriberId)) {
4755 result.add(subscriberId);
4756 }
4757 }
4758 }
4759 }
4760
4761 final String[] resultArray = result.toArray(new String[result.size()]);
4762 Arrays.sort(resultArray);
4763 if (DBG_MERGE) {
4764 Slog.d(LOG_TAG,
4765 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4766 }
4767 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004768 } finally {
4769 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004770 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004771 }
4772
4773 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004774 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004775 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4776 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004777
4778 final long identity = Binder.clearCallingIdentity();
4779 try {
4780 final Phone phone = getPhone(subId);
4781 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4782 } finally {
4783 Binder.restoreCallingIdentity(identity);
4784 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004785 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004786
4787 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004788 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004789 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4790 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004791 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792
4793 final long identity = Binder.clearCallingIdentity();
4794 try {
4795 final Phone phone = getPhone(subId);
4796 if (phone == null) {
4797 return false;
4798 }
4799 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4800 cdmaNonRoamingList);
4801 } finally {
4802 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004803 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004804 }
4805
4806 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004807 @Deprecated
4808 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4809 enforceModifyPermission();
4810
4811 int returnValue = 0;
4812 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004813 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004814 if(result.exception == null) {
4815 if (result.result != null) {
4816 byte[] responseData = (byte[])(result.result);
4817 if(responseData.length > oemResp.length) {
4818 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4819 responseData.length + "bytes. Buffer Size is " +
4820 oemResp.length + "bytes.");
4821 }
4822 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4823 returnValue = responseData.length;
4824 }
4825 } else {
4826 CommandException ex = (CommandException) result.exception;
4827 returnValue = ex.getCommandError().ordinal();
4828 if(returnValue > 0) returnValue *= -1;
4829 }
4830 } catch (RuntimeException e) {
4831 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4832 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4833 if(returnValue > 0) returnValue *= -1;
4834 }
4835
4836 return returnValue;
4837 }
4838
4839 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004840 public void setRadioCapability(RadioAccessFamily[] rafs) {
4841 try {
4842 ProxyController.getInstance().setRadioCapability(rafs);
4843 } catch (RuntimeException e) {
4844 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4845 }
4846 }
4847
4848 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004849 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004850 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004851 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004852 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004853 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004854 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004855 final long identity = Binder.clearCallingIdentity();
4856 try {
chen xub97461a2018-10-26 14:17:57 -07004857 TelephonyPermissions
4858 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4859 mApp, phone.getSubId(), "getRadioAccessFamily");
4860 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
chen xub97461a2018-10-26 14:17:57 -07004864 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004865 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004866
4867 @Override
4868 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004869 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004870 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871
4872 final long identity = Binder.clearCallingIdentity();
4873 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004874 ImsManager.getInstance(defaultPhone.getContext(),
4875 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004876 } finally {
4877 Binder.restoreCallingIdentity(identity);
4878 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004879 }
4880
4881 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004882 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004883 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004884 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004885 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004886 return false;
4887 }
Svet Ganovb320e182015-04-16 12:30:10 -07004888
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 final long identity = Binder.clearCallingIdentity();
4890 try {
4891 // Check the user preference and the system-level IMS setting. Even if the user has
4892 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4893 // In the long run, we may instead need to check if there exists a connection service
4894 // which can support video calling.
4895 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004896 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004897 return imsManager.isVtEnabledByPlatform()
4898 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4899 && imsManager.isVtEnabledByUser();
4900 } finally {
4901 Binder.restoreCallingIdentity(identity);
4902 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004903 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004904
Andrew Leea1239f22015-03-02 17:44:07 -08004905 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4907 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4908 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4909 return false;
4910 }
4911
4912 final long identity = Binder.clearCallingIdentity();
4913 try {
4914 CarrierConfigManager configManager =
4915 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004916 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4918 } finally {
4919 Binder.restoreCallingIdentity(identity);
4920 }
Andrew Leea1239f22015-03-02 17:44:07 -08004921 }
4922
4923 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924 public boolean isWorldPhone(int subId, String callingPackage) {
4925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4926 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4927 return false;
4928 }
4929
4930 final long identity = Binder.clearCallingIdentity();
4931 try {
4932 CarrierConfigManager configManager =
4933 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004934 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4936 } finally {
4937 Binder.restoreCallingIdentity(identity);
4938 }
Andrew Leea1239f22015-03-02 17:44:07 -08004939 }
4940
Andrew Lee9431b832015-03-09 18:46:45 -07004941 @Override
4942 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004943 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004944 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004945 }
4946
4947 @Override
4948 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 final long identity = Binder.clearCallingIdentity();
4950 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004951 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 } finally {
4953 Binder.restoreCallingIdentity(identity);
4954 }
Andrew Lee9431b832015-03-09 18:46:45 -07004955 }
4956
Hall Liuf6668912018-10-31 17:05:23 -07004957 /**
4958 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4959 * support for the feature and device firmware support.
4960 *
4961 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4962 */
4963 @Override
4964 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004966 final Phone phone = getPhone(subscriptionId);
4967 if (phone == null) {
4968 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4969 return false;
4970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004971 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004972 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4974 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004975 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004976 return isCarrierSupported && isDeviceSupported;
4977 } finally {
4978 Binder.restoreCallingIdentity(identity);
4979 }
Hall Liu98187582018-01-22 19:15:32 -08004980 }
4981
Hall Liuf6668912018-10-31 17:05:23 -07004982 /**
4983 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4984 * both also support RTT.
4985 */
4986 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004987 final long identity = Binder.clearCallingIdentity();
4988 try {
Hall Liuf6668912018-10-31 17:05:23 -07004989 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004990 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004994 }
4995
Sanket Padawe7310cc72015-01-14 09:53:20 -08004996 /**
4997 * Returns the unique device ID of phone, for example, the IMEI for
4998 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4999 *
5000 * <p>Requires Permission:
5001 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5002 */
5003 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005004 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005005 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005006 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005007 return null;
5008 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005009 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005010 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5011 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005012 return null;
5013 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014
5015 final long identity = Binder.clearCallingIdentity();
5016 try {
5017 return phone.getDeviceId();
5018 } finally {
5019 Binder.restoreCallingIdentity(identity);
5020 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005021 }
5022
Ping Sunc67b7c22016-03-02 19:16:45 +08005023 /**
5024 * {@hide}
5025 * Returns the IMS Registration Status on a particular subid
5026 *
5027 * @param subId
5028 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005029 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005030 Phone phone = getPhone(subId);
5031 if (phone != null) {
5032 return phone.isImsRegistered();
5033 } else {
5034 return false;
5035 }
5036 }
5037
Santos Cordon7a1885b2015-02-03 11:15:19 -08005038 @Override
5039 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005040 final long identity = Binder.clearCallingIdentity();
5041 try {
5042 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5043 } finally {
5044 Binder.restoreCallingIdentity(identity);
5045 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005046 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005047
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005048 /**
5049 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005050 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005051 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 final long identity = Binder.clearCallingIdentity();
5053 try {
5054 Phone phone = getPhone(subId);
5055 if (phone != null) {
5056 return phone.isWifiCallingEnabled();
5057 } else {
5058 return false;
5059 }
5060 } finally {
5061 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005062 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005063 }
5064
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005065 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005066 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005067 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005068 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069 final long identity = Binder.clearCallingIdentity();
5070 try {
5071 Phone phone = getPhone(subId);
5072 if (phone != null) {
5073 return phone.isVideoEnabled();
5074 } else {
5075 return false;
5076 }
5077 } finally {
5078 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005079 }
5080 }
5081
5082 /**
5083 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5084 * defined in {@link ImsRegistrationImplBase}.
5085 */
5086 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 final long identity = Binder.clearCallingIdentity();
5088 try {
5089 Phone phone = getPhone(subId);
5090 if (phone != null) {
5091 return phone.getImsRegistrationTech();
5092 } else {
5093 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5094 }
5095 } finally {
5096 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005097 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005098 }
5099
Stuart Scott8eef64f2015-04-08 15:13:54 -07005100 @Override
5101 public void factoryReset(int subId) {
5102 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005103 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5104 return;
5105 }
5106
Svet Ganovcc087f82015-05-12 20:35:54 -07005107 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005108
Svet Ganovcc087f82015-05-12 20:35:54 -07005109 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005110 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5111 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005112 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005113 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005114 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005115 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5116 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005117 }
5118 } finally {
5119 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005120 }
5121 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005122
5123 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005124 public String getSimLocaleForSubscriber(int subId) {
5125 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5126 final Phone phone = getPhone(subId);
5127 if (phone == null) {
5128 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005129 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005130 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005131 final long identity = Binder.clearCallingIdentity();
5132 try {
chen xu5d3637b2019-01-21 23:31:38 -08005133 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5134 phone.getContext().getOpPackageName());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135 // Try and fetch the locale from the carrier properties or from the SIM language
5136 // preferences (EF-PL and EF-LI)...
5137 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005139 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5140 if (localeFromDefaultSim != null) {
5141 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5142 if (DBG) log("Using locale from subId: " + subId + " locale: "
5143 + localeFromDefaultSim);
5144 return localeFromDefaultSim.toLanguageTag();
5145 } else {
5146 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005147 }
5148 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005149
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005150 // The SIM language preferences only store a language (e.g. fr = French), not an
5151 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5152 // the SIM and carrier preferences does not include a country we add the country
5153 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005154 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005155 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005156 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005157 return mccLocale.toLanguageTag();
5158 }
5159
5160 if (DBG) log("No locale found - returning null");
5161 return null;
5162 } finally {
5163 Binder.restoreCallingIdentity(identity);
5164 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005165 }
5166
5167 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005168 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005169 }
5170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 /**
5172 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5173 */
5174 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005175 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005176 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005177
Chenjie Yu1ba97252018-01-11 18:16:20 -08005178 private final ModemActivityInfo mLastModemActivityInfo =
5179 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5180
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005181 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005182 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5183 * representing the state of the modem.
5184 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005185 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5186 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005187 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005188 */
5189 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005190 public void requestModemActivityInfo(ResultReceiver result) {
5191 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005192 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193
5194 final long identity = Binder.clearCallingIdentity();
5195 try {
5196 ModemActivityInfo ret = null;
5197 synchronized (mLastModemActivityInfo) {
5198 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5199 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005200 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005201 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005202 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5203 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005204 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5205 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206 }
5207 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005208 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5209 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210 mLastModemActivityInfo.setIdleTimeMillis(
5211 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5212 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5213 mLastModemActivityInfo.setRxTimeMillis(
5214 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5215 mLastModemActivityInfo.setEnergyUsed(
5216 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005217 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5219 mLastModemActivityInfo.getSleepTimeMillis(),
5220 mLastModemActivityInfo.getIdleTimeMillis(),
5221 mLastModemActivityInfo.getTxTimeMillis(),
5222 mLastModemActivityInfo.getRxTimeMillis(),
5223 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005224 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 Bundle bundle = new Bundle();
5226 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5227 result.send(0, bundle);
5228 } finally {
5229 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005230 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005231 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005232
Siddharth Rayb8114062018-06-17 15:02:38 -07005233 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5234 // less than total activity duration.
5235 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5236 if (info == null) {
5237 return false;
5238 }
5239 int activityDurationMs =
5240 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5241 int totalTxTimeMs = 0;
5242 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5243 totalTxTimeMs += info.getTxTimeMillis()[i];
5244 }
5245 return (info.isValid()
5246 && (info.getSleepTimeMillis() <= activityDurationMs)
5247 && (info.getIdleTimeMillis() <= activityDurationMs)
5248 && (info.getRxTimeMillis() <= activityDurationMs)
5249 && (totalTxTimeMs <= activityDurationMs));
5250 }
5251
Jack Yu85bd38a2015-11-09 11:34:32 -08005252 /**
5253 * {@hide}
5254 * Returns the service state information on specified subscription.
5255 */
5256 @Override
5257 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005258 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005259 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005260 return null;
5261 }
5262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 final long identity = Binder.clearCallingIdentity();
5264 try {
5265 final Phone phone = getPhone(subId);
5266 if (phone == null) {
5267 return null;
5268 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005269
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 return phone.getServiceState();
5271 } finally {
5272 Binder.restoreCallingIdentity(identity);
5273 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005274 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005275
5276 /**
5277 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5278 *
5279 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5280 * voicemail ringtone.
5281 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5282 * PhoneAccount.
5283 */
5284 @Override
5285 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 final long identity = Binder.clearCallingIdentity();
5287 try {
5288 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5289 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005290 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005297 }
5298
5299 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005300 * Sets the per-account voicemail ringtone.
5301 *
5302 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5303 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5304 *
5305 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5306 * voicemail ringtone.
5307 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5308 * PhoneAccount.
5309 */
5310 @Override
5311 public void setVoicemailRingtoneUri(String callingPackage,
5312 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005313 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005314 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5315 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005316 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5318 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5319 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321
5322 final long identity = Binder.clearCallingIdentity();
5323 try {
5324 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5325 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005326 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 }
5328 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5329 } finally {
5330 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005331 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005332 }
5333
5334 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005335 * Returns whether vibration is set for voicemail notification in Phone settings.
5336 *
5337 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5338 * voicemail vibration setting.
5339 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5340 */
5341 @Override
5342 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343 final long identity = Binder.clearCallingIdentity();
5344 try {
5345 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5346 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005347 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005354 }
5355
Youhan Wange64578a2016-05-02 15:32:42 -07005356 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005357 * Sets the per-account voicemail vibration.
5358 *
5359 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5360 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5361 *
5362 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5363 * voicemail vibration setting.
5364 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5365 * specific PhoneAccount.
5366 */
5367 @Override
5368 public void setVoicemailVibrationEnabled(String callingPackage,
5369 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005370 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005371 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5372 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005373 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5375 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5376 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005377 }
5378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 final long identity = Binder.clearCallingIdentity();
5380 try {
5381 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5382 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005383 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005384 }
5385 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5386 } finally {
5387 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005388 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005389 }
5390
5391 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005392 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5393 *
5394 * @throws SecurityException if the caller does not have the required permission
5395 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005396 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005397 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005398 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005399 }
5400
5401 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005402 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5403 * permission.
5404 *
5405 * @throws SecurityException if the caller does not have the required permission
5406 */
5407 private void enforceSendSmsPermission() {
5408 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5409 }
5410
5411 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005412 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005413 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005414 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005415 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005416 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417 final long identity = Binder.clearCallingIdentity();
5418 try {
5419 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005420 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 if (componentName == null) {
5422 throw new SecurityException(
5423 "Caller not current active visual voicemail package[null]");
5424 }
5425 String vvmPackage = componentName.getPackageName();
5426 if (!callingPackage.equals(vvmPackage)) {
5427 throw new SecurityException("Caller not current active visual voicemail package["
5428 + vvmPackage + "]");
5429 }
5430 } finally {
5431 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005432 }
5433 }
5434
5435 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005436 * Return the application ID for the app type.
5437 *
5438 * @param subId the subscription ID that this request applies to.
5439 * @param appType the uicc app type.
5440 * @return Application ID for specificied app type, or null if no uicc.
5441 */
5442 @Override
5443 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005444 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005445 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446
5447 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005448 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 if (phone == null) {
5450 return null;
5451 }
5452 String aid = null;
5453 try {
5454 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5455 .getApplicationByType(appType).getAid();
5456 } catch (Exception e) {
5457 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5458 }
5459 return aid;
5460 } finally {
5461 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005462 }
Youhan Wange64578a2016-05-02 15:32:42 -07005463 }
5464
Youhan Wang4001d252016-05-11 10:29:41 -07005465 /**
5466 * Return the Electronic Serial Number.
5467 *
5468 * @param subId the subscription ID that this request applies to.
5469 * @return ESN or null if error.
5470 */
5471 @Override
5472 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005473 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005474 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475
5476 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005477 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478 if (phone == null) {
5479 return null;
5480 }
5481 String esn = null;
5482 try {
5483 esn = phone.getEsn();
5484 } catch (Exception e) {
5485 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5486 }
5487 return esn;
5488 } finally {
5489 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005490 }
Youhan Wang4001d252016-05-11 10:29:41 -07005491 }
5492
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005493 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005494 * Return the Preferred Roaming List Version.
5495 *
5496 * @param subId the subscription ID that this request applies to.
5497 * @return PRLVersion or null if error.
5498 */
5499 @Override
5500 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005501 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005502 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005503
5504 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005505 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 if (phone == null) {
5507 return null;
5508 }
5509 String cdmaPrlVersion = null;
5510 try {
5511 cdmaPrlVersion = phone.getCdmaPrlVersion();
5512 } catch (Exception e) {
5513 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5514 }
5515 return cdmaPrlVersion;
5516 } finally {
5517 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005518 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005519 }
5520
5521 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005522 * Get snapshot of Telephony histograms
5523 * @return List of Telephony histograms
5524 * @hide
5525 */
5526 @Override
5527 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5529 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530
5531 final long identity = Binder.clearCallingIdentity();
5532 try {
5533 return RIL.getTelephonyRILTimingHistograms();
5534 } finally {
5535 Binder.restoreCallingIdentity(identity);
5536 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005537 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005538
5539 /**
5540 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005541 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5542 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005543 * Require system privileges. In the future we may add this to carrier APIs.
5544 *
Michele Berionne482f8202018-11-27 18:57:59 -08005545 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005546 */
5547 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005548 @TelephonyManager.SetCarrierRestrictionResult
5549 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005550 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005551 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005552
Michele Berionne482f8202018-11-27 18:57:59 -08005553 if (carrierRestrictionRules == null) {
5554 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005555 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557 final long identity = Binder.clearCallingIdentity();
5558 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005559 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005560 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561 } finally {
5562 Binder.restoreCallingIdentity(identity);
5563 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005564 }
5565
5566 /**
5567 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005568 * Get the allowed carrier list and the excluded carrier list, including the priority between
5569 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005570 * Require system privileges. In the future we may add this to carrier APIs.
5571 *
Michele Berionne482f8202018-11-27 18:57:59 -08005572 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005573 */
5574 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005575 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005576 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005577 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578
5579 final long identity = Binder.clearCallingIdentity();
5580 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005581 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5582 if (response instanceof CarrierRestrictionRules) {
5583 return (CarrierRestrictionRules) response;
5584 }
5585 // Response is an Exception of some kind,
5586 // which is signalled to the user as a NULL retval
5587 return null;
5588 } catch (Exception e) {
5589 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5590 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591 } finally {
5592 Binder.restoreCallingIdentity(identity);
5593 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005594 }
5595
fionaxu59545b42016-05-25 15:53:37 -07005596 /**
5597 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5598 * @param subId the subscription ID that this action applies to.
5599 * @param enabled control enable or disable metered apns.
5600 * {@hide}
5601 */
5602 @Override
5603 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5604 enforceModifyPermission();
5605 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606
5607 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005608 if (phone == null) {
5609 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5610 return;
5611 }
5612 try {
5613 phone.carrierActionSetMeteredApnsEnabled(enabled);
5614 } catch (Exception e) {
5615 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005616 } finally {
5617 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005618 }
5619 }
5620
5621 /**
5622 * Action set from carrier signalling broadcast receivers to enable/disable radio
5623 * @param subId the subscription ID that this action applies to.
5624 * @param enabled control enable or disable radio.
5625 * {@hide}
5626 */
5627 @Override
5628 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5629 enforceModifyPermission();
5630 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005631
5632 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005633 if (phone == null) {
5634 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5635 return;
5636 }
5637 try {
5638 phone.carrierActionSetRadioEnabled(enabled);
5639 } catch (Exception e) {
5640 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 } finally {
5642 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005643 }
5644 }
5645
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005646 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005647 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5648 * network status based on which carrier apps could apply actions accordingly,
5649 * enable/disable default url handler for example.
5650 *
5651 * @param subId the subscription ID that this action applies to.
5652 * @param report control start/stop reporting the default network status.
5653 * {@hide}
5654 */
5655 @Override
5656 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5657 enforceModifyPermission();
5658 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659
5660 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005661 if (phone == null) {
5662 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5663 return;
5664 }
5665 try {
5666 phone.carrierActionReportDefaultNetworkStatus(report);
5667 } catch (Exception e) {
5668 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005669 } finally {
5670 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005671 }
5672 }
5673
5674 /**
fionaxud9622282017-07-17 17:51:30 -07005675 * Action set from carrier signalling broadcast receivers to reset all carrier actions
5676 * @param subId the subscription ID that this action applies to.
5677 * {@hide}
5678 */
5679 @Override
5680 public void carrierActionResetAll(int subId) {
5681 enforceModifyPermission();
5682 final Phone phone = getPhone(subId);
5683 if (phone == null) {
5684 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
5685 return;
5686 }
5687 try {
5688 phone.carrierActionResetAll();
5689 } catch (Exception e) {
5690 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
5691 }
5692 }
5693
5694 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005695 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5696 * bug report is being generated.
5697 */
5698 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005699 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005700 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5701 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005702 writer.println("Permission Denial: can't dump Phone from pid="
5703 + Binder.getCallingPid()
5704 + ", uid=" + Binder.getCallingUid()
5705 + "without permission "
5706 + android.Manifest.permission.DUMP);
5707 return;
5708 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005709 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005710 }
Jack Yueb89b242016-06-22 13:27:47 -07005711
Brad Ebingerdac2f002018-04-03 15:17:52 -07005712 @Override
5713 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5714 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5715 throws RemoteException {
5716 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5717 }
5718
Jack Yueb89b242016-06-22 13:27:47 -07005719 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005720 * Get aggregated video call data usage since boot.
5721 *
5722 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5723 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005724 * {@hide}
5725 */
5726 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005727 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005728 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5729 null);
5730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 final long identity = Binder.clearCallingIdentity();
5732 try {
5733 // NetworkStatsService keeps tracking the active network interface and identity. It
5734 // records the delta with the corresponding network identity.
5735 // We just return the total video call data usage snapshot since boot.
5736 Phone phone = getPhone(subId);
5737 if (phone != null) {
5738 return phone.getVtDataUsage(perUidStats);
5739 }
5740 return null;
5741 } finally {
5742 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005743 }
Jack Yueb89b242016-06-22 13:27:47 -07005744 }
Jack Yu75ab2952016-07-08 14:29:33 -07005745
5746 /**
5747 * Policy control of data connection. Usually used when data limit is passed.
5748 * @param enabled True if enabling the data, otherwise disabling.
5749 * @param subId Subscription index
5750 * {@hide}
5751 */
5752 @Override
5753 public void setPolicyDataEnabled(boolean enabled, int subId) {
5754 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005755
5756 final long identity = Binder.clearCallingIdentity();
5757 try {
5758 Phone phone = getPhone(subId);
5759 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005760 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761 }
5762 } finally {
5763 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005764 }
5765 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005766
5767 /**
5768 * Get Client request stats
5769 * @return List of Client Request Stats
5770 * @hide
5771 */
5772 @Override
5773 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005774 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005775 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005776 return null;
5777 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005778 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005779
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780 final long identity = Binder.clearCallingIdentity();
5781 try {
5782 if (phone != null) {
5783 return phone.getClientRequestStats();
5784 }
5785
5786 return null;
5787 } finally {
5788 Binder.restoreCallingIdentity(identity);
5789 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005790 }
5791
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005792 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005793 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005794 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005795 }
Jack Yueb4124c2017-02-16 15:32:43 -08005796
5797 /**
Grace Chen70990072017-03-24 17:21:30 -07005798 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005799 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005800 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005801 * @param state State of SIM (power down, power up, pass through)
5802 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5803 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5804 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005805 *
5806 **/
5807 @Override
Grace Chen70990072017-03-24 17:21:30 -07005808 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005809 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005810 Phone phone = PhoneFactory.getPhone(slotIndex);
5811
vagdeviaf9a5b92018-08-15 16:01:53 -07005812 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814 final long identity = Binder.clearCallingIdentity();
5815 try {
5816 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005817 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 }
5819 } finally {
5820 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005821 }
5822 }
Shuo Qiandd210312017-04-12 22:11:33 +00005823
Tyler Gunn65d45c22017-06-05 11:22:26 -07005824 private boolean isUssdApiAllowed(int subId) {
5825 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005826 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005827 if (configManager == null) {
5828 return false;
5829 }
5830 PersistableBundle pb = configManager.getConfigForSubId(subId);
5831 if (pb == null) {
5832 return false;
5833 }
5834 return pb.getBoolean(
5835 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5836 }
5837
Shuo Qiandd210312017-04-12 22:11:33 +00005838 /**
5839 * Check if phone is in emergency callback mode
5840 * @return true if phone is in emergency callback mode
5841 * @param subId sub id
5842 */
goneil9c5f4872017-12-05 14:07:56 -08005843 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005844 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005845 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005846 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847
5848 final long identity = Binder.clearCallingIdentity();
5849 try {
5850 if (phone != null) {
5851 return phone.isInEcm();
5852 } else {
5853 return false;
5854 }
5855 } finally {
5856 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005857 }
5858 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005859
5860 /**
5861 * Get the current signal strength information for the given subscription.
5862 * Because this information is not updated when the device is in a low power state
5863 * it should not be relied-upon to be current.
5864 * @param subId Subscription index
5865 * @return the most recent cached signal strength info from the modem
5866 */
5867 @Override
5868 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005869 final long identity = Binder.clearCallingIdentity();
5870 try {
5871 Phone p = getPhone(subId);
5872 if (p == null) {
5873 return null;
5874 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005875
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005876 return p.getSignalStrength();
5877 } finally {
5878 Binder.restoreCallingIdentity(identity);
5879 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005880 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005881
Pengquan Meng77b7f132018-08-22 14:49:57 -07005882 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005883 * Get the current modem radio state for the given slot.
5884 * @param slotIndex slot index.
5885 * @param callingPackage the name of the package making the call.
5886 * @return the current radio power state from the modem
5887 */
5888 @Override
5889 public int getRadioPowerState(int slotIndex, String callingPackage) {
5890 Phone phone = PhoneFactory.getPhone(slotIndex);
5891 if (phone != null) {
5892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5893 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5894 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5895 }
5896
5897 final long identity = Binder.clearCallingIdentity();
5898 try {
5899 return phone.getRadioPowerState();
5900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
5903 }
5904 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5905 }
5906
5907 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005908 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5909 *
5910 * <p>Requires one of the following permissions:
5911 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5912 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5913 * privileges.
5914 *
5915 * @param subId subscription id
5916 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5917 * {@code false}.
5918 */
5919 @Override
5920 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005921 boolean isEnabled = false;
5922 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005923 try {
5924 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005925 null /* message */);
5926 Phone phone = getPhone(subId);
5927 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005928 } catch (Exception e) {
5929 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5930 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005931 } finally {
5932 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005933 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005934 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005935 }
5936
5937
5938 /**
5939 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5940 *
5941 * <p> Requires permission:
5942 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5943 * privileges.
5944 *
5945 * @param subId subscription id
5946 * @param isEnabled {@code true} means enable, {@code false} means disable.
5947 */
5948 @Override
5949 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005950 final long identity = Binder.clearCallingIdentity();
5951 try {
5952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5953 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005954
Pengquan Menga1bb6272018-09-06 09:59:22 -07005955 Phone phone = getPhone(subId);
5956 if (phone != null) {
5957 phone.setDataRoamingEnabled(isEnabled);
5958 }
5959 } finally {
5960 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005961 }
5962 }
5963
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005964 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005965 public boolean isManualNetworkSelectionAllowed(int subId) {
5966 boolean isAllowed = true;
5967 final long identity = Binder.clearCallingIdentity();
5968 try {
5969 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5970 mApp, subId, "isManualNetworkSelectionAllowed");
5971 Phone phone = getPhone(subId);
5972 if (phone != null) {
5973 isAllowed = phone.isCspPlmnEnabled();
5974 }
5975 } finally {
5976 Binder.restoreCallingIdentity(identity);
5977 }
5978 return isAllowed;
5979 }
5980
5981 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08005982 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
5983 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
5984 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5985 throw new SecurityException("Caller does not have carrier privileges on any UICC.");
5986 }
Jordan Liu5aa07002018-12-18 15:44:48 -08005987
5988 final long identity = Binder.clearCallingIdentity();
5989 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08005990 UiccController uiccController = UiccController.getInstance();
5991 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
5992
5993 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
5994 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
5995 // Remove private info if the caller doesn't have access
5996 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
5997 for (UiccCardInfo cardInfo : cardInfos) {
5998 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
5999 UiccProfile profile = card.getUiccProfile();
6000 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6001 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6002 filteredInfos.add(cardInfo.getUnprivileged());
6003 } else {
6004 filteredInfos.add(cardInfo);
6005 }
6006 }
6007 return filteredInfos;
6008 }
6009 return cardInfos;
6010 } catch (PackageManager.NameNotFoundException e) {
6011 // This should not happen since we pass the package info in from TelephonyManager
6012 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006013 } finally {
6014 Binder.restoreCallingIdentity(identity);
6015 }
6016 }
6017
6018 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006019 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006020 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 final long identity = Binder.clearCallingIdentity();
6023 try {
6024 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6025 if (slots == null) {
6026 Rlog.i(LOG_TAG, "slots is null.");
6027 return null;
6028 }
6029
6030 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6031 for (int i = 0; i < slots.length; i++) {
6032 UiccSlot slot = slots[i];
6033 if (slot == null) {
6034 continue;
6035 }
6036
6037 String cardId;
6038 UiccCard card = slot.getUiccCard();
6039 if (card != null) {
6040 cardId = card.getCardId();
6041 } else {
6042 cardId = slot.getIccId();
6043 }
6044
6045 int cardState = 0;
6046 switch (slot.getCardState()) {
6047 case CARDSTATE_ABSENT:
6048 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6049 break;
6050 case CARDSTATE_PRESENT:
6051 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6052 break;
6053 case CARDSTATE_ERROR:
6054 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6055 break;
6056 case CARDSTATE_RESTRICTED:
6057 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6058 break;
6059 default:
6060 break;
6061
6062 }
6063
6064 infos[i] = new UiccSlotInfo(
6065 slot.isActive(),
6066 slot.isEuicc(),
6067 cardId,
6068 cardState,
6069 slot.getPhoneId(),
6070 slot.isExtendedApduSupported());
6071 }
6072 return infos;
6073 } finally {
6074 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006075 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006076 }
6077
6078 @Override
6079 public boolean switchSlots(int[] physicalSlots) {
6080 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081
6082 final long identity = Binder.clearCallingIdentity();
6083 try {
6084 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6085 } finally {
6086 Binder.restoreCallingIdentity(identity);
6087 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006088 }
Jack Yu4c988042018-02-27 15:30:01 -08006089
6090 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006091 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006092 final long identity = Binder.clearCallingIdentity();
6093 try {
6094 return UiccController.getInstance().getCardIdForDefaultEuicc();
6095 } finally {
6096 Binder.restoreCallingIdentity(identity);
6097 }
6098 }
6099
6100 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006101 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6102 enforceModifyPermission();
6103 final Phone phone = getPhone(subId);
6104 if (phone == null) {
6105 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6106 return;
6107 }
6108
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109 final long identity = Binder.clearCallingIdentity();
6110 try {
6111 phone.setRadioIndicationUpdateMode(filters, mode);
6112 } finally {
6113 Binder.restoreCallingIdentity(identity);
6114 }
Jack Yu4c988042018-02-27 15:30:01 -08006115 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006116
6117 /**
goneil47ffb6e2018-04-06 15:40:58 -07006118 * A test API to reload the UICC profile.
6119 *
6120 * <p>Requires that the calling app has permission
6121 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6122 * @hide
6123 */
6124 @Override
6125 public void refreshUiccProfile(int subId) {
6126 enforceModifyPermission();
6127
6128 final long identity = Binder.clearCallingIdentity();
6129 try {
6130 Phone phone = getPhone(subId);
6131 if (phone == null) {
6132 return;
6133 }
6134 UiccCard uiccCard = phone.getUiccCard();
6135 if (uiccCard == null) {
6136 return;
6137 }
6138 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6139 if (uiccProfile == null) {
6140 return;
6141 }
6142 uiccProfile.refresh();
6143 } finally {
6144 Binder.restoreCallingIdentity(identity);
6145 }
6146 }
6147
6148 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006149 * Returns false if the mobile data is disabled by default, otherwise return true.
6150 */
6151 private boolean getDefaultDataEnabled() {
6152 return "true".equalsIgnoreCase(
6153 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6154 }
6155
6156 /**
6157 * Returns true if the data roaming is enabled by default, i.e the system property
6158 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6159 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6160 */
6161 private boolean getDefaultDataRoamingEnabled(int subId) {
6162 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006163 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006164 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6165 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6166 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6167 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6168 return isDataRoamingEnabled;
6169 }
6170
6171 /**
6172 * Returns the default network type for the given {@code subId}, if the default network type is
6173 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6174 */
6175 private int getDefaultNetworkType(int subId) {
6176 return Integer.parseInt(
6177 TelephonyManager.getTelephonyProperty(
6178 mSubscriptionController.getPhoneId(subId),
6179 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6180 String.valueOf(Phone.PREFERRED_NT_MODE)));
6181 }
fionaxua13278b2018-03-21 00:08:13 -07006182
6183 @Override
6184 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6185 gid1, String gid2, String plmn, String spn) {
6186 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006187
6188 final long identity = Binder.clearCallingIdentity();
6189 try {
6190 final Phone phone = getPhone(subId);
6191 if (phone == null) {
6192 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6193 return;
6194 }
6195 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6196 } finally {
6197 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006198 }
fionaxua13278b2018-03-21 00:08:13 -07006199 }
6200
6201 @Override
6202 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006203 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204
6205 final long identity = Binder.clearCallingIdentity();
6206 try {
6207 final Phone phone = getPhone(subId);
6208 if (phone == null) {
6209 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6210 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6211 }
6212 return phone.getCarrierIdListVersion();
6213 } finally {
6214 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006215 }
fionaxua13278b2018-03-21 00:08:13 -07006216 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006217
6218 @Override
6219 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6220 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6221 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6222 return -1;
6223 }
6224
6225 final long identity = Binder.clearCallingIdentity();
6226 try {
6227 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6228 } finally {
6229 Binder.restoreCallingIdentity(identity);
6230 }
6231 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006232
6233 @Override
6234 public int getCdmaRoamingMode(int subId) {
6235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6236 mApp, subId, "getCdmaRoamingMode");
6237
6238 final long identity = Binder.clearCallingIdentity();
6239 try {
6240 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6241 } finally {
6242 Binder.restoreCallingIdentity(identity);
6243 }
6244 }
6245
6246 @Override
6247 public boolean setCdmaRoamingMode(int subId, int mode) {
6248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6249 mApp, subId, "setCdmaRoamingMode");
6250
6251 final long identity = Binder.clearCallingIdentity();
6252 try {
6253 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6254 } finally {
6255 Binder.restoreCallingIdentity(identity);
6256 }
6257 }
6258
6259 @Override
6260 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6262 mApp, subId, "setCdmaSubscriptionMode");
6263
6264 final long identity = Binder.clearCallingIdentity();
6265 try {
6266 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6267 } finally {
6268 Binder.restoreCallingIdentity(identity);
6269 }
6270 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006271
6272 private void ensureUserRunning(int userId) {
6273 if (!mUserManager.isUserRunning(userId)) {
6274 throw new IllegalStateException("User " + userId + " does not exist or not running");
6275 }
6276 }
6277
6278 /**
6279 * Returns a list of SMS apps on a given user.
6280 *
6281 * Only the shell user (UID 2000 or 0) can call it.
6282 * Target user must be running.
6283 */
6284 @Override
6285 public String[] getSmsApps(int userId) {
6286 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6287 ensureUserRunning(userId);
6288
6289 final Collection<SmsApplicationData> apps =
6290 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6291
6292 String[] ret = new String[apps.size()];
6293 int i = 0;
6294 for (SmsApplicationData app : apps) {
6295 ret[i++] = app.mPackageName;
6296 }
6297 return ret;
6298 }
6299
6300 /**
6301 * Returns the default SMS app package name on a given user.
6302 *
6303 * Only the shell user (UID 2000 or 0) can call it.
6304 * Target user must be running.
6305 */
6306 @Override
6307 public String getDefaultSmsApp(int userId) {
6308 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6309 ensureUserRunning(userId);
6310
6311 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6312 /* updateIfNeeded= */ true, userId);
6313 return cn == null ? null : cn.getPackageName();
6314 }
6315
6316 /**
6317 * Set a package as the default SMS app on a given user.
6318 *
6319 * Only the shell user (UID 2000 or 0) can call it.
6320 * Target user must be running.
6321 */
6322 @Override
6323 public void setDefaultSmsApp(int userId, String packageName) {
6324 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6325 ensureUserRunning(userId);
6326
6327 boolean found = false;
6328 for (String pkg : getSmsApps(userId)) {
6329 if (TextUtils.equals(packageName, pkg)) {
6330 found = true;
6331 break;
6332 }
6333 }
6334 if (!found) {
6335 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6336 }
6337
6338 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6339 }
sqianc5eccab2018-10-19 18:46:41 -07006340
6341 @Override
6342 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6343 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006344 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6345 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6346 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6347 }
6348 final long identity = Binder.clearCallingIdentity();
6349 try {
sqian854d44b2018-12-12 16:48:18 -08006350 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6351 for (Phone phone: PhoneFactory.getPhones()) {
6352 if (phone.getEmergencyNumberTracker() != null
6353 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6354 emergencyNumberListInternal.put(
6355 phone.getSubId(),
6356 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6357 }
sqian11b7a0e2018-12-05 18:48:28 -08006358 }
sqian854d44b2018-12-12 16:48:18 -08006359 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006360 } finally {
6361 Binder.restoreCallingIdentity(identity);
6362 }
sqianc5eccab2018-10-19 18:46:41 -07006363 }
6364
6365 @Override
sqian11b7a0e2018-12-05 18:48:28 -08006366 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006367 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006368 if (!exactMatch) {
6369 TelephonyPermissions
6370 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006371 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006372 }
6373 final long identity = Binder.clearCallingIdentity();
6374 try {
sqian854d44b2018-12-12 16:48:18 -08006375 for (Phone phone: PhoneFactory.getPhones()) {
6376 if (phone.getEmergencyNumberTracker() != null
6377 && phone.getEmergencyNumberTracker() != null) {
6378 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6379 number, exactMatch)) {
6380 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006381 }
6382 }
sqian11b7a0e2018-12-05 18:48:28 -08006383 }
6384 return false;
6385 } finally {
6386 Binder.restoreCallingIdentity(identity);
6387 }
6388 }
6389
sqianf4ca7ed2019-01-15 18:32:07 -08006390 /**
6391 * Update emergency number list for test mode.
6392 */
6393 @Override
6394 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6395 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6396 "updateEmergencyNumberListTestMode");
6397
6398 final long identity = Binder.clearCallingIdentity();
6399 try {
6400 for (Phone phone: PhoneFactory.getPhones()) {
6401 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6402 if (tracker != null) {
6403 tracker.executeEmergencyNumberTestModeCommand(action, num);
6404 }
6405 }
6406 } finally {
6407 Binder.restoreCallingIdentity(identity);
6408 }
6409 }
6410
6411 /**
6412 * Get the full emergency number list for test mode.
6413 */
6414 @Override
6415 public List<String> getEmergencyNumberListTestMode() {
6416 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6417 "getEmergencyNumberListTestMode");
6418
6419 final long identity = Binder.clearCallingIdentity();
6420 try {
6421 Set<String> emergencyNumbers = new HashSet<>();
6422 for (Phone phone: PhoneFactory.getPhones()) {
6423 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6424 if (tracker != null) {
6425 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6426 emergencyNumbers.add(num.getNumber());
6427 }
6428 }
6429 }
6430 return new ArrayList<>(emergencyNumbers);
6431 } finally {
6432 Binder.restoreCallingIdentity(identity);
6433 }
6434 }
6435
chen xud6b45bd2018-10-30 22:27:10 -07006436 @Override
6437 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6438 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6439 Phone phone = getPhone(subId);
6440 if (phone == null) {
6441 return null;
6442 }
6443 final long identity = Binder.clearCallingIdentity();
6444 try {
6445 UiccProfile profile = UiccController.getInstance()
6446 .getUiccProfileForPhone(phone.getPhoneId());
6447 if (profile != null) {
6448 return profile.getCertsFromCarrierPrivilegeAccessRules();
6449 }
6450 } finally {
6451 Binder.restoreCallingIdentity(identity);
6452 }
6453 return null;
6454 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006455
6456 /**
6457 * Enable or disable a modem stack.
6458 */
6459 @Override
6460 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6461 enforceModifyPermission();
6462
6463 final long identity = Binder.clearCallingIdentity();
6464 try {
6465 Phone phone = PhoneFactory.getPhone(slotIndex);
6466 if (phone == null) {
6467 return false;
6468 } else {
6469 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6470 }
6471 } finally {
6472 Binder.restoreCallingIdentity(identity);
6473 }
6474 }
Michelecea4cf22018-12-21 15:00:11 -08006475
6476 @Override
6477 public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) {
6478 enforceModifyPermission();
6479
6480 final long identity = Binder.clearCallingIdentity();
6481 try {
6482 mTelephonySharedPreferences.edit()
6483 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted)
6484 .commit();
6485 } finally {
6486 Binder.restoreCallingIdentity(identity);
6487 }
6488 }
6489
6490 @Override
6491 public boolean isMultisimCarrierRestricted() {
6492 enforceReadPrivilegedPermission("isMultisimCarrierRestricted");
6493
6494 final long identity = Binder.clearCallingIdentity();
6495 try {
6496 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6497 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6498 if (numPhysicalSlots < 2) {
6499 loge("isMultisimCarrierRestricted: requires at least 2 cards");
6500 return true;
6501 }
6502
6503 // Default value is false. Multi SIM is allowed unless explicitly restricted.
6504 return mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false);
6505 } finally {
6506 Binder.restoreCallingIdentity(identity);
6507 }
6508 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006509
6510 /**
6511 * Switch configs to enable multi-sim or switch back to single-sim
6512 * @param numOfSims number of active sims we want to switch to
6513 */
6514 @Override
6515 public void switchMultiSimConfig(int numOfSims) {
6516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6517 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6518 final long identity = Binder.clearCallingIdentity();
6519 try {
6520 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6521 } finally {
6522 Binder.restoreCallingIdentity(identity);
6523 }
6524 }
6525
6526 /**
6527 * Get how many sims have been activated on the phone
6528 */
6529 @Override
6530 public int getNumOfActiveSims() {
6531 final long identity = Binder.clearCallingIdentity();
6532 try {
6533 return mPhoneConfigurationManager.getNumOfActiveSims();
6534 } finally {
6535 Binder.restoreCallingIdentity(identity);
6536 }
6537 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006538
6539 /**
6540 * Get whether reboot is required or not after making changes to modem configurations.
6541 * Return value defaults to false
6542 */
6543 @Override
6544 public boolean isRebootRequiredForModemConfigChange() {
6545 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6546 final long identity = Binder.clearCallingIdentity();
6547 try {
6548 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6549 } finally {
6550 Binder.restoreCallingIdentity(identity);
6551 }
6552 }
6553
Pengquan Meng3889a572019-01-23 11:16:29 -08006554 @Override
6555 public int[] getSlotsMapping() {
6556 enforceReadPrivilegedPermission("getSlotsMapping");
6557
6558 final long identity = Binder.clearCallingIdentity();
6559 try {
6560 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6561 // All logical slots should have a mapping to a physical slot.
6562 int[] logicalSlotsMapping = new int[phoneCount];
6563 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6564 for (int i = 0; i < slotInfos.length; i++) {
6565 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6566 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6567 }
6568 }
6569 return logicalSlotsMapping;
6570 } finally {
6571 Binder.restoreCallingIdentity(identity);
6572 }
6573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006574}