blob: d10d3b521977b04ebf31d057bd76fabdf5fa0642 [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
Derek Tan740e1672017-06-27 14:56:27 -0700268 // The AID of ISD-R.
269 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
270
yinxub1bed742017-04-17 11:45:04 -0700271 private NetworkScanRequestTracker mNetworkScanRequestTracker;
272
David Kelly5e06a7f2018-03-12 14:10:59 +0000273 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
274 private static final int MANUFACTURER_CODE_LENGTH = 8;
275
Derek Tan89e89d42014-07-08 17:00:10 -0700276 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700277 * A request object to use for transmitting data to an ICC.
278 */
279 private static final class IccAPDUArgument {
280 public int channel, cla, command, p1, p2, p3;
281 public String data;
282
283 public IccAPDUArgument(int channel, int cla, int command,
284 int p1, int p2, int p3, String data) {
285 this.channel = channel;
286 this.cla = cla;
287 this.command = command;
288 this.p1 = p1;
289 this.p2 = p2;
290 this.p3 = p3;
291 this.data = data;
292 }
293 }
294
295 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700296 * A request object to use for transmitting data to an ICC.
297 */
298 private static final class ManualNetworkSelectionArgument {
299 public OperatorInfo operatorInfo;
300 public boolean persistSelection;
301
302 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
303 this.operatorInfo = operatorInfo;
304 this.persistSelection = persistSelection;
305 }
306 }
307
308 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700309 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
310 * request after sending. The main thread will notify the request when it is complete.
311 */
312 private static final class MainThreadRequest {
313 /** The argument to use for the request */
314 public Object argument;
315 /** The result of the request that is run on the main thread */
316 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800317 // The subscriber id that this request applies to. Defaults to
318 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
319 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700320
Nathan Harold92bed182018-10-12 18:16:49 -0700321 // In cases where subId is unavailable, the caller needs to specify the phone.
322 public Phone phone;
323
vagdeviaf9a5b92018-08-15 16:01:53 -0700324 public WorkSource workSource;
325
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326 public MainThreadRequest(Object argument) {
327 this.argument = argument;
328 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800329
Nathan Harold92bed182018-10-12 18:16:49 -0700330 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
331 this.argument = argument;
332 if (phone != null) {
333 this.phone = phone;
334 }
335 this.workSource = workSource;
336 }
337
vagdeviaf9a5b92018-08-15 16:01:53 -0700338 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800339 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800340 if (subId != null) {
341 this.subId = subId;
342 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700343 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 }
346
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800347 private static final class IncomingThirdPartyCallArgs {
348 public final ComponentName component;
349 public final String callId;
350 public final String callerDisplayName;
351
352 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
353 String callerDisplayName) {
354 this.component = component;
355 this.callId = callId;
356 this.callerDisplayName = callerDisplayName;
357 }
358 }
359
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360 /**
361 * A handler that processes messages on the main thread in the phone process. Since many
362 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
363 * inbound binder threads to the main thread in the phone process. The Binder thread
364 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
365 * on, which will be notified when the operation completes and will contain the result of the
366 * request.
367 *
368 * <p>If a MainThreadRequest object is provided in the msg.obj field,
369 * note that request.result must be set to something non-null for the calling thread to
370 * unblock.
371 */
372 private final class MainThreadHandler extends Handler {
373 @Override
374 public void handleMessage(Message msg) {
375 MainThreadRequest request;
376 Message onCompleted;
377 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800378 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700379 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800380 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381
382 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700383 case CMD_HANDLE_USSD_REQUEST: {
384 request = (MainThreadRequest) msg.obj;
385 final Phone phone = getPhoneFromRequest(request);
386 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
387 String ussdRequest = ussdObject.first;
388 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700389
Pengquan Menga1bb6272018-09-06 09:59:22 -0700390 if (!isUssdApiAllowed(request.subId)) {
391 // Carrier does not support use of this API, return failure.
392 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
393 UssdResponse response = new UssdResponse(ussdRequest, null);
394 Bundle returnData = new Bundle();
395 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
396 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700397
Pengquan Menga1bb6272018-09-06 09:59:22 -0700398 request.result = true;
399 notifyRequester(request);
400 return;
401 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700402
Pengquan Menga1bb6272018-09-06 09:59:22 -0700403 try {
404 request.result = phone != null
405 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
406 } catch (CallStateException cse) {
407 request.result = false;
408 }
409 // Wake up the requesting thread
410 notifyRequester(request);
411 break;
pkanwar32d516d2016-10-14 19:37:38 -0700412 }
413
Yorke Lee716f67e2015-06-17 15:39:16 -0700414 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700416 final Phone phone = getPhoneFromRequest(request);
417 request.result = phone != null ?
418 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
419 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700421 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700426 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800428 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700429 if (uiccCard == null) {
430 loge("iccTransmitApduLogicalChannel: No UICC");
431 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700432 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700433 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
435 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700436 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 iccArgument.channel, iccArgument.cla, iccArgument.command,
438 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700439 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700440 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700441 break;
442
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 ar = (AsyncResult) msg.obj;
445 request = (MainThreadRequest) ar.userObj;
446 if (ar.exception == null && ar.result != null) {
447 request.result = ar.result;
448 } else {
449 request.result = new IccIoResult(0x6F, 0, (byte[])null);
450 if (ar.result == null) {
451 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800452 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700453 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800454 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700455 } else {
456 loge("iccTransmitApduLogicalChannel: Unknown exception");
457 }
458 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700459 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 break;
461
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
463 request = (MainThreadRequest) msg.obj;
464 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800465 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700466 if (uiccCard == null) {
467 loge("iccTransmitApduBasicChannel: No UICC");
468 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700469 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 } else {
471 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
472 request);
473 uiccCard.iccTransmitApduBasicChannel(
474 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
475 iccArgument.p3, iccArgument.data, onCompleted);
476 }
477 break;
478
479 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
480 ar = (AsyncResult) msg.obj;
481 request = (MainThreadRequest) ar.userObj;
482 if (ar.exception == null && ar.result != null) {
483 request.result = ar.result;
484 } else {
485 request.result = new IccIoResult(0x6F, 0, (byte[])null);
486 if (ar.result == null) {
487 loge("iccTransmitApduBasicChannel: Empty response");
488 } else if (ar.exception instanceof CommandException) {
489 loge("iccTransmitApduBasicChannel: CommandException: " +
490 ar.exception);
491 } else {
492 loge("iccTransmitApduBasicChannel: Unknown exception");
493 }
494 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 break;
497
498 case CMD_EXCHANGE_SIM_IO:
499 request = (MainThreadRequest) msg.obj;
500 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800501 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 if (uiccCard == null) {
503 loge("iccExchangeSimIO: No UICC");
504 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700505 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700506 } else {
507 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
508 request);
509 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
510 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
511 iccArgument.data, onCompleted);
512 }
513 break;
514
515 case EVENT_EXCHANGE_SIM_IO_DONE:
516 ar = (AsyncResult) msg.obj;
517 request = (MainThreadRequest) ar.userObj;
518 if (ar.exception == null && ar.result != null) {
519 request.result = ar.result;
520 } else {
521 request.result = new IccIoResult(0x6f, 0, (byte[])null);
522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 break;
525
Derek Tan4d5e5c12014-02-04 11:54:58 -0800526 case CMD_SEND_ENVELOPE:
527 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800528 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700529 if (uiccCard == null) {
530 loge("sendEnvelopeWithStatus: No UICC");
531 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700533 } else {
534 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
535 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
536 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800537 break;
538
539 case EVENT_SEND_ENVELOPE_DONE:
540 ar = (AsyncResult) msg.obj;
541 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700542 if (ar.exception == null && ar.result != null) {
543 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800544 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700545 request.result = new IccIoResult(0x6F, 0, (byte[])null);
546 if (ar.result == null) {
547 loge("sendEnvelopeWithStatus: Empty response");
548 } else if (ar.exception instanceof CommandException) {
549 loge("sendEnvelopeWithStatus: CommandException: " +
550 ar.exception);
551 } else {
552 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
553 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800554 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700555 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800556 break;
557
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 case CMD_OPEN_CHANNEL:
559 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800560 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800561 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 if (uiccCard == null) {
563 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800564 request.result = new IccOpenLogicalChannelResponse(-1,
565 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700567 } else {
568 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800569 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
570 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700571 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 break;
573
574 case EVENT_OPEN_CHANNEL_DONE:
575 ar = (AsyncResult) msg.obj;
576 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700579 int[] result = (int[]) ar.result;
580 int channelId = result[0];
581 byte[] selectResponse = null;
582 if (result.length > 1) {
583 selectResponse = new byte[result.length - 1];
584 for (int i = 1; i < result.length; ++i) {
585 selectResponse[i - 1] = (byte) result[i];
586 }
587 }
588 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700589 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 if (ar.result == null) {
592 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 if (ar.exception != null) {
595 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
596 }
597
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700598 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700599 if (ar.exception instanceof CommandException) {
600 CommandException.Error error =
601 ((CommandException) (ar.exception)).getCommandError();
602 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700603 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700604 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700605 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 }
607 }
608 openChannelResp = new IccOpenLogicalChannelResponse(
609 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700611 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700612 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 break;
614
615 case CMD_CLOSE_CHANNEL:
616 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800617 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700618 if (uiccCard == null) {
619 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900620 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700622 } else {
623 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
624 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
625 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 break;
627
628 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800629 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
630 break;
631
632 case CMD_NV_READ_ITEM:
633 request = (MainThreadRequest) msg.obj;
634 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800635 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
636 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800637 break;
638
639 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 ar = (AsyncResult) msg.obj;
641 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800642 if (ar.exception == null && ar.result != null) {
643 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800645 request.result = "";
646 if (ar.result == null) {
647 loge("nvReadItem: Empty response");
648 } else if (ar.exception instanceof CommandException) {
649 loge("nvReadItem: CommandException: " +
650 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800652 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 }
654 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 break;
657
Jake Hambye994d462014-02-03 13:10:13 -0800658 case CMD_NV_WRITE_ITEM:
659 request = (MainThreadRequest) msg.obj;
660 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
661 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800662 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700663 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800664 break;
665
666 case EVENT_NV_WRITE_ITEM_DONE:
667 handleNullReturnEvent(msg, "nvWriteItem");
668 break;
669
670 case CMD_NV_WRITE_CDMA_PRL:
671 request = (MainThreadRequest) msg.obj;
672 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800673 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800674 break;
675
676 case EVENT_NV_WRITE_CDMA_PRL_DONE:
677 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
678 break;
679
chen xu6dac5ab2018-10-26 17:39:23 -0700680 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800681 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700682 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800683 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800684 break;
685
chen xu6dac5ab2018-10-26 17:39:23 -0700686 case EVENT_RESET_MODEM_CONFIG_DONE:
687 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800688 break;
689
Jake Hamby7c27be32014-03-03 13:25:59 -0800690 case CMD_GET_PREFERRED_NETWORK_TYPE:
691 request = (MainThreadRequest) msg.obj;
692 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700693 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800694 break;
695
696 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
697 ar = (AsyncResult) msg.obj;
698 request = (MainThreadRequest) ar.userObj;
699 if (ar.exception == null && ar.result != null) {
700 request.result = ar.result; // Integer
701 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800702 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800703 if (ar.result == null) {
704 loge("getPreferredNetworkType: Empty response");
705 } else if (ar.exception instanceof CommandException) {
706 loge("getPreferredNetworkType: CommandException: " +
707 ar.exception);
708 } else {
709 loge("getPreferredNetworkType: Unknown exception");
710 }
711 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700712 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 break;
714
715 case CMD_SET_PREFERRED_NETWORK_TYPE:
716 request = (MainThreadRequest) msg.obj;
717 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
718 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700719 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800720 break;
721
722 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
723 handleNullReturnEvent(msg, "setPreferredNetworkType");
724 break;
725
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000726 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
727 request = (MainThreadRequest)msg.obj;
728 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800729 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000730 break;
731
732 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
733 ar = (AsyncResult)msg.obj;
734 request = (MainThreadRequest)ar.userObj;
735 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700736 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000737 break;
738
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800739 case CMD_SET_VOICEMAIL_NUMBER:
740 request = (MainThreadRequest) msg.obj;
741 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
742 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800743 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
744 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800745 break;
746
747 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
748 handleNullReturnEvent(msg, "setVoicemailNumber");
749 break;
750
Stuart Scott54788802015-03-30 13:18:01 -0700751 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
754 request);
755 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
756 break;
757
758 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
759 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
760 break;
761
Shishir Agrawal302c8692015-06-19 13:49:39 -0700762 case CMD_PERFORM_NETWORK_SCAN:
763 request = (MainThreadRequest) msg.obj;
764 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
765 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
766 break;
767
768 case EVENT_PERFORM_NETWORK_SCAN_DONE:
769 ar = (AsyncResult) msg.obj;
770 request = (MainThreadRequest) ar.userObj;
771 CellNetworkScanResult cellScanResult;
772 if (ar.exception == null && ar.result != null) {
773 cellScanResult = new CellNetworkScanResult(
774 CellNetworkScanResult.STATUS_SUCCESS,
775 (List<OperatorInfo>) ar.result);
776 } else {
777 if (ar.result == null) {
778 loge("getCellNetworkScanResults: Empty response");
779 }
780 if (ar.exception != null) {
781 loge("getCellNetworkScanResults: Exception: " + ar.exception);
782 }
783 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
784 if (ar.exception instanceof CommandException) {
785 CommandException.Error error =
786 ((CommandException) (ar.exception)).getCommandError();
787 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
788 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
789 } else if (error == CommandException.Error.GENERIC_FAILURE) {
790 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
791 }
792 }
793 cellScanResult = new CellNetworkScanResult(errorCode, null);
794 }
795 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700796 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700797 break;
798
799 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
800 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700801 ManualNetworkSelectionArgument selArg =
802 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700803 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
804 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700805 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
806 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700807 break;
808
809 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700810 ar = (AsyncResult) msg.obj;
811 request = (MainThreadRequest) ar.userObj;
812 if (ar.exception == null) {
813 request.result = true;
814 } else {
815 request.result = false;
816 loge("setNetworkSelectionModeManual " + ar.exception);
817 }
818 notifyRequester(request);
819 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700820 break;
821
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700822 case CMD_GET_MODEM_ACTIVITY_INFO:
823 request = (MainThreadRequest) msg.obj;
824 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800825 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700826 break;
827
828 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
829 ar = (AsyncResult) msg.obj;
830 request = (MainThreadRequest) ar.userObj;
831 if (ar.exception == null && ar.result != null) {
832 request.result = ar.result;
833 } else {
834 if (ar.result == null) {
835 loge("queryModemActivityInfo: Empty response");
836 } else if (ar.exception instanceof CommandException) {
837 loge("queryModemActivityInfo: CommandException: " +
838 ar.exception);
839 } else {
840 loge("queryModemActivityInfo: Unknown exception");
841 }
842 }
Amit Mahajand4766222016-01-28 15:28:28 -0800843 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
844 if (request.result == null) {
845 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
846 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700847 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700848 break;
849
Meng Wang1a7c35a2016-05-05 20:56:15 -0700850 case CMD_SET_ALLOWED_CARRIERS:
851 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800852 CarrierRestrictionRules argument =
853 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700854 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800855 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700856 break;
857
858 case EVENT_SET_ALLOWED_CARRIERS_DONE:
859 ar = (AsyncResult) msg.obj;
860 request = (MainThreadRequest) ar.userObj;
861 if (ar.exception == null && ar.result != null) {
862 request.result = ar.result;
863 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800864 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
865 if (ar.exception instanceof CommandException) {
866 loge("setAllowedCarriers: CommandException: " + ar.exception);
867 CommandException.Error error =
868 ((CommandException) (ar.exception)).getCommandError();
869 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
870 request.result =
871 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
872 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700873 } else {
874 loge("setAllowedCarriers: Unknown exception");
875 }
876 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700877 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700878 break;
879
880 case CMD_GET_ALLOWED_CARRIERS:
881 request = (MainThreadRequest) msg.obj;
882 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800883 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700884 break;
885
886 case EVENT_GET_ALLOWED_CARRIERS_DONE:
887 ar = (AsyncResult) msg.obj;
888 request = (MainThreadRequest) ar.userObj;
889 if (ar.exception == null && ar.result != null) {
890 request.result = ar.result;
891 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800892 request.result = new IllegalStateException(
893 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700894 if (ar.result == null) {
895 loge("getAllowedCarriers: Empty response");
896 } else if (ar.exception instanceof CommandException) {
897 loge("getAllowedCarriers: CommandException: " +
898 ar.exception);
899 } else {
900 loge("getAllowedCarriers: Unknown exception");
901 }
902 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700903 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700904 break;
905
Nathan Haroldb3014052017-01-25 15:57:32 -0800906 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
907 ar = (AsyncResult) msg.obj;
908 request = (MainThreadRequest) ar.userObj;
909 if (ar.exception == null && ar.result != null) {
910 request.result = ar.result;
911 } else {
912 request.result = new IllegalArgumentException(
913 "Failed to retrieve Forbidden Plmns");
914 if (ar.result == null) {
915 loge("getForbiddenPlmns: Empty response");
916 } else {
917 loge("getForbiddenPlmns: Unknown exception");
918 }
919 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700920 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800921 break;
922
923 case CMD_GET_FORBIDDEN_PLMNS:
924 request = (MainThreadRequest) msg.obj;
925 uiccCard = getUiccCardFromRequest(request);
926 if (uiccCard == null) {
927 loge("getForbiddenPlmns() UiccCard is null");
928 request.result = new IllegalArgumentException(
929 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700930 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800931 break;
932 }
933 Integer appType = (Integer) request.argument;
934 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
935 if (uiccApp == null) {
936 loge("getForbiddenPlmns() no app with specified type -- "
937 + appType);
938 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700939 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800940 break;
941 } else {
942 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
943 + " specified type -- " + appType);
944 }
945 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
946 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
947 onCompleted);
948 break;
949
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000950 case CMD_SWITCH_SLOTS:
951 request = (MainThreadRequest) msg.obj;
952 int[] physicalSlots = (int[]) request.argument;
953 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
954 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
955 break;
956
957 case EVENT_SWITCH_SLOTS_DONE:
958 ar = (AsyncResult) msg.obj;
959 request = (MainThreadRequest) ar.userObj;
960 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700961 notifyRequester(request);
962 break;
963 case CMD_GET_NETWORK_SELECTION_MODE:
964 request = (MainThreadRequest) msg.obj;
965 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
966 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
967 break;
968
969 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
970 ar = (AsyncResult) msg.obj;
971 request = (MainThreadRequest) ar.userObj;
972 if (ar.exception != null) {
973 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
974 } else {
975 int mode = ((int[]) ar.result)[0];
976 if (mode == 0) {
977 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
978 } else {
979 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
980 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000981 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700982 notifyRequester(request);
983 break;
984 case CMD_GET_CDMA_ROAMING_MODE:
985 request = (MainThreadRequest) msg.obj;
986 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
987 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
988 break;
989 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
992 if (ar.exception != null) {
993 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
994 } else {
995 request.result = ((int[]) ar.result)[0];
996 }
997 notifyRequester(request);
998 break;
999 case CMD_SET_CDMA_ROAMING_MODE:
1000 request = (MainThreadRequest) msg.obj;
1001 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1002 int mode = (int) request.argument;
1003 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1004 break;
1005 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1006 ar = (AsyncResult) msg.obj;
1007 request = (MainThreadRequest) ar.userObj;
1008 request.result = ar.exception == null;
1009 notifyRequester(request);
1010 break;
1011 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1012 request = (MainThreadRequest) msg.obj;
1013 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1014 int subscriptionMode = (int) request.argument;
1015 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1016 break;
1017 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1018 ar = (AsyncResult) msg.obj;
1019 request = (MainThreadRequest) ar.userObj;
1020 request.result = ar.exception == null;
1021 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001022 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001023 case CMD_GET_ALL_CELL_INFO:
1024 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001025 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001026 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001027 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001028 case EVENT_GET_ALL_CELL_INFO_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001031 // If a timeout occurs, the response will be null
1032 request.result = (ar.exception == null && ar.result != null)
1033 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001034 synchronized (request) {
1035 request.notifyAll();
1036 }
1037 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001038 case CMD_REQUEST_CELL_INFO_UPDATE:
1039 request = (MainThreadRequest) msg.obj;
1040 request.phone.requestCellInfoUpdate(request.workSource,
1041 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1042 break;
1043 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
1046 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1047 try {
1048 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001049 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001050 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1051 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001052 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001053 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001054 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001055 } else {
1056 // use the result as returned
1057 cb.onCellInfo((List<CellInfo>) ar.result);
1058 }
1059 } catch (RemoteException re) {
1060 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1061 }
1062 break;
1063 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 request = (MainThreadRequest) msg.obj;
1065 WorkSource ws = (WorkSource) request.argument;
1066 Phone phone = getPhoneFromRequest(request);
1067 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1068 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001069 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001070 ar = (AsyncResult) msg.obj;
1071 request = (MainThreadRequest) ar.userObj;
1072 if (ar.exception == null) {
1073 request.result = ar.result;
1074 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001076 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1077 ? new CdmaCellLocation() : new GsmCellLocation();
1078 }
1079
1080 synchronized (request) {
1081 request.notifyAll();
1082 }
1083 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001084 case CMD_MODEM_REBOOT:
1085 request = (MainThreadRequest) msg.obj;
1086 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001087 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001088 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001089 case EVENT_CMD_MODEM_REBOOT_DONE:
1090 handleNullReturnEvent(msg, "rebootModem");
1091 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001092 case CMD_REQUEST_ENABLE_MODEM:
1093 request = (MainThreadRequest) msg.obj;
1094 boolean enable = (boolean) request.argument;
1095 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
1096 PhoneConfigurationManager.getInstance()
1097 .enablePhone(request.phone, enable, onCompleted);
1098 break;
1099 case EVENT_ENABLE_MODEM_DONE:
1100 ar = (AsyncResult) msg.obj;
1101 request = (MainThreadRequest) ar.userObj;
1102 request.result = (ar.exception == null);
1103 notifyRequester(request);
1104 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001105 default:
1106 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1107 break;
1108 }
1109 }
Jake Hambye994d462014-02-03 13:10:13 -08001110
Pengquan Menga1bb6272018-09-06 09:59:22 -07001111 private void notifyRequester(MainThreadRequest request) {
1112 synchronized (request) {
1113 request.notifyAll();
1114 }
1115 }
1116
Jake Hambye994d462014-02-03 13:10:13 -08001117 private void handleNullReturnEvent(Message msg, String command) {
1118 AsyncResult ar = (AsyncResult) msg.obj;
1119 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1120 if (ar.exception == null) {
1121 request.result = true;
1122 } else {
1123 request.result = false;
1124 if (ar.exception instanceof CommandException) {
1125 loge(command + ": CommandException: " + ar.exception);
1126 } else {
1127 loge(command + ": Unknown exception");
1128 }
1129 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001130 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001132 }
1133
1134 /**
1135 * Posts the specified command to be executed on the main thread,
1136 * waits for the request to complete, and returns the result.
1137 * @see #sendRequestAsync
1138 */
1139 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001140 return sendRequest(
1141 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001142 }
1143
1144 /**
1145 * Posts the specified command to be executed on the main thread,
1146 * waits for the request to complete, and returns the result.
1147 * @see #sendRequestAsync
1148 */
1149 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1150 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001151 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001152 }
1153
1154 /**
1155 * Posts the specified command to be executed on the main thread,
1156 * waits for the request to complete, and returns the result.
1157 * @see #sendRequestAsync
1158 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001159 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001160 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001161 }
1162
1163 /**
1164 * Posts the specified command to be executed on the main thread,
1165 * waits for the request to complete, and returns the result.
1166 * @see #sendRequestAsync
1167 */
Nathan Harold92bed182018-10-12 18:16:49 -07001168 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1169 return sendRequest(command, argument, subId, null, workSource);
1170 }
1171
1172 /**
1173 * Posts the specified command to be executed on the main thread,
1174 * waits for the request to complete, and returns the result.
1175 * @see #sendRequestAsync
1176 */
1177 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1178 return sendRequest(
1179 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1180 }
1181
1182 /**
1183 * Posts the specified command to be executed on the main thread,
1184 * waits for the request to complete, and returns the result.
1185 * @see #sendRequestAsync
1186 */
1187 private Object sendRequest(
1188 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001189 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1190 throw new RuntimeException("This method will deadlock if called from the main thread.");
1191 }
1192
Nathan Harold92bed182018-10-12 18:16:49 -07001193 MainThreadRequest request = null;
1194 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1195 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1196 } else if (phone != null) {
1197 request = new MainThreadRequest(argument, phone, workSource);
1198 } else {
1199 request = new MainThreadRequest(argument, subId, workSource);
1200 }
1201
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001202 Message msg = mMainThreadHandler.obtainMessage(command, request);
1203 msg.sendToTarget();
1204
1205 // Wait for the request to complete
1206 synchronized (request) {
1207 while (request.result == null) {
1208 try {
1209 request.wait();
1210 } catch (InterruptedException e) {
1211 // Do nothing, go back and wait until the request is complete
1212 }
1213 }
1214 }
1215 return request.result;
1216 }
1217
1218 /**
1219 * Asynchronous ("fire and forget") version of sendRequest():
1220 * Posts the specified command to be executed on the main thread, and
1221 * returns immediately.
1222 * @see #sendRequest
1223 */
1224 private void sendRequestAsync(int command) {
1225 mMainThreadHandler.sendEmptyMessage(command);
1226 }
1227
1228 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001229 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001230 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001231 */
1232 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001233 sendRequestAsync(command, argument, null, null);
1234 }
1235
1236 /**
1237 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1238 * @see {@link #sendRequest(int,Object)}
1239 */
1240 private void sendRequestAsync(
1241 int command, Object argument, Phone phone, WorkSource workSource) {
1242 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001243 Message msg = mMainThreadHandler.obtainMessage(command, request);
1244 msg.sendToTarget();
1245 }
1246
1247 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 * Initialize the singleton PhoneInterfaceManager instance.
1249 * This is only done once, at startup, from PhoneApp.onCreate().
1250 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001251 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001252 synchronized (PhoneInterfaceManager.class) {
1253 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001254 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001255 } else {
1256 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1257 }
1258 return sInstance;
1259 }
1260 }
1261
1262 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001263 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001265 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001266 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001267 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1268 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001269 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001270 mTelephonySharedPreferences =
1271 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001272 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001273 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001274
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001275 publish();
1276 }
1277
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001278 private Phone getDefaultPhone() {
1279 Phone thePhone = getPhone(getDefaultSubscription());
1280 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1281 }
1282
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 private void publish() {
1284 if (DBG) log("publish: " + this);
1285
1286 ServiceManager.addService("phone", this);
1287 }
1288
Stuart Scott584921c2015-01-15 17:10:34 -08001289 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001290 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001291 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001292 }
1293
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001294 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1295 Phone phone = getPhoneFromRequest(request);
1296 return phone == null ? null :
1297 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1298 }
1299
Wink Saville36469e72014-06-11 15:17:00 -07001300 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001301 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001302 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304
1305 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001306 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001307 }
1308
Wink Savilleb564aae2014-10-23 10:18:09 -07001309 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001310 if (DBG) log("dial: " + number);
1311 // No permission check needed here: This is just a wrapper around the
1312 // ACTION_DIAL intent, which is available to any app since it puts up
1313 // the UI before it does anything.
1314
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001315 final long identity = Binder.clearCallingIdentity();
1316 try {
1317 String url = createTelUrl(number);
1318 if (url == null) {
1319 return;
1320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001322 // PENDING: should we just silently fail if phone is offhook or ringing?
1323 PhoneConstants.State state = mCM.getState(subId);
1324 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1325 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1326 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1327 mApp.startActivity(intent);
1328 }
1329 } finally {
1330 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 }
1332 }
1333
1334 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001335 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001336 }
1337
Wink Savilleb564aae2014-10-23 10:18:09 -07001338 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 if (DBG) log("call: " + number);
1340
1341 // This is just a wrapper around the ACTION_CALL intent, but we still
1342 // need to do a permission check since we're calling startActivity()
1343 // from the context of the phone app.
1344 enforceCallPermission();
1345
1346 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1347 != AppOpsManager.MODE_ALLOWED) {
1348 return;
1349 }
1350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001351 final long identity = Binder.clearCallingIdentity();
1352 try {
1353 String url = createTelUrl(number);
1354 if (url == null) {
1355 return;
1356 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001357
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001358 boolean isValid = false;
1359 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1360 if (slist != null) {
1361 for (SubscriptionInfo subInfoRecord : slist) {
1362 if (subInfoRecord.getSubscriptionId() == subId) {
1363 isValid = true;
1364 break;
1365 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001366 }
Wink Saville08874612014-08-31 19:19:58 -07001367 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001368 if (!isValid) {
1369 return;
1370 }
Wink Saville08874612014-08-31 19:19:58 -07001371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001372 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1373 intent.putExtra(SUBSCRIPTION_KEY, subId);
1374 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1375 mApp.startActivity(intent);
1376 } finally {
1377 Binder.restoreCallingIdentity(identity);
1378 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 }
1380
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001382 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001383 }
1384
Wink Savilleb564aae2014-10-23 10:18:09 -07001385 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001386 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001387 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1388 }
1389
1390 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001391 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001392 }
1393
Wink Savilleb564aae2014-10-23 10:18:09 -07001394 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001395 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001396 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1397 }
1398
1399 /** {@hide} */
1400 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001401 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001402 }
1403
Wink Savilleb564aae2014-10-23 10:18:09 -07001404 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001405 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001406
1407 final long identity = Binder.clearCallingIdentity();
1408 try {
1409 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1410 checkSimPin.start();
1411 return checkSimPin.unlockSim(null, pin);
1412 } finally {
1413 Binder.restoreCallingIdentity(identity);
1414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415 }
1416
Wink Saville9de0f752013-10-22 19:04:03 -07001417 /** {@hide} */
1418 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001419 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001420 }
1421
Wink Savilleb564aae2014-10-23 10:18:09 -07001422 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001423 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001424
1425 final long identity = Binder.clearCallingIdentity();
1426 try {
1427 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1428 checkSimPuk.start();
1429 return checkSimPuk.unlockSim(puk, pin);
1430 } finally {
1431 Binder.restoreCallingIdentity(identity);
1432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001433 }
1434
1435 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001436 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001437 * a synchronous one.
1438 */
1439 private static class UnlockSim extends Thread {
1440
1441 private final IccCard mSimCard;
1442
1443 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001444 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1445 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001446
1447 // For replies from SimCard interface
1448 private Handler mHandler;
1449
1450 // For async handler to identify request type
1451 private static final int SUPPLY_PIN_COMPLETE = 100;
1452
1453 public UnlockSim(IccCard simCard) {
1454 mSimCard = simCard;
1455 }
1456
1457 @Override
1458 public void run() {
1459 Looper.prepare();
1460 synchronized (UnlockSim.this) {
1461 mHandler = new Handler() {
1462 @Override
1463 public void handleMessage(Message msg) {
1464 AsyncResult ar = (AsyncResult) msg.obj;
1465 switch (msg.what) {
1466 case SUPPLY_PIN_COMPLETE:
1467 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1468 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001469 mRetryCount = msg.arg1;
1470 if (ar.exception != null) {
1471 if (ar.exception instanceof CommandException &&
1472 ((CommandException)(ar.exception)).getCommandError()
1473 == CommandException.Error.PASSWORD_INCORRECT) {
1474 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1475 } else {
1476 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1477 }
1478 } else {
1479 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 mDone = true;
1482 UnlockSim.this.notifyAll();
1483 }
1484 break;
1485 }
1486 }
1487 };
1488 UnlockSim.this.notifyAll();
1489 }
1490 Looper.loop();
1491 }
1492
1493 /*
1494 * Use PIN or PUK to unlock SIM card
1495 *
1496 * If PUK is null, unlock SIM card with PIN
1497 *
1498 * If PUK is not null, unlock SIM card with PUK and set PIN code
1499 */
Wink Saville9de0f752013-10-22 19:04:03 -07001500 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501
1502 while (mHandler == null) {
1503 try {
1504 wait();
1505 } catch (InterruptedException e) {
1506 Thread.currentThread().interrupt();
1507 }
1508 }
1509 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1510
1511 if (puk == null) {
1512 mSimCard.supplyPin(pin, callback);
1513 } else {
1514 mSimCard.supplyPuk(puk, pin, callback);
1515 }
1516
1517 while (!mDone) {
1518 try {
1519 Log.d(LOG_TAG, "wait for done");
1520 wait();
1521 } catch (InterruptedException e) {
1522 // Restore the interrupted status
1523 Thread.currentThread().interrupt();
1524 }
1525 }
1526 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001527 int[] resultArray = new int[2];
1528 resultArray[0] = mResult;
1529 resultArray[1] = mRetryCount;
1530 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 }
1532 }
1533
1534 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001535 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001536
1537 }
1538
Wink Savilleb564aae2014-10-23 10:18:09 -07001539 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001540 // No permission check needed here: this call is harmless, and it's
1541 // needed for the ServiceState.requestStateUpdate() call (which is
1542 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001543 final long identity = Binder.clearCallingIdentity();
1544 try {
1545 final Phone phone = getPhone(subId);
1546 if (phone != null) {
1547 phone.updateServiceLocation();
1548 }
1549 } finally {
1550 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001552 }
1553
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001554 @Override
1555 public boolean isRadioOn(String callingPackage) {
1556 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001557 }
1558
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001559 @Override
1560 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001561 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001562 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001563 return false;
1564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001565
1566 final long identity = Binder.clearCallingIdentity();
1567 try {
1568 return isRadioOnForSubscriber(subId);
1569 } finally {
1570 Binder.restoreCallingIdentity(identity);
1571 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001572 }
1573
1574 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001575 final long identity = Binder.clearCallingIdentity();
1576 try {
1577 final Phone phone = getPhone(subId);
1578 if (phone != null) {
1579 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1580 } else {
1581 return false;
1582 }
1583 } finally {
1584 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 }
1587
1588 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001589 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 }
Wink Saville36469e72014-06-11 15:17:00 -07001591
Wink Savilleb564aae2014-10-23 10:18:09 -07001592 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001594
1595 final long identity = Binder.clearCallingIdentity();
1596 try {
1597 final Phone phone = getPhone(subId);
1598 if (phone != null) {
1599 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1600 }
1601 } finally {
1602 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001603 }
Wink Saville36469e72014-06-11 15:17:00 -07001604 }
1605
1606 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001607 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001608 }
1609
Wink Savilleb564aae2014-10-23 10:18:09 -07001610 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001611 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001612
1613 final long identity = Binder.clearCallingIdentity();
1614 try {
1615 final Phone phone = getPhone(subId);
1616 if (phone == null) {
1617 return false;
1618 }
1619 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1620 toggleRadioOnOffForSubscriber(subId);
1621 }
1622 return true;
1623 } finally {
1624 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001625 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001626 }
Wink Saville36469e72014-06-11 15:17:00 -07001627
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001628 public boolean needMobileRadioShutdown() {
1629 /*
1630 * If any of the Radios are available, it will need to be
1631 * shutdown. So return true if any Radio is available.
1632 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001633 final long identity = Binder.clearCallingIdentity();
1634 try {
1635 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1636 Phone phone = PhoneFactory.getPhone(i);
1637 if (phone != null && phone.isRadioAvailable()) return true;
1638 }
1639 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1640 return false;
1641 } finally {
1642 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001643 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001644 }
1645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001646 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001647 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001648 enforceModifyPermission();
1649
1650 final long identity = Binder.clearCallingIdentity();
1651 try {
1652 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1653 logv("Shutting down Phone " + i);
1654 shutdownRadioUsingPhoneId(i);
1655 }
1656 } finally {
1657 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001658 }
1659 }
1660
1661 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001662 Phone phone = PhoneFactory.getPhone(phoneId);
1663 if (phone != null && phone.isRadioAvailable()) {
1664 phone.shutdownRadio();
1665 }
1666 }
1667
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001669 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001670
1671 final long identity = Binder.clearCallingIdentity();
1672 try {
1673 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1674 if (defaultPhone != null) {
1675 defaultPhone.setRadioPower(turnOn);
1676 return true;
1677 } else {
1678 loge("There's no default phone.");
1679 return false;
1680 }
1681 } finally {
1682 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001683 }
Wink Saville36469e72014-06-11 15:17:00 -07001684 }
1685
Wink Savilleb564aae2014-10-23 10:18:09 -07001686 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001688
1689 final long identity = Binder.clearCallingIdentity();
1690 try {
1691 final Phone phone = getPhone(subId);
1692 if (phone != null) {
1693 phone.setRadioPower(turnOn);
1694 return true;
1695 } else {
1696 return false;
1697 }
1698 } finally {
1699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 }
1702
Wink Saville36469e72014-06-11 15:17:00 -07001703 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 public boolean enableDataConnectivity() {
1706 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001707
1708 final long identity = Binder.clearCallingIdentity();
1709 try {
1710 int subId = mSubscriptionController.getDefaultDataSubId();
1711 final Phone phone = getPhone(subId);
1712 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001713 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001714 return true;
1715 } else {
1716 return false;
1717 }
1718 } finally {
1719 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001721 }
1722
Wink Saville36469e72014-06-11 15:17:00 -07001723 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 public boolean disableDataConnectivity() {
1726 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001727
1728 final long identity = Binder.clearCallingIdentity();
1729 try {
1730 int subId = mSubscriptionController.getDefaultDataSubId();
1731 final Phone phone = getPhone(subId);
1732 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001733 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001734 return true;
1735 } else {
1736 return false;
1737 }
1738 } finally {
1739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 }
1742
Sanket Padawe356d7632015-06-22 14:03:32 -07001743 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001744 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001745 final long identity = Binder.clearCallingIdentity();
1746 try {
1747 final Phone phone = getPhone(subId);
1748 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001749 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001750 } else {
1751 return false;
1752 }
1753 } finally {
1754 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001755 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 }
1757
1758 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001759 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001760 }
1761
pkanwarae03a6b2016-11-06 20:37:09 -08001762 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001763 enforceCallPermission();
1764
1765 final long identity = Binder.clearCallingIdentity();
1766 try {
1767 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1768 return;
1769 }
1770 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1771 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1772 } finally {
1773 Binder.restoreCallingIdentity(identity);
1774 }
pkanwar32d516d2016-10-14 19:37:38 -07001775 };
1776
Wink Savilleb564aae2014-10-23 10:18:09 -07001777 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001779
1780 final long identity = Binder.clearCallingIdentity();
1781 try {
1782 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1783 return false;
1784 }
1785 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1786 } finally {
1787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
1790
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001792 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001793 }
1794
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001795 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001796 final long identity = Binder.clearCallingIdentity();
1797 try {
1798 Phone phone = PhoneFactory.getPhone(slotIndex);
1799 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1800 PhoneConstantConversions.convertCallState(phone.getState());
1801 } finally {
1802 Binder.restoreCallingIdentity(identity);
1803 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 }
1805
Sanket Padawe356d7632015-06-22 14:03:32 -07001806 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001808 final long identity = Binder.clearCallingIdentity();
1809 try {
1810 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1811 if (phone != null) {
1812 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1813 } else {
1814 return PhoneConstantConversions.convertDataState(
1815 PhoneConstants.DataState.DISCONNECTED);
1816 }
1817 } finally {
1818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 }
1821
Sanket Padawe356d7632015-06-22 14:03:32 -07001822 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001824 final long identity = Binder.clearCallingIdentity();
1825 try {
1826 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1827 if (phone != null) {
1828 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1829 } else {
1830 return TelephonyManager.DATA_ACTIVITY_NONE;
1831 }
1832 } finally {
1833 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001834 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001835 }
1836
1837 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001838 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001839 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001840 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001841 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1842 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001843 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001844 }
1845
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001846 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001847 final long identity = Binder.clearCallingIdentity();
1848 try {
1849 if (DBG_LOC) log("getCellLocation: is active user");
1850 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001851 int subId = mSubscriptionController.getDefaultDataSubId();
1852 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1853 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001854 return data;
1855 } finally {
1856 Binder.restoreCallingIdentity(identity);
1857 }
Svetoslav64fad262015-04-14 14:35:21 -07001858 }
1859
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001861 public String getNetworkCountryIsoForPhone(int phoneId) {
1862 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1863 // registered cell info, so return a NULL country instead.
1864 final long identity = Binder.clearCallingIdentity();
1865 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001866 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1867 // Get default phone in this case.
1868 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1869 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001870 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001871 // Todo: fix this when we can get the actual cellular network info when the device
1872 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001873 if (TelephonyManager.NETWORK_TYPE_IWLAN
1874 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1875 return "";
1876 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001877 Phone phone = PhoneFactory.getPhone(phoneId);
1878 if (phone != null) {
1879 ServiceStateTracker sst = phone.getServiceStateTracker();
1880 if (sst != null) {
1881 LocaleTracker lt = sst.getLocaleTracker();
1882 if (lt != null) {
1883 return lt.getCurrentCountry();
1884 }
1885 }
1886 }
1887 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001888 } finally {
1889 Binder.restoreCallingIdentity(identity);
1890 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001891 }
1892
1893 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001895 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001896 }
1897
Sanket Padawe356d7632015-06-22 14:03:32 -07001898 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001899 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001900 mApp.enforceCallingOrSelfPermission(
1901 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001902
1903 final long identity = Binder.clearCallingIdentity();
1904 try {
1905 final Phone phone = getPhone(subId);
1906 if (phone != null) {
1907 phone.enableLocationUpdates();
1908 }
1909 } finally {
1910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001912 }
1913
1914 @Override
1915 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001916 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001917 }
1918
Sanket Padawe356d7632015-06-22 14:03:32 -07001919 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001920 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 mApp.enforceCallingOrSelfPermission(
1922 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001923
1924 final long identity = Binder.clearCallingIdentity();
1925 try {
1926 final Phone phone = getPhone(subId);
1927 if (phone != null) {
1928 phone.disableLocationUpdates();
1929 }
1930 } finally {
1931 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 }
1934
Nathan Harold31d7ff32018-10-15 20:20:30 -07001935 /**
1936 * Returns the target SDK version number for a given package name.
1937 *
1938 * @return target SDK if the package is found or INT_MAX.
1939 */
1940 private int getTargetSdk(String packageName) {
1941 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001942 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1943 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001944 if (ai != null) return ai.targetSdkVersion;
1945 } catch (PackageManager.NameNotFoundException unexpected) {
1946 }
1947 return Integer.MAX_VALUE;
1948 }
1949
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 @Override
1951 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001952 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1953 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001954 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1955 throw new SecurityException(
1956 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1957 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001958
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1960 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1961 return null;
1962 }
Svetoslav64fad262015-04-14 14:35:21 -07001963
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001964 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001965
Nathan Haroldf180aac2018-06-01 18:43:55 -07001966 List<CellInfo> info = getAllCellInfo(callingPackage);
1967 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968
Nathan Haroldf180aac2018-06-01 18:43:55 -07001969 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1970 for (CellInfo ci : info) {
1971 if (ci instanceof CellInfoGsm) {
1972 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1973 } else if (ci instanceof CellInfoWcdma) {
1974 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1975 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001977 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 }
1979
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001980 private List<CellInfo> getCachedCellInfo() {
1981 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1982 for (Phone phone : PhoneFactory.getPhones()) {
1983 List<CellInfo> info = phone.getAllCellInfo();
1984 if (info != null) cellInfos.addAll(info);
1985 }
1986 return cellInfos;
1987 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988
1989 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001990 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001991 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001992 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001993 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001994 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001995 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 }
1997
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001998 final int targetSdk = getTargetSdk(callingPackage);
1999 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2000 return getCachedCellInfo();
2001 }
2002
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002003 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002004 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002005 final long identity = Binder.clearCallingIdentity();
2006 try {
2007 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2008 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002009 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002010 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002011 if (info != null) cellInfos.addAll(info);
2012 }
2013 return cellInfos;
2014 } finally {
2015 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 }
2017 }
2018
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002019 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002020 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2021 requestCellInfoUpdateInternal(
2022 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2023 }
2024
2025 @Override
2026 public void requestCellInfoUpdateWithWorkSource(
2027 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2028 enforceModifyPermission();
2029 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2030 }
2031
2032 private void requestCellInfoUpdateInternal(
2033 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002034 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002035 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002036 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2037 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002038 return;
2039 }
2040
2041 final Phone phone = getPhone(subId);
2042 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2043
2044 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2045 }
2046
2047 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002049 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002050 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002051
2052 final long identity = Binder.clearCallingIdentity();
2053 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002054 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002055 } finally {
2056 Binder.restoreCallingIdentity(identity);
2057 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 }
2059
Shishir Agrawala9f32182016-04-12 12:00:16 -07002060 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002061 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002062 Phone phone = PhoneFactory.getPhone(slotIndex);
2063 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002064 return null;
2065 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002066 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002067 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2068 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002069 return null;
2070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002071
2072 final long identity = Binder.clearCallingIdentity();
2073 try {
2074 return phone.getImei();
2075 } finally {
2076 Binder.restoreCallingIdentity(identity);
2077 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002078 }
2079
2080 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002081 public String getTypeAllocationCodeForSlot(int slotIndex) {
2082 Phone phone = PhoneFactory.getPhone(slotIndex);
2083 String tac = null;
2084 if (phone != null) {
2085 String imei = phone.getImei();
2086 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2087 }
2088 return tac;
2089 }
2090
2091 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002092 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002093 Phone phone = PhoneFactory.getPhone(slotIndex);
2094 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002095 return null;
2096 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002097
Jeff Davidson913390f2018-02-23 17:11:49 -08002098 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002099 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2100 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002101 return null;
2102 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002103
2104 final long identity = Binder.clearCallingIdentity();
2105 try {
2106 return phone.getMeid();
2107 } finally {
2108 Binder.restoreCallingIdentity(identity);
2109 }
Jack Yu2af8d712017-03-15 17:14:14 -07002110 }
2111
2112 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002113 public String getManufacturerCodeForSlot(int slotIndex) {
2114 Phone phone = PhoneFactory.getPhone(slotIndex);
2115 String manufacturerCode = null;
2116 if (phone != null) {
2117 String meid = phone.getMeid();
2118 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2119 }
2120 return manufacturerCode;
2121 }
2122
2123 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002124 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002125 Phone phone = PhoneFactory.getPhone(slotIndex);
2126 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002127 return null;
2128 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002129 int subId = phone.getSubId();
2130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2131 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2132 return null;
2133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002134
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 return phone.getDeviceSvn();
2138 } finally {
2139 Binder.restoreCallingIdentity(identity);
2140 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002141 }
2142
fionaxu43304da2017-11-27 22:51:16 -08002143 @Override
2144 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002145 final long identity = Binder.clearCallingIdentity();
2146 try {
2147 final Phone phone = getPhone(subId);
2148 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2149 } finally {
2150 Binder.restoreCallingIdentity(identity);
2151 }
fionaxu43304da2017-11-27 22:51:16 -08002152 }
2153
2154 @Override
2155 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002156 final long identity = Binder.clearCallingIdentity();
2157 try {
2158 final Phone phone = getPhone(subId);
2159 return phone == null ? null : phone.getCarrierName();
2160 } finally {
2161 Binder.restoreCallingIdentity(identity);
2162 }
fionaxu43304da2017-11-27 22:51:16 -08002163 }
2164
calvinpanffe225e2018-11-01 19:43:06 +08002165 @Override
chen xu25637222018-11-04 17:17:00 -08002166 public int getSubscriptionPreciseCarrierId(int subId) {
2167 final long identity = Binder.clearCallingIdentity();
2168 try {
2169 final Phone phone = getPhone(subId);
2170 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2171 : phone.getPreciseCarrierId();
2172 } finally {
2173 Binder.restoreCallingIdentity(identity);
2174 }
2175 }
2176
2177 @Override
2178 public String getSubscriptionPreciseCarrierName(int subId) {
2179 final long identity = Binder.clearCallingIdentity();
2180 try {
2181 final Phone phone = getPhone(subId);
2182 return phone == null ? null : phone.getPreciseCarrierName();
2183 } finally {
2184 Binder.restoreCallingIdentity(identity);
2185 }
2186 }
2187
chen xu651eec72018-11-11 19:03:44 -08002188 @Override
chen xu864e11c2018-12-06 22:10:03 -08002189 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2190 if (!isSubscriptionMccMnc) {
2191 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2192 }
chen xu651eec72018-11-11 19:03:44 -08002193 final Phone phone = PhoneFactory.getPhone(slotIndex);
2194 if (phone == null) {
2195 return TelephonyManager.UNKNOWN_CARRIER_ID;
2196 }
2197 final long identity = Binder.clearCallingIdentity();
2198 try {
2199 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2200 } finally {
2201 Binder.restoreCallingIdentity(identity);
2202 }
2203 }
2204
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002205 //
2206 // Internal helper methods.
2207 //
2208
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002209 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2211 *
2212 * @throws SecurityException if the caller does not have the required permission
2213 */
2214 private void enforceModifyPermission() {
2215 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2216 }
2217
2218 /**
2219 * Make sure the caller has the CALL_PHONE permission.
2220 *
2221 * @throws SecurityException if the caller does not have the required permission
2222 */
2223 private void enforceCallPermission() {
2224 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2225 }
2226
Stuart Scott8eef64f2015-04-08 15:13:54 -07002227 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002228 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002229 "ConnectivityService");
2230 }
2231
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 private String createTelUrl(String number) {
2233 if (TextUtils.isEmpty(number)) {
2234 return null;
2235 }
2236
Jake Hambye994d462014-02-03 13:10:13 -08002237 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 }
2239
Ihab Awadf9e92732013-12-05 18:02:52 -08002240 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2242 }
2243
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002244 private static void logv(String msg) {
2245 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2246 }
2247
Ihab Awadf9e92732013-12-05 18:02:52 -08002248 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2250 }
2251
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002252 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002254 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002255 }
2256
Sanket Padawe356d7632015-06-22 14:03:32 -07002257 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002258 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002259 final long identity = Binder.clearCallingIdentity();
2260 try {
2261 final Phone phone = PhoneFactory.getPhone(slotIndex);
2262 if (phone == null) {
2263 return PhoneConstants.PHONE_TYPE_NONE;
2264 } else {
2265 return phone.getPhoneType();
2266 }
2267 } finally {
2268 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 }
2271
2272 /**
2273 * Returns the CDMA ERI icon index to display
2274 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002275 @Override
2276 public int getCdmaEriIconIndex(String callingPackage) {
2277 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002278 }
2279
Sanket Padawe356d7632015-06-22 14:03:32 -07002280 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002281 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002283 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002284 return -1;
2285 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286
2287 final long identity = Binder.clearCallingIdentity();
2288 try {
2289 final Phone phone = getPhone(subId);
2290 if (phone != null) {
2291 return phone.getCdmaEriIconIndex();
2292 } else {
2293 return -1;
2294 }
2295 } finally {
2296 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 }
2299
2300 /**
2301 * Returns the CDMA ERI icon mode,
2302 * 0 - ON
2303 * 1 - FLASHING
2304 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002305 @Override
2306 public int getCdmaEriIconMode(String callingPackage) {
2307 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002308 }
2309
Sanket Padawe356d7632015-06-22 14:03:32 -07002310 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002311 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002313 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002314 return -1;
2315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002316
2317 final long identity = Binder.clearCallingIdentity();
2318 try {
2319 final Phone phone = getPhone(subId);
2320 if (phone != null) {
2321 return phone.getCdmaEriIconMode();
2322 } else {
2323 return -1;
2324 }
2325 } finally {
2326 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002328 }
2329
2330 /**
2331 * Returns the CDMA ERI text,
2332 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002333 @Override
2334 public String getCdmaEriText(String callingPackage) {
2335 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002336 }
2337
Sanket Padawe356d7632015-06-22 14:03:32 -07002338 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002339 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002341 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002342 return null;
2343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344
2345 final long identity = Binder.clearCallingIdentity();
2346 try {
2347 final Phone phone = getPhone(subId);
2348 if (phone != null) {
2349 return phone.getCdmaEriText();
2350 } else {
2351 return null;
2352 }
2353 } finally {
2354 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 }
2357
2358 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002359 * Returns the CDMA MDN.
2360 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002361 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002362 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2364 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002365
2366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002369 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002370 return phone.getLine1Number();
2371 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002372 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002373 return null;
2374 }
2375 } finally {
2376 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002377 }
2378 }
2379
2380 /**
2381 * Returns the CDMA MIN.
2382 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002383 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002384 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2386 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387
2388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 final Phone phone = getPhone(subId);
2391 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2392 return phone.getCdmaMin();
2393 } else {
2394 return null;
2395 }
2396 } finally {
2397 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002398 }
2399 }
2400
Hall Liud892bec2018-11-30 14:51:45 -08002401 @Override
2402 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2403 INumberVerificationCallback callback, String callingPackage) {
2404 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2405 != PERMISSION_GRANTED) {
2406 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2407 }
2408 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2409
2410 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2411 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2412 throw new SecurityException("Calling package must be configured in the device config");
2413 }
2414
2415 if (range == null) {
2416 throw new NullPointerException("Range must be non-null");
2417 }
2418
2419 timeoutMillis = Math.min(timeoutMillis,
2420 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2421
2422 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2423 }
2424
Junda Liuca05d5d2014-08-14 22:36:34 -07002425 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 * Returns true if CDMA provisioning needs to run.
2427 */
2428 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002429 final long identity = Binder.clearCallingIdentity();
2430 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002431 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002432 } finally {
2433 Binder.restoreCallingIdentity(identity);
2434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 }
2436
2437 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002438 * Sets the voice mail number of a given subId.
2439 */
2440 @Override
2441 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002442 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002443
2444 final long identity = Binder.clearCallingIdentity();
2445 try {
2446 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2447 new Pair<String, String>(alphaTag, number), new Integer(subId));
2448 return success;
2449 } finally {
2450 Binder.restoreCallingIdentity(identity);
2451 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002452 }
2453
Ta-wei Yen87c49842016-05-13 21:19:52 -07002454 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002455 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2456 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002457 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002458 if (!TextUtils.equals(callingPackage, systemDialer)) {
2459 throw new SecurityException("caller must be system dialer");
2460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002461
2462 final long identity = Binder.clearCallingIdentity();
2463 try {
2464 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2465 if (phoneAccountHandle == null) {
2466 return null;
2467 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002468 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469 } finally {
2470 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002471 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002472 }
2473
2474 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002475 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002476 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002478 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002479 return null;
2480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002482 final long identity = Binder.clearCallingIdentity();
2483 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002484 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002485 } finally {
2486 Binder.restoreCallingIdentity(identity);
2487 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002488 }
2489
2490 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002491 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2492 VisualVoicemailSmsFilterSettings settings) {
2493 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002494
2495 final long identity = Binder.clearCallingIdentity();
2496 try {
2497 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002498 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499 } finally {
2500 Binder.restoreCallingIdentity(identity);
2501 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002502 }
2503
2504 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002505 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2506 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507
2508 final long identity = Binder.clearCallingIdentity();
2509 try {
2510 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002511 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 } finally {
2513 Binder.restoreCallingIdentity(identity);
2514 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002515 }
2516
2517 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002518 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2519 String callingPackage, int subId) {
2520 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002521
2522 final long identity = Binder.clearCallingIdentity();
2523 try {
2524 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002525 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002526 } finally {
2527 Binder.restoreCallingIdentity(identity);
2528 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002529 }
2530
2531 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002532 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002533 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002534
2535 final long identity = Binder.clearCallingIdentity();
2536 try {
2537 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002538 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002539 } finally {
2540 Binder.restoreCallingIdentity(identity);
2541 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002542 }
2543
2544 @Override
2545 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2546 String number, int port, String text, PendingIntent sentIntent) {
2547 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002548 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002549 enforceSendSmsPermission();
2550 // Make the calls as the phone process.
2551 final long identity = Binder.clearCallingIdentity();
2552 try {
2553 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2554 if (port == 0) {
2555 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2556 sentIntent, null, false);
2557 } else {
2558 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2559 smsManager.sendDataMessageWithSelfPermissions(number, null,
2560 (short) port, data, sentIntent, null);
2561 }
2562 } finally {
2563 Binder.restoreCallingIdentity(identity);
2564 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002565 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002566 /**
fionaxu0152e512016-11-14 13:36:14 -08002567 * Sets the voice activation state of a given subId.
2568 */
2569 @Override
2570 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2572 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573
2574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 final Phone phone = getPhone(subId);
2577 if (phone != null) {
2578 phone.setVoiceActivationState(activationState);
2579 } else {
2580 loge("setVoiceActivationState fails with invalid subId: " + subId);
2581 }
2582 } finally {
2583 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002584 }
2585 }
2586
2587 /**
2588 * Sets the data activation state of a given subId.
2589 */
2590 @Override
2591 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2593 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002594
2595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 final Phone phone = getPhone(subId);
2598 if (phone != null) {
2599 phone.setDataActivationState(activationState);
2600 } else {
2601 loge("setVoiceActivationState fails with invalid subId: " + subId);
2602 }
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002605 }
2606 }
2607
2608 /**
2609 * Returns the voice activation state of a given subId.
2610 */
2611 @Override
2612 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002613 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614
fionaxu0152e512016-11-14 13:36:14 -08002615 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 if (phone != null) {
2619 return phone.getVoiceActivationState();
2620 } else {
2621 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2622 }
2623 } finally {
2624 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002625 }
2626 }
2627
2628 /**
2629 * Returns the data activation state of a given subId.
2630 */
2631 @Override
2632 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002633 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634
fionaxu0152e512016-11-14 13:36:14 -08002635 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 if (phone != null) {
2639 return phone.getDataActivationState();
2640 } else {
2641 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2642 }
2643 } finally {
2644 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002645 }
2646 }
2647
2648 /**
Wink Saville36469e72014-06-11 15:17:00 -07002649 * Returns the unread count of voicemails for a subId
2650 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002651 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002652 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2653 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2654 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2655 return 0;
2656 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 final Phone phone = getPhone(subId);
2660 if (phone != null) {
2661 return phone.getVoiceMessageCount();
2662 } else {
2663 return 0;
2664 }
2665 } finally {
2666 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002667 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668 }
2669
2670 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002671 * returns true, if the device is in a state where both voice and data
2672 * are supported simultaneously. This can change based on location or network condition.
2673 */
2674 @Override
2675 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676 final long identity = Binder.clearCallingIdentity();
2677 try {
2678 final Phone phone = getPhone(subId);
2679 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2680 } finally {
2681 Binder.restoreCallingIdentity(identity);
2682 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002683 }
2684
2685 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002686 * Send the dialer code if called from the current default dialer or the caller has
2687 * carrier privilege.
2688 * @param inputCode The dialer code to send
2689 */
2690 @Override
2691 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002692 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002693 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002694 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2695 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002696 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002697 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2698 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002699 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700
2701 final long identity = Binder.clearCallingIdentity();
2702 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002703 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704 } finally {
2705 Binder.restoreCallingIdentity(identity);
2706 }
fionaxu235cc5e2017-03-06 22:25:57 -08002707 }
2708
2709 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002710 * Returns the data network type.
2711 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002712 *
2713 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2714 */
2715 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002716 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 final long identity = Binder.clearCallingIdentity();
2718 try {
2719 final Phone phone = getPhone(getDefaultSubscription());
2720 if (phone != null) {
2721 return phone.getServiceState().getDataNetworkType();
2722 } else {
2723 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2724 }
2725 } finally {
2726 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002727 }
Wink Saville36469e72014-06-11 15:17:00 -07002728 }
2729
Pengquan Menga1bb6272018-09-06 09:59:22 -07002730 @Override
2731 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002732 if (!isActiveSubscription(subId)) {
2733 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2734 }
2735
Pengquan Menga1bb6272018-09-06 09:59:22 -07002736 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2737 }
2738
Brad Ebinger35c841c2018-10-01 10:40:55 -07002739 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002740 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2741 throws RemoteException {
2742 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002743 final long token = Binder.clearCallingIdentity();
2744 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002745 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002746 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002747 .addRegistrationCallbackForSubscription(c, subId);
2748 } finally {
2749 Binder.restoreCallingIdentity(token);
2750 }
2751 }
2752
2753 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002754 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2755 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002756 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2757 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2758 }
2759 Binder.withCleanCallingIdentity(() -> {
2760 try {
2761 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002762 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002763 .removeRegistrationCallbackForSubscription(c, subId);
2764 } catch (IllegalArgumentException e) {
2765 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2766 + "is inactive, ignoring unregister.");
2767 // If the subscription is no longer active, just return, since the callback
2768 // will already have been removed internally.
2769 }
2770 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002771 }
2772
2773 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002774 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2775 throws RemoteException {
2776 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002777 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2778 final long token = Binder.clearCallingIdentity();
2779 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002780 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002781 .addCapabilitiesCallbackForSubscription(c, subId);
2782 } finally {
2783 Binder.restoreCallingIdentity(token);
2784 }
2785 }
2786
2787 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002788 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2789 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002790
2791 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2792 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2793 }
2794 Binder.withCleanCallingIdentity(() -> {
2795 try {
2796 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002797 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002798 .removeCapabilitiesCallbackForSubscription(c, subId);
2799 } catch (IllegalArgumentException e) {
2800 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2801 + "is inactive, ignoring unregister.");
2802 // If the subscription is no longer active, just return, since the callback
2803 // will already have been removed internally.
2804 }
2805 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002806 }
2807
2808 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002809 public boolean isCapable(int subId, int capability, int regTech) {
2810 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002811 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2812 final long token = Binder.clearCallingIdentity();
2813 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002814 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002815 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2816 } catch (ImsException e) {
2817 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2818 return false;
2819 } finally {
2820 Binder.restoreCallingIdentity(token);
2821 }
2822 }
2823
2824 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002825 public boolean isAvailable(int subId, int capability, int regTech) {
2826 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002827 final long token = Binder.clearCallingIdentity();
2828 try {
2829 Phone phone = getPhone(subId);
2830 if (phone == null) return false;
2831 return phone.isImsCapabilityAvailable(capability, regTech);
2832 } finally {
2833 Binder.restoreCallingIdentity(token);
2834 }
2835 }
2836
2837 @Override
2838 public boolean isAdvancedCallingSettingEnabled(int subId) {
2839 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2841 final long token = Binder.clearCallingIdentity();
2842 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002843 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002844 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2845 } finally {
2846 Binder.restoreCallingIdentity(token);
2847 }
2848 }
2849
2850 @Override
2851 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2853 "setAdvancedCallingSetting");
2854 final long identity = Binder.clearCallingIdentity();
2855 try {
2856 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002857 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002858 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2859 } finally {
2860 Binder.restoreCallingIdentity(identity);
2861 }
2862 }
2863
2864 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002865 public boolean isVtSettingEnabled(int subId) {
2866 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002870 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002871 getSlotIndexOrException(subId)).isVtEnabledByUser();
2872 } finally {
2873 Binder.restoreCallingIdentity(identity);
2874 }
2875 }
2876
2877 @Override
2878 public void setVtSetting(int subId, boolean isEnabled) {
2879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2880 "setVtSetting");
2881 final long identity = Binder.clearCallingIdentity();
2882 try {
2883 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002884 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002885 } finally {
2886 Binder.restoreCallingIdentity(identity);
2887 }
2888 }
2889
2890 @Override
2891 public boolean isVoWiFiSettingEnabled(int subId) {
2892 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2893 final long identity = Binder.clearCallingIdentity();
2894 try {
2895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002896 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002897 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
2900 }
2901 }
2902
2903 @Override
2904 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2906 "setVoWiFiSetting");
2907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002910 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002911 } finally {
2912 Binder.restoreCallingIdentity(identity);
2913 }
2914 }
2915
2916 @Override
2917 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2918 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002922 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002923 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
2926 }
2927 }
2928
2929 @Override
2930 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2932 "setVoWiFiRoamingSetting");
2933 final long identity = Binder.clearCallingIdentity();
2934 try {
2935 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002936 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002937 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
2940 }
2941 }
2942
2943 @Override
2944 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2946 "setVoWiFiNonPersistent");
2947 final long identity = Binder.clearCallingIdentity();
2948 try {
2949 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08002950 boolean isRoaming = TelephonyManager.from(
2951 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002952 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08002953 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002954 } finally {
2955 Binder.restoreCallingIdentity(identity);
2956 }
2957 }
2958
2959 @Override
2960 public int getVoWiFiModeSetting(int subId) {
2961 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2962 final long identity = Binder.clearCallingIdentity();
2963 try {
2964 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002965 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002966 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
2970 }
2971
2972 @Override
2973 public void setVoWiFiModeSetting(int subId, int mode) {
2974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2975 "setVoWiFiModeSetting");
2976 final long identity = Binder.clearCallingIdentity();
2977 try {
2978 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002979 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002980 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2981 } finally {
2982 Binder.restoreCallingIdentity(identity);
2983 }
2984 }
2985
2986 @Override
2987 public int getVoWiFiRoamingModeSetting(int subId) {
2988 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2989 final long identity = Binder.clearCallingIdentity();
2990 try {
2991 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002992 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002993 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2994 } finally {
2995 Binder.restoreCallingIdentity(identity);
2996 }
2997 }
2998
2999 @Override
3000 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3002 "setVoWiFiRoamingModeSetting");
3003 final long identity = Binder.clearCallingIdentity();
3004 try {
3005 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003006 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003007 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
3011 }
3012
3013 @Override
3014 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3016 "setRttCapabilityEnabled");
3017 final long identity = Binder.clearCallingIdentity();
3018 try {
3019 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003020 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003021 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3022 } finally {
3023 Binder.restoreCallingIdentity(identity);
3024 }
3025 }
3026
3027 @Override
3028 public boolean isTtyOverVolteEnabled(int subId) {
3029 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3030 final long identity = Binder.clearCallingIdentity();
3031 try {
3032 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003033 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003034 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3035 } finally {
3036 Binder.restoreCallingIdentity(identity);
3037 }
3038 }
3039
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003040 @Override
3041 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3042 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003046 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003047 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003048 } finally {
3049 Binder.restoreCallingIdentity(identity);
3050 }
3051 }
3052
3053 @Override
3054 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3055 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3056 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003057 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3058 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3059 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003060 try {
3061 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003062 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003063 .removeProvisioningCallbackForSubscription(callback, subId);
3064 } catch (IllegalArgumentException e) {
3065 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3066 + "is inactive, ignoring unregister.");
3067 // If the subscription is no longer active, just return, since the callback will already
3068 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
3072 }
3073
3074 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003075 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3076 boolean isProvisioned) {
3077 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3078 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3079 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3080 }
3081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3082 "setProvisioningStatusForCapability");
3083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3086 Phone phone = getPhone(subId);
3087 if (phone == null) {
3088 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3089 + subId);
3090 return;
3091 }
3092 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3093 return;
3094 }
3095
3096 // this capability requires provisioning, route to the correct API.
3097 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3098 switch (capability) {
3099 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3100 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3101 ims.setVolteProvisioned(isProvisioned);
3102 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3103 ims.setWfcProvisioned(isProvisioned);
3104 }
3105 break;
3106 }
3107 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3108 // There is currently no difference in VT provisioning type.
3109 ims.setVtProvisioned(isProvisioned);
3110 break;
3111 }
3112 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3113 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3114 // change the capability of the feature instead if needed.
3115 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3116 == isProvisioned) {
3117 // No change in provisioning.
3118 return;
3119 }
3120 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3121 try {
3122 ims.changeMmTelCapability(capability, tech, isProvisioned);
3123 } catch (ImsException e) {
3124 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3125 + ", Exception" + e.getMessage());
3126 }
3127 break;
3128 }
3129 default: {
3130 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3131 + capability + "', which does not require provisioning.");
3132 }
3133 }
3134
3135 } finally {
3136 Binder.restoreCallingIdentity(identity);
3137 }
3138 }
3139
3140 @Override
3141 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3142 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3143 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3144 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3145 }
3146 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3150 Phone phone = getPhone(subId);
3151 if (phone == null) {
3152 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3153 + subId);
3154 // We will fail with "true" as the provisioning status because this is the default
3155 // if we do not require provisioning.
3156 return true;
3157 }
3158
3159 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3160 return true;
3161 }
3162
3163 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3164 switch (capability) {
3165 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3166 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3167 return ims.isVolteProvisionedOnDevice();
3168 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3169 return ims.isWfcProvisionedOnDevice();
3170 }
3171 // This should never happen, since we are checking tech above to make sure it
3172 // is either LTE or IWLAN.
3173 throw new IllegalArgumentException("Invalid radio technology for voice "
3174 + "capability.");
3175 }
3176 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3177 // There is currently no difference in VT provisioning type.
3178 return ims.isVtProvisionedOnDevice();
3179 }
3180 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3181 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3182 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3183 }
3184 default: {
3185 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3186 + capability + "', which does not require provisioning.");
3187 }
3188 }
3189
3190 } finally {
3191 Binder.restoreCallingIdentity(identity);
3192 }
3193 }
3194
3195 @Override
3196 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3197 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3198 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3199 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3200 }
3201 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3202 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3203 return (provisionedBits & capability) > 0;
3204 }
3205
3206 @Override
3207 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3208 boolean isProvisioned) {
3209 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3210 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3211 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3212 }
3213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3214 "setProvisioningStatusForCapability");
3215 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3216 // If the current provisioning status for capability already matches isProvisioned,
3217 // do nothing.
3218 if (((provisionedBits & capability) > 0) == isProvisioned) {
3219 return;
3220 }
3221 if (isProvisioned) {
3222 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3223 } else {
3224 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3225 }
3226 }
3227
3228 /**
3229 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3230 * technology. The bitfield should mirror the bitfield defined by
3231 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3232 */
3233 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3234 String key = getMmTelProvisioningKey(subId, tech);
3235 // Default is no capabilities are provisioned.
3236 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3237 }
3238
3239 /**
3240 * Sets the MmTel capability provisioning bitfield (defined by
3241 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3242 * technology specified.
3243 *
3244 * Note: This is a synchronous command and should not be called on UI thread.
3245 */
3246 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3247 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3248 String key = getMmTelProvisioningKey(subId, tech);
3249 editor.putInt(key, newField);
3250 editor.commit();
3251 }
3252
3253 private static String getMmTelProvisioningKey(int subId, int tech) {
3254 // resulting key is provision_ims_mmtel_{subId}_{tech}
3255 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3256 }
3257
3258 /**
3259 * Query CarrierConfig to see if the specified capability requires provisioning for the
3260 * carrier associated with the subscription id.
3261 */
3262 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3263 int capability) {
3264 CarrierConfigManager configManager = new CarrierConfigManager(context);
3265 PersistableBundle c = configManager.getConfigForSubId(subId);
3266 boolean requireUtProvisioning = c.getBoolean(
3267 // By default, this config is true (even if there is no SIM). We also check to make
3268 // sure the subscription needs provisioning here, so we do not need to check for
3269 // the no-SIM case, where we would normally shortcut this to false.
3270 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3271 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3272 false);
3273 boolean requireVoiceVtProvisioning = c.getBoolean(
3274 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3275
3276 // First check to make sure that the capability requires provisioning.
3277 switch (capability) {
3278 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3279 // intentional fallthrough
3280 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3281 if (requireVoiceVtProvisioning) {
3282 // Voice and Video requires provisioning
3283 return true;
3284 }
3285 break;
3286 }
3287 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3288 if (requireUtProvisioning) {
3289 // UT requires provisioning
3290 return true;
3291 }
3292 break;
3293 }
3294 }
3295 return false;
3296 }
3297
3298 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003299 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003300 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3301 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3302 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003303 enforceReadPrivilegedPermission("getImsProvisioningInt");
3304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003307 int slotId = getSlotIndex(subId);
3308 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3309 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3310 + subId + "' for key:" + key);
3311 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3312 }
3313 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003314 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003315 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3316 + subId + "' for key:" + key);
3317 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
3321 }
3322
3323 @Override
3324 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003325 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3326 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3327 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003328 enforceReadPrivilegedPermission("getImsProvisioningString");
3329 final long identity = Binder.clearCallingIdentity();
3330 try {
3331 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003332 int slotId = getSlotIndex(subId);
3333 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3334 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3335 + subId + "' for key:" + key);
3336 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3337 }
3338 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003339 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003340 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3341 + subId + "' for key:" + key);
3342 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003343 } finally {
3344 Binder.restoreCallingIdentity(identity);
3345 }
3346 }
3347
3348 @Override
3349 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003350 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3351 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3352 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3354 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003355 final long identity = Binder.clearCallingIdentity();
3356 try {
3357 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003358 int slotId = getSlotIndex(subId);
3359 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3360 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3361 + subId + "' for key:" + key);
3362 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3363 }
3364 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003365 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003366 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3367 + "' for key:" + key);
3368 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003369 } finally {
3370 Binder.restoreCallingIdentity(identity);
3371 }
3372 }
3373
3374 @Override
3375 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003376 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3377 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3378 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3380 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003381 final long identity = Binder.clearCallingIdentity();
3382 try {
3383 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003384 int slotId = getSlotIndex(subId);
3385 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3386 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3387 + subId + "' for key:" + key);
3388 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3389 }
3390 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003391 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003392 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3393 + "' for key:" + key);
3394 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003395 } finally {
3396 Binder.restoreCallingIdentity(identity);
3397 }
3398 }
3399
Brad Ebinger35c841c2018-10-01 10:40:55 -07003400 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3401 int slotId = SubscriptionManager.getSlotIndex(subId);
3402 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3403 throw new IllegalArgumentException("Invalid Subscription Id.");
3404 }
3405 return slotId;
3406 }
3407
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003408 private int getSlotIndex(int subId) {
3409 int slotId = SubscriptionManager.getSlotIndex(subId);
3410 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3411 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3412 }
3413 return slotId;
3414 }
3415
Wink Saville36469e72014-06-11 15:17:00 -07003416 /**
3417 * Returns the network type for a subId
3418 */
3419 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003420 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003421 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003422 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003423 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3424 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003426 final long identity = Binder.clearCallingIdentity();
3427 try {
3428 final Phone phone = getPhone(subId);
3429 if (phone != null) {
3430 return phone.getServiceState().getDataNetworkType();
3431 } else {
3432 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3433 }
3434 } finally {
3435 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003436 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003437 }
3438
3439 /**
3440 * Returns the data network type
3441 */
3442 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003443 public int getDataNetworkType(String callingPackage) {
3444 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003445 }
3446
3447 /**
3448 * Returns the data network type for a subId
3449 */
3450 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003451 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003452 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003453 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003454 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3455 }
3456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003457 final long identity = Binder.clearCallingIdentity();
3458 try {
3459 final Phone phone = getPhone(subId);
3460 if (phone != null) {
3461 return phone.getServiceState().getDataNetworkType();
3462 } else {
3463 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3464 }
3465 } finally {
3466 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003468 }
3469
3470 /**
Wink Saville36469e72014-06-11 15:17:00 -07003471 * Returns the Voice network type for a subId
3472 */
3473 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003474 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003476 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003477 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3478 }
3479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003480 final long identity = Binder.clearCallingIdentity();
3481 try {
3482 final Phone phone = getPhone(subId);
3483 if (phone != null) {
3484 return phone.getServiceState().getVoiceNetworkType();
3485 } else {
3486 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3487 }
3488 } finally {
3489 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003490 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003491 }
3492
3493 /**
3494 * @return true if a ICC card is present
3495 */
3496 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003497 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003498 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3499 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003500 }
3501
3502 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003503 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003504 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003505 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003506 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 final Phone phone = PhoneFactory.getPhone(slotIndex);
3510 if (phone != null) {
3511 return phone.getIccCard().hasIccCard();
3512 } else {
3513 return false;
3514 }
3515 } finally {
3516 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003518 }
3519
3520 /**
3521 * Return if the current radio is LTE on CDMA. This
3522 * is a tri-state return value as for a period of time
3523 * the mode may be unknown.
3524 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003525 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003526 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003527 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003528 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003529 @Override
3530 public int getLteOnCdmaMode(String callingPackage) {
3531 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003532 }
3533
Sanket Padawe356d7632015-06-22 14:03:32 -07003534 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003535 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003536 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003537 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003538 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3539 }
3540
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003541 final long identity = Binder.clearCallingIdentity();
3542 try {
3543 final Phone phone = getPhone(subId);
3544 if (phone == null) {
3545 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3546 } else {
3547 return phone.getLteOnCdmaMode();
3548 }
3549 } finally {
3550 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003551 }
Wink Saville36469e72014-06-11 15:17:00 -07003552 }
3553
Wink Saville36469e72014-06-11 15:17:00 -07003554 /**
3555 * {@hide}
3556 * Returns Default subId, 0 in the case of single standby.
3557 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003558 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003559 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003560 }
3561
Shishir Agrawala9f32182016-04-12 12:00:16 -07003562 private int getSlotForDefaultSubscription() {
3563 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3564 }
3565
Wink Savilleb564aae2014-10-23 10:18:09 -07003566 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003567 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003568 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003569
Pengquan Menge92a50d2018-09-21 15:54:48 -07003570 private boolean isActiveSubscription(int subId) {
3571 return mSubscriptionController.isActiveSubId(subId);
3572 }
3573
Ihab Awadf2177b72013-11-25 13:33:23 -08003574 /**
3575 * @see android.telephony.TelephonyManager.WifiCallingChoices
3576 */
3577 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578 final long identity = Binder.clearCallingIdentity();
3579 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003580 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3582 getWhenToMakeWifiCallsDefaultPreference());
3583 } finally {
3584 Binder.restoreCallingIdentity(identity);
3585 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003586 }
3587
3588 /**
3589 * @see android.telephony.TelephonyManager.WifiCallingChoices
3590 */
3591 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003592 final long identity = Binder.clearCallingIdentity();
3593 try {
3594 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003595 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003596 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3597 } finally {
3598 Binder.restoreCallingIdentity(identity);
3599 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003600 }
3601
Sailesh Nepald1e68152013-12-12 19:08:02 -08003602 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003603 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003604 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003605 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003606
Shishir Agrawal566b7612013-10-28 14:41:00 -07003607 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003608 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3609 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3611 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003612 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003614 final long identity = Binder.clearCallingIdentity();
3615 try {
3616 if (TextUtils.equals(ISDR_AID, aid)) {
3617 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003618 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3619 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003620 if (bestComponent == null
3621 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3622 loge("The calling package is not allowed to access ISD-R.");
3623 throw new SecurityException(
3624 "The calling package is not allowed to access ISD-R.");
3625 }
Derek Tan740e1672017-06-27 14:56:27 -07003626 }
Derek Tan740e1672017-06-27 14:56:27 -07003627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003628 if (DBG) {
3629 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3630 }
3631 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3632 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3633 if (DBG) log("iccOpenLogicalChannel: " + response);
3634 return response;
3635 } finally {
3636 Binder.restoreCallingIdentity(identity);
3637 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003638 }
3639
3640 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003641 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3643 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003645 final long identity = Binder.clearCallingIdentity();
3646 try {
3647 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3648 if (channel < 0) {
3649 return false;
3650 }
3651 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3652 if (DBG) log("iccCloseLogicalChannel: " + success);
3653 return success;
3654 } finally {
3655 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003656 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003657 }
3658
3659 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003660 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003661 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3663 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 if (DBG) {
3668 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3669 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3670 + p3 + " data=" + data);
3671 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003672
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673 if (channel < 0) {
3674 return "";
3675 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003677 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3678 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3679 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003681 // Append the returned status code to the end of the response payload.
3682 String s = Integer.toHexString(
3683 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3684 if (response.payload != null) {
3685 s = IccUtils.bytesToHexString(response.payload) + s;
3686 }
3687 return s;
3688 } finally {
3689 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003690 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003691 }
Jake Hambye994d462014-02-03 13:10:13 -08003692
Evan Charltonc66da362014-05-16 14:06:40 -07003693 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003694 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3695 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3697 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003698 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3703 && TextUtils.equals(ISDR_AID, data)) {
3704 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003705 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3706 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003707 if (bestComponent == null
3708 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3709 loge("The calling package is not allowed to select ISD-R.");
3710 throw new SecurityException(
3711 "The calling package is not allowed to select ISD-R.");
3712 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003713 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003715 if (DBG) {
3716 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3717 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3718 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003719
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003720 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3721 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3722 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724 // Append the returned status code to the end of the response payload.
3725 String s = Integer.toHexString(
3726 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3727 if (response.payload != null) {
3728 s = IccUtils.bytesToHexString(response.payload) + s;
3729 }
3730 return s;
3731 } finally {
3732 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003733 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003734 }
3735
3736 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003737 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003738 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3740 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003742 final long identity = Binder.clearCallingIdentity();
3743 try {
3744 if (DBG) {
3745 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3746 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3747 }
3748
3749 IccIoResult response =
3750 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3751 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3752 subId);
3753
3754 if (DBG) {
3755 log("Exchange SIM_IO [R]" + response);
3756 }
3757
3758 byte[] result = null;
3759 int length = 2;
3760 if (response.payload != null) {
3761 length = 2 + response.payload.length;
3762 result = new byte[length];
3763 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3764 } else {
3765 result = new byte[length];
3766 }
3767
3768 result[length - 1] = (byte) response.sw2;
3769 result[length - 2] = (byte) response.sw1;
3770 return result;
3771 } finally {
3772 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003773 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003774 }
3775
Nathan Haroldb3014052017-01-25 15:57:32 -08003776 /**
3777 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3778 * on a particular subscription
3779 */
sqianb6e41952018-03-12 14:54:01 -07003780 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3781 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3782 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3783 return null;
3784 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785
3786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 if (appType != TelephonyManager.APPTYPE_USIM
3789 && appType != TelephonyManager.APPTYPE_SIM) {
3790 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3791 return null;
3792 }
3793 Object response = sendRequest(
3794 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3795 if (response instanceof String[]) {
3796 return (String[]) response;
3797 }
3798 // Response is an Exception of some kind,
3799 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003800 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003801 } finally {
3802 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003803 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003804 }
3805
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003806 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003807 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3809 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811 final long identity = Binder.clearCallingIdentity();
3812 try {
3813 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3814 if (response.payload == null) {
3815 return "";
3816 }
Evan Charltonc66da362014-05-16 14:06:40 -07003817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003818 // Append the returned status code to the end of the response payload.
3819 String s = Integer.toHexString(
3820 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3821 s = IccUtils.bytesToHexString(response.payload) + s;
3822 return s;
3823 } finally {
3824 Binder.restoreCallingIdentity(identity);
3825 }
Evan Charltonc66da362014-05-16 14:06:40 -07003826 }
3827
Jake Hambye994d462014-02-03 13:10:13 -08003828 /**
3829 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3830 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3831 *
3832 * @param itemID the ID of the item to read
3833 * @return the NV item as a String, or null on error.
3834 */
3835 @Override
3836 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003837 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3839 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003840
3841 final long identity = Binder.clearCallingIdentity();
3842 try {
3843 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003844 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003845 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3846 return value;
3847 } finally {
3848 Binder.restoreCallingIdentity(identity);
3849 }
Jake Hambye994d462014-02-03 13:10:13 -08003850 }
3851
3852 /**
3853 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3854 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3855 *
3856 * @param itemID the ID of the item to read
3857 * @param itemValue the value to write, as a String
3858 * @return true on success; false on any failure
3859 */
3860 @Override
3861 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003862 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3864 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003865
3866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3869 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003870 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3872 return success;
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
3875 }
Jake Hambye994d462014-02-03 13:10:13 -08003876 }
3877
3878 /**
3879 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3880 * Used for device configuration by some CDMA operators.
3881 *
3882 * @param preferredRoamingList byte array containing the new PRL
3883 * @return true on success; false on any failure
3884 */
3885 @Override
3886 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3888 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003889
3890 final long identity = Binder.clearCallingIdentity();
3891 try {
3892 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3893 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3894 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3895 return success;
3896 } finally {
3897 Binder.restoreCallingIdentity(identity);
3898 }
Jake Hambye994d462014-02-03 13:10:13 -08003899 }
3900
3901 /**
chen xu6dac5ab2018-10-26 17:39:23 -07003902 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003903 * Used for device configuration by some CDMA operators.
3904 *
chen xu6dac5ab2018-10-26 17:39:23 -07003905 * @param slotIndex - device slot.
3906 *
Jake Hambye994d462014-02-03 13:10:13 -08003907 * @return true on success; false on any failure
3908 */
3909 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07003910 public boolean resetModemConfig(int slotIndex) {
3911 Phone phone = PhoneFactory.getPhone(slotIndex);
3912 if (phone != null) {
3913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3914 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003915
chen xu6dac5ab2018-10-26 17:39:23 -07003916 final long identity = Binder.clearCallingIdentity();
3917 try {
3918 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3919 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3920 return success;
3921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003924 }
chen xu6dac5ab2018-10-26 17:39:23 -07003925 return false;
3926 }
3927
3928 /**
3929 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3930 *
3931 * @param slotIndex - device slot.
3932 *
3933 * @return true on success; false on any failure
3934 */
3935 @Override
3936 public boolean rebootModem(int slotIndex) {
3937 Phone phone = PhoneFactory.getPhone(slotIndex);
3938 if (phone != null) {
3939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3940 mApp, phone.getSubId(), "rebootModem");
3941
3942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3945 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3946 return success;
3947 } finally {
3948 Binder.restoreCallingIdentity(identity);
3949 }
3950 }
3951 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003952 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003953
Svet Ganovb320e182015-04-16 12:30:10 -07003954 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003955 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003957 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003958 return new String[0];
3959 }
3960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003961 final long identity = Binder.clearCallingIdentity();
3962 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003963 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003964 } finally {
3965 Binder.restoreCallingIdentity(identity);
3966 }
Wink Saville36469e72014-06-11 15:17:00 -07003967 }
3968
Brad Ebinger51f743a2017-01-23 13:50:20 -08003969 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003970 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3971 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003972 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003973 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003974 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003975
3976 final long identity = Binder.clearCallingIdentity();
3977 try {
3978 PhoneFactory.getImsResolver().enableIms(slotId);
3979 } finally {
3980 Binder.restoreCallingIdentity(identity);
3981 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003982 }
3983
3984 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003985 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3986 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003987 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003988 public void disableIms(int slotId) {
3989 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003990
3991 final long identity = Binder.clearCallingIdentity();
3992 try {
3993 PhoneFactory.getImsResolver().disableIms(slotId);
3994 } finally {
3995 Binder.restoreCallingIdentity(identity);
3996 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003997 }
3998
3999 /**
4000 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4001 * feature or {@link null} if the service is not available. If the feature is available, the
4002 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4003 */
4004 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004005 IImsServiceFeatureCallback callback) {
4006 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007
4008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
4011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004014 }
4015
4016 /**
4017 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4018 * feature during emergency calling or {@link null} if the service is not available. If the
4019 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4020 * listener for feature updates.
4021 */
4022 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4023 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004024
4025 final long identity = Binder.clearCallingIdentity();
4026 try {
4027 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
4028 } finally {
4029 Binder.restoreCallingIdentity(identity);
4030 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004031 }
4032
Brad Ebinger5f64b052017-12-14 14:26:15 -08004033 /**
4034 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
4035 * specified.
4036 */
4037 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4038 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004039
4040 final long identity = Binder.clearCallingIdentity();
4041 try {
4042 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
4043 } finally {
4044 Binder.restoreCallingIdentity(identity);
4045 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004046 }
4047
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004048 /**
4049 * Returns the {@link IImsConfig} structure associated with the slotId and feature
4050 * specified.
4051 */
4052 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4053 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004054
4055 final long identity = Binder.clearCallingIdentity();
4056 try {
4057 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004061 }
4062
Brad Ebinger884c07b2018-02-15 16:17:40 -08004063 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004064 * Sets the ImsService Package Name that Telephony will bind to.
4065 *
4066 * @param slotId the slot ID that the ImsService should bind for.
4067 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4068 * ImsService is the device default ImsService.
4069 * @param packageName The package name of the application that contains the ImsService to bind
4070 * to.
4071 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4072 * @hide
4073 */
4074 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004075 int[] subIds = SubscriptionManager.getSubId(slotId);
4076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4077 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4078 "setImsService");
4079
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004080 final long identity = Binder.clearCallingIdentity();
4081 try {
4082 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
4083 isCarrierImsService, packageName);
4084 } finally {
4085 Binder.restoreCallingIdentity(identity);
4086 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004087 }
4088
4089 /**
4090 * Return the ImsService configuration.
4091 *
4092 * @param slotId The slot that the ImsService is associated with.
4093 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4094 * the device default.
4095 * @return the package name of the ImsService configuration.
4096 */
4097 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004098 int[] subIds = SubscriptionManager.getSubId(slotId);
4099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4100 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4101 "getImsService");
4102
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
4106 isCarrierImsService);
4107 } finally {
4108 Binder.restoreCallingIdentity(identity);
4109 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004110 }
4111
Wink Saville36469e72014-06-11 15:17:00 -07004112 public void setImsRegistrationState(boolean registered) {
4113 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004114
4115 final long identity = Binder.clearCallingIdentity();
4116 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004117 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004118 } finally {
4119 Binder.restoreCallingIdentity(identity);
4120 }
Wink Saville36469e72014-06-11 15:17:00 -07004121 }
4122
4123 /**
Stuart Scott54788802015-03-30 13:18:01 -07004124 * Set the network selection mode to automatic.
4125 *
4126 */
4127 @Override
4128 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4130 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004131
Pengquan Menge92a50d2018-09-21 15:54:48 -07004132 if (!isActiveSubscription(subId)) {
4133 return;
4134 }
4135
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004136 final long identity = Binder.clearCallingIdentity();
4137 try {
4138 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4139 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4140 } finally {
4141 Binder.restoreCallingIdentity(identity);
4142 }
Stuart Scott54788802015-03-30 13:18:01 -07004143 }
4144
Pengquan Mengea84e042018-09-20 14:57:26 -07004145 /**
4146 * Ask the radio to connect to the input network and change selection mode to manual.
4147 *
4148 * @param subId the id of the subscription.
4149 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4150 * the operator to attach to.
4151 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4152 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4153 * normal network selection next time.
4154 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004155 */
4156 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004157 public boolean setNetworkSelectionModeManual(
4158 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4160 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004161
4162 if (!isActiveSubscription(subId)) {
4163 return false;
4164 }
4165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 final long identity = Binder.clearCallingIdentity();
4167 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004168 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004169 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004170 if (DBG) {
4171 log("setNetworkSelectionModeManual: subId: " + subId
4172 + " operator: " + operatorInfo);
4173 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004174 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4175 } finally {
4176 Binder.restoreCallingIdentity(identity);
4177 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004178 }
4179
4180 /**
4181 * Scans for available networks.
4182 */
4183 @Override
4184 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4186 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004187
Pengquan Menga1bb6272018-09-06 09:59:22 -07004188 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004189 try {
4190 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004191 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004192 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193 } finally {
4194 Binder.restoreCallingIdentity(identity);
4195 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004196 }
4197
4198 /**
yinxub1bed742017-04-17 11:45:04 -07004199 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004200 *
yinxub1bed742017-04-17 11:45:04 -07004201 * @param subId id of the subscription
4202 * @param request contains the radio access networks with bands/channels to scan
4203 * @param messenger callback messenger for scan results or errors
4204 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004205 * @return the id of the requested scan which can be used to stop the scan.
4206 */
4207 @Override
4208 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
4209 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4211 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004212
4213 final long identity = Binder.clearCallingIdentity();
4214 try {
4215 return mNetworkScanRequestTracker.startNetworkScan(
4216 request, messenger, binder, getPhone(subId));
4217 } finally {
4218 Binder.restoreCallingIdentity(identity);
4219 }
yinxu504e1392017-04-12 16:03:22 -07004220 }
4221
4222 /**
4223 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004224 *
4225 * @param subId id of the subscription
4226 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004227 */
4228 @Override
4229 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4231 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004232
4233 final long identity = Binder.clearCallingIdentity();
4234 try {
4235 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4236 } finally {
4237 Binder.restoreCallingIdentity(identity);
4238 }
yinxu504e1392017-04-12 16:03:22 -07004239 }
4240
4241 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004242 * Get the calculated preferred network type.
4243 * Used for debugging incorrect network type.
4244 *
4245 * @return the preferred network type, defined in RILConstants.java.
4246 */
4247 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004248 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004249 final Phone defaultPhone = getDefaultPhone();
4250 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4251 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004252 return RILConstants.PREFERRED_NETWORK_MODE;
4253 }
4254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004255 final long identity = Binder.clearCallingIdentity();
4256 try {
4257 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004258 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259 } finally {
4260 Binder.restoreCallingIdentity(identity);
4261 }
Junda Liu84d15a22014-07-02 11:21:04 -07004262 }
4263
4264 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004265 * Get the preferred network type.
4266 * Used for device configuration by some CDMA operators.
4267 *
4268 * @return the preferred network type, defined in RILConstants.java.
4269 */
4270 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004271 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004272 TelephonyPermissions
4273 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4274 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275
4276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 if (DBG) log("getPreferredNetworkType");
4279 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4280 int networkType = (result != null ? result[0] : -1);
4281 if (DBG) log("getPreferredNetworkType: " + networkType);
4282 return networkType;
4283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004286 }
4287
4288 /**
4289 * Set the preferred network type.
4290 * Used for device configuration by some CDMA operators.
4291 *
4292 * @param networkType the preferred network type, defined in RILConstants.java.
4293 * @return true on success; false on any failure.
4294 */
4295 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004296 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4298 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004299
4300 final long identity = Binder.clearCallingIdentity();
4301 try {
4302 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4303 Boolean success = (Boolean) sendRequest(
4304 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4305 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4306 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004307 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004308 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4309 }
4310 return success;
4311 } finally {
4312 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004313 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004314 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004315
4316 /**
Junda Liu475951f2014-11-07 16:45:03 -08004317 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu3cda1cd2018-10-30 17:41:31 -07004318 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004319 * tethering.
4320 *
4321 * @return 0: Not required. 1: required. 2: Not set.
4322 * @hide
4323 */
4324 @Override
4325 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004326 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004327
4328 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004329 final Phone defaultPhone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004331 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004332 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu3cda1cd2018-10-30 17:41:31 -07004333 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004334 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004335 dunRequired = 1;
4336 }
4337 return dunRequired;
4338 } finally {
4339 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004340 }
Junda Liu475951f2014-11-07 16:45:03 -08004341 }
4342
4343 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004344 * Set mobile data enabled
4345 * Used by the user through settings etc to turn on/off mobile data
4346 *
4347 * @param enable {@code true} turn turn data on, else {@code false}
4348 */
4349 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004350 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4352 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353
4354 final long identity = Binder.clearCallingIdentity();
4355 try {
4356 int phoneId = mSubscriptionController.getPhoneId(subId);
4357 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4358 Phone phone = PhoneFactory.getPhone(phoneId);
4359 if (phone != null) {
4360 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004361 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004362 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004363 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004364 }
4365 } finally {
4366 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004367 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004368 }
4369
4370 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004371 * Get the user enabled state of Mobile Data.
4372 *
4373 * TODO: remove and use isUserDataEnabled.
4374 * This can't be removed now because some vendor codes
4375 * calls through ITelephony directly while they should
4376 * use TelephonyManager.
4377 *
4378 * @return true on enabled
4379 */
4380 @Override
4381 public boolean getDataEnabled(int subId) {
4382 return isUserDataEnabled(subId);
4383 }
4384
4385 /**
4386 * Get whether mobile data is enabled per user setting.
4387 *
4388 * There are other factors deciding whether mobile data is actually enabled, but they are
4389 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004390 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004391 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004392 *
4393 * @return {@code true} if data is enabled else {@code false}
4394 */
4395 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004396 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004397 try {
4398 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4399 null);
4400 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4402 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004403 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404
4405 final long identity = Binder.clearCallingIdentity();
4406 try {
4407 int phoneId = mSubscriptionController.getPhoneId(subId);
4408 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4409 Phone phone = PhoneFactory.getPhone(phoneId);
4410 if (phone != null) {
4411 boolean retVal = phone.isUserDataEnabled();
4412 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4413 return retVal;
4414 } else {
4415 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4416 return false;
4417 }
4418 } finally {
4419 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004420 }
4421 }
4422
4423 /**
4424 * Get whether mobile data is enabled.
4425 *
4426 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4427 * whether mobile data is actually enabled.
4428 *
4429 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4430 *
4431 * @return {@code true} if data is enabled else {@code false}
4432 */
4433 @Override
4434 public boolean isDataEnabled(int subId) {
4435 try {
4436 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4437 null);
4438 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4440 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442
4443 final long identity = Binder.clearCallingIdentity();
4444 try {
4445 int phoneId = mSubscriptionController.getPhoneId(subId);
4446 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4447 Phone phone = PhoneFactory.getPhone(phoneId);
4448 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004449 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4451 return retVal;
4452 } else {
4453 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4454 return false;
4455 }
4456 } finally {
4457 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004458 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004459 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004460
4461 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004462 public int getCarrierPrivilegeStatus(int subId) {
4463 final Phone phone = getPhone(subId);
4464 if (phone == null) {
4465 loge("getCarrierPrivilegeStatus: Invalid subId");
4466 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4467 }
4468 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004469 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004470 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004471 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4472 }
4473 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004474 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004475 }
Junda Liu29340342014-07-10 15:23:27 -07004476
4477 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004478 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4479 final Phone phone = getPhone(subId);
4480 if (phone == null) {
4481 loge("getCarrierPrivilegeStatus: Invalid subId");
4482 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4483 }
4484 UiccProfile profile =
4485 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4486 if (profile == null) {
4487 loge("getCarrierPrivilegeStatus: No UICC");
4488 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4489 }
4490 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4491 }
4492
4493 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004494 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004495 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004496 if (TextUtils.isEmpty(pkgName))
4497 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004498 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004499 if (card == null) {
4500 loge("checkCarrierPrivilegesForPackage: No UICC");
4501 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4502 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004503 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4504 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004505 }
4506
4507 @Override
4508 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004509 if (TextUtils.isEmpty(pkgName))
4510 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004511 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4512 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4513 UiccCard card = UiccController.getInstance().getUiccCard(i);
4514 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004515 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004516 continue;
4517 }
4518
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004519 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004520 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4521 break;
4522 }
4523 }
4524
4525 return result;
Junda Liu29340342014-07-10 15:23:27 -07004526 }
Derek Tan89e89d42014-07-08 17:00:10 -07004527
4528 @Override
Junda Liue64de782015-04-16 17:19:16 -07004529 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4530 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4531 loge("phoneId " + phoneId + " is not valid.");
4532 return null;
4533 }
4534 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004535 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004536 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004537 return null ;
4538 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004539 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004540 }
4541
Amith Yamasani6e118872016-02-19 12:53:51 -08004542 @Override
4543 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004544 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004545 List<String> privilegedPackages = new ArrayList<>();
4546 List<PackageInfo> packages = null;
4547 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4548 UiccCard card = UiccController.getInstance().getUiccCard(i);
4549 if (card == null) {
4550 // No UICC in that slot.
4551 continue;
4552 }
4553 if (card.hasCarrierPrivilegeRules()) {
4554 if (packages == null) {
4555 // Only check packages in user 0 for now
4556 packages = pm.getInstalledPackagesAsUser(
4557 PackageManager.MATCH_DISABLED_COMPONENTS
4558 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4559 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4560 }
4561 for (int p = packages.size() - 1; p >= 0; p--) {
4562 PackageInfo pkgInfo = packages.get(p);
4563 if (pkgInfo != null && pkgInfo.packageName != null
4564 && card.getCarrierPrivilegeStatus(pkgInfo)
4565 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4566 privilegedPackages.add(pkgInfo.packageName);
4567 }
4568 }
4569 }
4570 }
4571 return privilegedPackages;
4572 }
4573
Wink Savilleb564aae2014-10-23 10:18:09 -07004574 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004575 final Phone phone = getPhone(subId);
4576 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004577 if (card == null) {
4578 loge("getIccId: No UICC");
4579 return null;
4580 }
4581 String iccId = card.getIccId();
4582 if (TextUtils.isEmpty(iccId)) {
4583 loge("getIccId: ICC ID is null or empty.");
4584 return null;
4585 }
4586 return iccId;
4587 }
4588
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004589 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004590 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4591 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004592 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4593 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 final long identity = Binder.clearCallingIdentity();
4596 try {
4597 final String iccId = getIccId(subId);
4598 final Phone phone = getPhone(subId);
4599 if (phone == null) {
4600 return false;
4601 }
4602 final String subscriberId = phone.getSubscriberId();
4603
4604 if (DBG_MERGE) {
4605 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4606 + subscriberId + " to " + number);
4607 }
4608
4609 if (TextUtils.isEmpty(iccId)) {
4610 return false;
4611 }
4612
4613 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4614
4615 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4616 if (alphaTag == null) {
4617 editor.remove(alphaTagPrefKey);
4618 } else {
4619 editor.putString(alphaTagPrefKey, alphaTag);
4620 }
4621
4622 // Record both the line number and IMSI for this ICCID, since we need to
4623 // track all merged IMSIs based on line number
4624 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4625 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4626 if (number == null) {
4627 editor.remove(numberPrefKey);
4628 editor.remove(subscriberPrefKey);
4629 } else {
4630 editor.putString(numberPrefKey, number);
4631 editor.putString(subscriberPrefKey, subscriberId);
4632 }
4633
4634 editor.commit();
4635 return true;
4636 } finally {
4637 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004638 }
Derek Tan7226c842014-07-02 17:42:23 -07004639 }
4640
4641 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004642 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004643 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004644 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004645 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004646 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004647 return null;
4648 }
Derek Tan97ebb422014-09-05 16:55:38 -07004649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650 final long identity = Binder.clearCallingIdentity();
4651 try {
4652 String iccId = getIccId(subId);
4653 if (iccId != null) {
4654 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4655 if (DBG_MERGE) {
4656 log("getLine1NumberForDisplay returning "
4657 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4658 }
4659 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004661 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4662 return null;
4663 } finally {
4664 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004665 }
Derek Tan7226c842014-07-02 17:42:23 -07004666 }
4667
4668 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004669 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004670 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004671 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004672 return null;
4673 }
Derek Tan97ebb422014-09-05 16:55:38 -07004674
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004675 final long identity = Binder.clearCallingIdentity();
4676 try {
4677 String iccId = getIccId(subId);
4678 if (iccId != null) {
4679 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4680 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4681 }
4682 return null;
4683 } finally {
4684 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004685 }
Derek Tan7226c842014-07-02 17:42:23 -07004686 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004687
4688 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004689 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004690 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4691 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004692 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004693 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4694 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004695 return null;
4696 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004697
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004698 final long identity = Binder.clearCallingIdentity();
4699 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004700 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004701 final TelephonyManager tele = TelephonyManager.from(context);
4702 final SubscriptionManager sub = SubscriptionManager.from(context);
4703
4704 // Figure out what subscribers are currently active
4705 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4706 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4707 // the process, where TelephonyManager was instantiated.
4708 // Otherwise AppOps check will fail.
4709
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004710 final int[] subIds = sub.getActiveSubscriptionIdList();
4711 for (int subId : subIds) {
4712 activeSubscriberIds.add(tele.getSubscriberId(subId));
4713 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004714
4715 // First pass, find a number override for an active subscriber
4716 String mergeNumber = null;
4717 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4718 for (String key : prefs.keySet()) {
4719 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4720 final String subscriberId = (String) prefs.get(key);
4721 if (activeSubscriberIds.contains(subscriberId)) {
4722 final String iccId = key.substring(
4723 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4724 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4725 mergeNumber = (String) prefs.get(numberKey);
4726 if (DBG_MERGE) {
4727 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4728 + " for active subscriber " + subscriberId);
4729 }
4730 if (!TextUtils.isEmpty(mergeNumber)) {
4731 break;
4732 }
4733 }
4734 }
4735 }
4736
4737 // Shortcut when no active merged subscribers
4738 if (TextUtils.isEmpty(mergeNumber)) {
4739 return null;
4740 }
4741
4742 // Second pass, find all subscribers under that line override
4743 final ArraySet<String> result = new ArraySet<>();
4744 for (String key : prefs.keySet()) {
4745 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4746 final String number = (String) prefs.get(key);
4747 if (mergeNumber.equals(number)) {
4748 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4749 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4750 final String subscriberId = (String) prefs.get(subscriberKey);
4751 if (!TextUtils.isEmpty(subscriberId)) {
4752 result.add(subscriberId);
4753 }
4754 }
4755 }
4756 }
4757
4758 final String[] resultArray = result.toArray(new String[result.size()]);
4759 Arrays.sort(resultArray);
4760 if (DBG_MERGE) {
4761 Slog.d(LOG_TAG,
4762 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4763 }
4764 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004765 } finally {
4766 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004767 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004768 }
4769
4770 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004771 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004772 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4773 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774
4775 final long identity = Binder.clearCallingIdentity();
4776 try {
4777 final Phone phone = getPhone(subId);
4778 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4779 } finally {
4780 Binder.restoreCallingIdentity(identity);
4781 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004782 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004783
4784 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004785 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004786 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4787 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004788 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789
4790 final long identity = Binder.clearCallingIdentity();
4791 try {
4792 final Phone phone = getPhone(subId);
4793 if (phone == null) {
4794 return false;
4795 }
4796 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4797 cdmaNonRoamingList);
4798 } finally {
4799 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004800 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004801 }
4802
4803 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004804 @Deprecated
4805 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4806 enforceModifyPermission();
4807
4808 int returnValue = 0;
4809 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004810 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004811 if(result.exception == null) {
4812 if (result.result != null) {
4813 byte[] responseData = (byte[])(result.result);
4814 if(responseData.length > oemResp.length) {
4815 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4816 responseData.length + "bytes. Buffer Size is " +
4817 oemResp.length + "bytes.");
4818 }
4819 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4820 returnValue = responseData.length;
4821 }
4822 } else {
4823 CommandException ex = (CommandException) result.exception;
4824 returnValue = ex.getCommandError().ordinal();
4825 if(returnValue > 0) returnValue *= -1;
4826 }
4827 } catch (RuntimeException e) {
4828 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4829 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4830 if(returnValue > 0) returnValue *= -1;
4831 }
4832
4833 return returnValue;
4834 }
4835
4836 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004837 public void setRadioCapability(RadioAccessFamily[] rafs) {
4838 try {
4839 ProxyController.getInstance().setRadioCapability(rafs);
4840 } catch (RuntimeException e) {
4841 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4842 }
4843 }
4844
4845 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004846 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004847 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004848 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004849 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004850 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004851 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004852 final long identity = Binder.clearCallingIdentity();
4853 try {
chen xub97461a2018-10-26 14:17:57 -07004854 TelephonyPermissions
4855 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4856 mApp, phone.getSubId(), "getRadioAccessFamily");
4857 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004858 } finally {
4859 Binder.restoreCallingIdentity(identity);
4860 }
chen xub97461a2018-10-26 14:17:57 -07004861 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004862 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004863
4864 @Override
4865 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004866 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004867 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004868
4869 final long identity = Binder.clearCallingIdentity();
4870 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004871 ImsManager.getInstance(defaultPhone.getContext(),
4872 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873 } finally {
4874 Binder.restoreCallingIdentity(identity);
4875 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004876 }
4877
4878 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004879 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004880 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004881 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004882 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004883 return false;
4884 }
Svet Ganovb320e182015-04-16 12:30:10 -07004885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004886 final long identity = Binder.clearCallingIdentity();
4887 try {
4888 // Check the user preference and the system-level IMS setting. Even if the user has
4889 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4890 // In the long run, we may instead need to check if there exists a connection service
4891 // which can support video calling.
4892 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004893 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004894 return imsManager.isVtEnabledByPlatform()
4895 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4896 && imsManager.isVtEnabledByUser();
4897 } finally {
4898 Binder.restoreCallingIdentity(identity);
4899 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004900 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004901
Andrew Leea1239f22015-03-02 17:44:07 -08004902 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4904 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4905 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4906 return false;
4907 }
4908
4909 final long identity = Binder.clearCallingIdentity();
4910 try {
4911 CarrierConfigManager configManager =
4912 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004913 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4915 } finally {
4916 Binder.restoreCallingIdentity(identity);
4917 }
Andrew Leea1239f22015-03-02 17:44:07 -08004918 }
4919
4920 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921 public boolean isWorldPhone(int subId, String callingPackage) {
4922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4923 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4924 return false;
4925 }
4926
4927 final long identity = Binder.clearCallingIdentity();
4928 try {
4929 CarrierConfigManager configManager =
4930 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004931 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
Andrew Leea1239f22015-03-02 17:44:07 -08004936 }
4937
Andrew Lee9431b832015-03-09 18:46:45 -07004938 @Override
4939 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004940 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004941 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004942 }
4943
4944 @Override
4945 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946 final long identity = Binder.clearCallingIdentity();
4947 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004948 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 } finally {
4950 Binder.restoreCallingIdentity(identity);
4951 }
Andrew Lee9431b832015-03-09 18:46:45 -07004952 }
4953
Hall Liuf6668912018-10-31 17:05:23 -07004954 /**
4955 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4956 * support for the feature and device firmware support.
4957 *
4958 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4959 */
4960 @Override
4961 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004963 final Phone phone = getPhone(subscriptionId);
4964 if (phone == null) {
4965 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4966 return false;
4967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004969 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4971 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004972 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 return isCarrierSupported && isDeviceSupported;
4974 } finally {
4975 Binder.restoreCallingIdentity(identity);
4976 }
Hall Liu98187582018-01-22 19:15:32 -08004977 }
4978
Hall Liuf6668912018-10-31 17:05:23 -07004979 /**
4980 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4981 * both also support RTT.
4982 */
4983 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984 final long identity = Binder.clearCallingIdentity();
4985 try {
Hall Liuf6668912018-10-31 17:05:23 -07004986 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004987 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988 } finally {
4989 Binder.restoreCallingIdentity(identity);
4990 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004991 }
4992
Sanket Padawe7310cc72015-01-14 09:53:20 -08004993 /**
4994 * Returns the unique device ID of phone, for example, the IMEI for
4995 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4996 *
4997 * <p>Requires Permission:
4998 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4999 */
5000 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005001 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005002 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005003 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005004 return null;
5005 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005006 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005007 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5008 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005009 return null;
5010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011
5012 final long identity = Binder.clearCallingIdentity();
5013 try {
5014 return phone.getDeviceId();
5015 } finally {
5016 Binder.restoreCallingIdentity(identity);
5017 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005018 }
5019
Ping Sunc67b7c22016-03-02 19:16:45 +08005020 /**
5021 * {@hide}
5022 * Returns the IMS Registration Status on a particular subid
5023 *
5024 * @param subId
5025 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005026 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005027 Phone phone = getPhone(subId);
5028 if (phone != null) {
5029 return phone.isImsRegistered();
5030 } else {
5031 return false;
5032 }
5033 }
5034
Santos Cordon7a1885b2015-02-03 11:15:19 -08005035 @Override
5036 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005037 final long identity = Binder.clearCallingIdentity();
5038 try {
5039 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5040 } finally {
5041 Binder.restoreCallingIdentity(identity);
5042 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005043 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005044
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005045 /**
5046 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005047 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005048 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049 final long identity = Binder.clearCallingIdentity();
5050 try {
5051 Phone phone = getPhone(subId);
5052 if (phone != null) {
5053 return phone.isWifiCallingEnabled();
5054 } else {
5055 return false;
5056 }
5057 } finally {
5058 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005059 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005060 }
5061
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005062 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005063 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005064 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005065 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 final long identity = Binder.clearCallingIdentity();
5067 try {
5068 Phone phone = getPhone(subId);
5069 if (phone != null) {
5070 return phone.isVideoEnabled();
5071 } else {
5072 return false;
5073 }
5074 } finally {
5075 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005076 }
5077 }
5078
5079 /**
5080 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5081 * defined in {@link ImsRegistrationImplBase}.
5082 */
5083 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005084 final long identity = Binder.clearCallingIdentity();
5085 try {
5086 Phone phone = getPhone(subId);
5087 if (phone != null) {
5088 return phone.getImsRegistrationTech();
5089 } else {
5090 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5091 }
5092 } finally {
5093 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005094 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005095 }
5096
Stuart Scott8eef64f2015-04-08 15:13:54 -07005097 @Override
5098 public void factoryReset(int subId) {
5099 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005100 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5101 return;
5102 }
5103
Svet Ganovcc087f82015-05-12 20:35:54 -07005104 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005105
Svet Ganovcc087f82015-05-12 20:35:54 -07005106 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005107 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5108 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005109 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005110 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005111 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005112 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5113 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005114 }
5115 } finally {
5116 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005117 }
5118 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005119
5120 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005121 public String getSimLocaleForSubscriber(int subId) {
5122 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5123 final Phone phone = getPhone(subId);
5124 if (phone == null) {
5125 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005126 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128 final long identity = Binder.clearCallingIdentity();
5129 try {
chen xu5d3637b2019-01-21 23:31:38 -08005130 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5131 phone.getContext().getOpPackageName());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132 // Try and fetch the locale from the carrier properties or from the SIM language
5133 // preferences (EF-PL and EF-LI)...
5134 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005136 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5137 if (localeFromDefaultSim != null) {
5138 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5139 if (DBG) log("Using locale from subId: " + subId + " locale: "
5140 + localeFromDefaultSim);
5141 return localeFromDefaultSim.toLanguageTag();
5142 } else {
5143 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005144 }
5145 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005147 // The SIM language preferences only store a language (e.g. fr = French), not an
5148 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5149 // the SIM and carrier preferences does not include a country we add the country
5150 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005151 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005152 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005153 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 return mccLocale.toLanguageTag();
5155 }
5156
5157 if (DBG) log("No locale found - returning null");
5158 return null;
5159 } finally {
5160 Binder.restoreCallingIdentity(identity);
5161 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005162 }
5163
5164 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005165 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005166 }
5167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 /**
5169 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5170 */
5171 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005172 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005173 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005174
Chenjie Yu1ba97252018-01-11 18:16:20 -08005175 private final ModemActivityInfo mLastModemActivityInfo =
5176 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5177
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005178 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005179 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5180 * representing the state of the modem.
5181 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005182 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5183 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005184 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005185 */
5186 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005187 public void requestModemActivityInfo(ResultReceiver result) {
5188 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005189 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190
5191 final long identity = Binder.clearCallingIdentity();
5192 try {
5193 ModemActivityInfo ret = null;
5194 synchronized (mLastModemActivityInfo) {
5195 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5196 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005197 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005198 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5200 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005201 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5202 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005203 }
5204 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005205 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5206 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 mLastModemActivityInfo.setIdleTimeMillis(
5208 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5209 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5210 mLastModemActivityInfo.setRxTimeMillis(
5211 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5212 mLastModemActivityInfo.setEnergyUsed(
5213 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005214 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5216 mLastModemActivityInfo.getSleepTimeMillis(),
5217 mLastModemActivityInfo.getIdleTimeMillis(),
5218 mLastModemActivityInfo.getTxTimeMillis(),
5219 mLastModemActivityInfo.getRxTimeMillis(),
5220 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005221 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005222 Bundle bundle = new Bundle();
5223 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5224 result.send(0, bundle);
5225 } finally {
5226 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005227 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005228 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005229
Siddharth Rayb8114062018-06-17 15:02:38 -07005230 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5231 // less than total activity duration.
5232 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5233 if (info == null) {
5234 return false;
5235 }
5236 int activityDurationMs =
5237 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5238 int totalTxTimeMs = 0;
5239 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5240 totalTxTimeMs += info.getTxTimeMillis()[i];
5241 }
5242 return (info.isValid()
5243 && (info.getSleepTimeMillis() <= activityDurationMs)
5244 && (info.getIdleTimeMillis() <= activityDurationMs)
5245 && (info.getRxTimeMillis() <= activityDurationMs)
5246 && (totalTxTimeMs <= activityDurationMs));
5247 }
5248
Jack Yu85bd38a2015-11-09 11:34:32 -08005249 /**
5250 * {@hide}
5251 * Returns the service state information on specified subscription.
5252 */
5253 @Override
5254 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005256 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005257 return null;
5258 }
5259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 final long identity = Binder.clearCallingIdentity();
5261 try {
5262 final Phone phone = getPhone(subId);
5263 if (phone == null) {
5264 return null;
5265 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005266
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005267 return phone.getServiceState();
5268 } finally {
5269 Binder.restoreCallingIdentity(identity);
5270 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005271 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005272
5273 /**
5274 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5275 *
5276 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5277 * voicemail ringtone.
5278 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5279 * PhoneAccount.
5280 */
5281 @Override
5282 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 final long identity = Binder.clearCallingIdentity();
5284 try {
5285 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5286 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005287 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5291 } finally {
5292 Binder.restoreCallingIdentity(identity);
5293 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005294 }
5295
5296 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005297 * Sets the per-account voicemail ringtone.
5298 *
5299 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5300 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5301 *
5302 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5303 * voicemail ringtone.
5304 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5305 * PhoneAccount.
5306 */
5307 @Override
5308 public void setVoicemailRingtoneUri(String callingPackage,
5309 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005310 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005311 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5312 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005313 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5315 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5316 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005317 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005318
5319 final long identity = Binder.clearCallingIdentity();
5320 try {
5321 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5322 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005323 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 }
5325 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5326 } finally {
5327 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005328 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005329 }
5330
5331 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005332 * Returns whether vibration is set for voicemail notification in Phone settings.
5333 *
5334 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5335 * voicemail vibration setting.
5336 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5337 */
5338 @Override
5339 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340 final long identity = Binder.clearCallingIdentity();
5341 try {
5342 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5343 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005344 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005347 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5348 } finally {
5349 Binder.restoreCallingIdentity(identity);
5350 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005351 }
5352
Youhan Wange64578a2016-05-02 15:32:42 -07005353 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005354 * Sets the per-account voicemail vibration.
5355 *
5356 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5357 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5358 *
5359 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5360 * voicemail vibration setting.
5361 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5362 * specific PhoneAccount.
5363 */
5364 @Override
5365 public void setVoicemailVibrationEnabled(String callingPackage,
5366 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005367 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005368 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5369 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005370 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5372 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5373 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005374 }
5375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 final long identity = Binder.clearCallingIdentity();
5377 try {
5378 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5379 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005380 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005381 }
5382 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5383 } finally {
5384 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005385 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005386 }
5387
5388 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005389 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5390 *
5391 * @throws SecurityException if the caller does not have the required permission
5392 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005393 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005394 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005395 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005396 }
5397
5398 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005399 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5400 * permission.
5401 *
5402 * @throws SecurityException if the caller does not have the required permission
5403 */
5404 private void enforceSendSmsPermission() {
5405 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5406 }
5407
5408 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005409 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005410 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005411 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005412 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005413 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414 final long identity = Binder.clearCallingIdentity();
5415 try {
5416 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005417 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 if (componentName == null) {
5419 throw new SecurityException(
5420 "Caller not current active visual voicemail package[null]");
5421 }
5422 String vvmPackage = componentName.getPackageName();
5423 if (!callingPackage.equals(vvmPackage)) {
5424 throw new SecurityException("Caller not current active visual voicemail package["
5425 + vvmPackage + "]");
5426 }
5427 } finally {
5428 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005429 }
5430 }
5431
5432 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005433 * Return the application ID for the app type.
5434 *
5435 * @param subId the subscription ID that this request applies to.
5436 * @param appType the uicc app type.
5437 * @return Application ID for specificied app type, or null if no uicc.
5438 */
5439 @Override
5440 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005441 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005442 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443
5444 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005445 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 if (phone == null) {
5447 return null;
5448 }
5449 String aid = null;
5450 try {
5451 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5452 .getApplicationByType(appType).getAid();
5453 } catch (Exception e) {
5454 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5455 }
5456 return aid;
5457 } finally {
5458 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005459 }
Youhan Wange64578a2016-05-02 15:32:42 -07005460 }
5461
Youhan Wang4001d252016-05-11 10:29:41 -07005462 /**
5463 * Return the Electronic Serial Number.
5464 *
5465 * @param subId the subscription ID that this request applies to.
5466 * @return ESN or null if error.
5467 */
5468 @Override
5469 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005470 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005471 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005472
5473 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005474 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 if (phone == null) {
5476 return null;
5477 }
5478 String esn = null;
5479 try {
5480 esn = phone.getEsn();
5481 } catch (Exception e) {
5482 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5483 }
5484 return esn;
5485 } finally {
5486 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005487 }
Youhan Wang4001d252016-05-11 10:29:41 -07005488 }
5489
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005490 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005491 * Return the Preferred Roaming List Version.
5492 *
5493 * @param subId the subscription ID that this request applies to.
5494 * @return PRLVersion or null if error.
5495 */
5496 @Override
5497 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005498 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005499 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500
5501 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005502 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005503 if (phone == null) {
5504 return null;
5505 }
5506 String cdmaPrlVersion = null;
5507 try {
5508 cdmaPrlVersion = phone.getCdmaPrlVersion();
5509 } catch (Exception e) {
5510 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5511 }
5512 return cdmaPrlVersion;
5513 } finally {
5514 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005515 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005516 }
5517
5518 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005519 * Get snapshot of Telephony histograms
5520 * @return List of Telephony histograms
5521 * @hide
5522 */
5523 @Override
5524 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5526 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527
5528 final long identity = Binder.clearCallingIdentity();
5529 try {
5530 return RIL.getTelephonyRILTimingHistograms();
5531 } finally {
5532 Binder.restoreCallingIdentity(identity);
5533 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005534 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005535
5536 /**
5537 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005538 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5539 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005540 * Require system privileges. In the future we may add this to carrier APIs.
5541 *
Michele Berionne482f8202018-11-27 18:57:59 -08005542 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005543 */
5544 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005545 @TelephonyManager.SetCarrierRestrictionResult
5546 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005547 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005548 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005549
Michele Berionne482f8202018-11-27 18:57:59 -08005550 if (carrierRestrictionRules == null) {
5551 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005552 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554 final long identity = Binder.clearCallingIdentity();
5555 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005556 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005557 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 } finally {
5559 Binder.restoreCallingIdentity(identity);
5560 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005561 }
5562
5563 /**
5564 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005565 * Get the allowed carrier list and the excluded carrier list, including the priority between
5566 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005567 * Require system privileges. In the future we may add this to carrier APIs.
5568 *
Michele Berionne482f8202018-11-27 18:57:59 -08005569 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005570 */
5571 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005572 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005573 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005574 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575
5576 final long identity = Binder.clearCallingIdentity();
5577 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005578 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5579 if (response instanceof CarrierRestrictionRules) {
5580 return (CarrierRestrictionRules) response;
5581 }
5582 // Response is an Exception of some kind,
5583 // which is signalled to the user as a NULL retval
5584 return null;
5585 } catch (Exception e) {
5586 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5587 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 } finally {
5589 Binder.restoreCallingIdentity(identity);
5590 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005591 }
5592
fionaxu59545b42016-05-25 15:53:37 -07005593 /**
5594 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5595 * @param subId the subscription ID that this action applies to.
5596 * @param enabled control enable or disable metered apns.
5597 * {@hide}
5598 */
5599 @Override
5600 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5601 enforceModifyPermission();
5602 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603
5604 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005605 if (phone == null) {
5606 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5607 return;
5608 }
5609 try {
5610 phone.carrierActionSetMeteredApnsEnabled(enabled);
5611 } catch (Exception e) {
5612 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005613 } finally {
5614 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005615 }
5616 }
5617
5618 /**
5619 * Action set from carrier signalling broadcast receivers to enable/disable radio
5620 * @param subId the subscription ID that this action applies to.
5621 * @param enabled control enable or disable radio.
5622 * {@hide}
5623 */
5624 @Override
5625 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5626 enforceModifyPermission();
5627 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628
5629 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005630 if (phone == null) {
5631 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5632 return;
5633 }
5634 try {
5635 phone.carrierActionSetRadioEnabled(enabled);
5636 } catch (Exception e) {
5637 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 } finally {
5639 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005640 }
5641 }
5642
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005643 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005644 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5645 * network status based on which carrier apps could apply actions accordingly,
5646 * enable/disable default url handler for example.
5647 *
5648 * @param subId the subscription ID that this action applies to.
5649 * @param report control start/stop reporting the default network status.
5650 * {@hide}
5651 */
5652 @Override
5653 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5654 enforceModifyPermission();
5655 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656
5657 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005658 if (phone == null) {
5659 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5660 return;
5661 }
5662 try {
5663 phone.carrierActionReportDefaultNetworkStatus(report);
5664 } catch (Exception e) {
5665 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 } finally {
5667 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005668 }
5669 }
5670
5671 /**
fionaxud9622282017-07-17 17:51:30 -07005672 * Action set from carrier signalling broadcast receivers to reset all carrier actions
5673 * @param subId the subscription ID that this action applies to.
5674 * {@hide}
5675 */
5676 @Override
5677 public void carrierActionResetAll(int subId) {
5678 enforceModifyPermission();
5679 final Phone phone = getPhone(subId);
5680 if (phone == null) {
5681 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
5682 return;
5683 }
5684 try {
5685 phone.carrierActionResetAll();
5686 } catch (Exception e) {
5687 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
5688 }
5689 }
5690
5691 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005692 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5693 * bug report is being generated.
5694 */
5695 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005696 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005697 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5698 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005699 writer.println("Permission Denial: can't dump Phone from pid="
5700 + Binder.getCallingPid()
5701 + ", uid=" + Binder.getCallingUid()
5702 + "without permission "
5703 + android.Manifest.permission.DUMP);
5704 return;
5705 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005706 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005707 }
Jack Yueb89b242016-06-22 13:27:47 -07005708
Brad Ebingerdac2f002018-04-03 15:17:52 -07005709 @Override
5710 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5711 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5712 throws RemoteException {
5713 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5714 }
5715
Jack Yueb89b242016-06-22 13:27:47 -07005716 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005717 * Get aggregated video call data usage since boot.
5718 *
5719 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5720 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005721 * {@hide}
5722 */
5723 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005724 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005725 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5726 null);
5727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728 final long identity = Binder.clearCallingIdentity();
5729 try {
5730 // NetworkStatsService keeps tracking the active network interface and identity. It
5731 // records the delta with the corresponding network identity.
5732 // We just return the total video call data usage snapshot since boot.
5733 Phone phone = getPhone(subId);
5734 if (phone != null) {
5735 return phone.getVtDataUsage(perUidStats);
5736 }
5737 return null;
5738 } finally {
5739 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005740 }
Jack Yueb89b242016-06-22 13:27:47 -07005741 }
Jack Yu75ab2952016-07-08 14:29:33 -07005742
5743 /**
5744 * Policy control of data connection. Usually used when data limit is passed.
5745 * @param enabled True if enabling the data, otherwise disabling.
5746 * @param subId Subscription index
5747 * {@hide}
5748 */
5749 @Override
5750 public void setPolicyDataEnabled(boolean enabled, int subId) {
5751 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752
5753 final long identity = Binder.clearCallingIdentity();
5754 try {
5755 Phone phone = getPhone(subId);
5756 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005757 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005758 }
5759 } finally {
5760 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005761 }
5762 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005763
5764 /**
5765 * Get Client request stats
5766 * @return List of Client Request Stats
5767 * @hide
5768 */
5769 @Override
5770 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005771 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005772 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005773 return null;
5774 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005775 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777 final long identity = Binder.clearCallingIdentity();
5778 try {
5779 if (phone != null) {
5780 return phone.getClientRequestStats();
5781 }
5782
5783 return null;
5784 } finally {
5785 Binder.restoreCallingIdentity(identity);
5786 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005787 }
5788
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005789 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005790 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005791 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005792 }
Jack Yueb4124c2017-02-16 15:32:43 -08005793
5794 /**
Grace Chen70990072017-03-24 17:21:30 -07005795 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005796 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005797 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005798 * @param state State of SIM (power down, power up, pass through)
5799 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5800 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5801 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005802 *
5803 **/
5804 @Override
Grace Chen70990072017-03-24 17:21:30 -07005805 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005806 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005807 Phone phone = PhoneFactory.getPhone(slotIndex);
5808
vagdeviaf9a5b92018-08-15 16:01:53 -07005809 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005811 final long identity = Binder.clearCallingIdentity();
5812 try {
5813 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005814 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 }
5816 } finally {
5817 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005818 }
5819 }
Shuo Qiandd210312017-04-12 22:11:33 +00005820
Tyler Gunn65d45c22017-06-05 11:22:26 -07005821 private boolean isUssdApiAllowed(int subId) {
5822 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005823 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005824 if (configManager == null) {
5825 return false;
5826 }
5827 PersistableBundle pb = configManager.getConfigForSubId(subId);
5828 if (pb == null) {
5829 return false;
5830 }
5831 return pb.getBoolean(
5832 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5833 }
5834
Shuo Qiandd210312017-04-12 22:11:33 +00005835 /**
5836 * Check if phone is in emergency callback mode
5837 * @return true if phone is in emergency callback mode
5838 * @param subId sub id
5839 */
goneil9c5f4872017-12-05 14:07:56 -08005840 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005841 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005842 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005843 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005844
5845 final long identity = Binder.clearCallingIdentity();
5846 try {
5847 if (phone != null) {
5848 return phone.isInEcm();
5849 } else {
5850 return false;
5851 }
5852 } finally {
5853 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005854 }
5855 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005856
5857 /**
5858 * Get the current signal strength information for the given subscription.
5859 * Because this information is not updated when the device is in a low power state
5860 * it should not be relied-upon to be current.
5861 * @param subId Subscription index
5862 * @return the most recent cached signal strength info from the modem
5863 */
5864 @Override
5865 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866 final long identity = Binder.clearCallingIdentity();
5867 try {
5868 Phone p = getPhone(subId);
5869 if (p == null) {
5870 return null;
5871 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005872
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005873 return p.getSignalStrength();
5874 } finally {
5875 Binder.restoreCallingIdentity(identity);
5876 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005877 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005878
Pengquan Meng77b7f132018-08-22 14:49:57 -07005879 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005880 * Get the current modem radio state for the given slot.
5881 * @param slotIndex slot index.
5882 * @param callingPackage the name of the package making the call.
5883 * @return the current radio power state from the modem
5884 */
5885 @Override
5886 public int getRadioPowerState(int slotIndex, String callingPackage) {
5887 Phone phone = PhoneFactory.getPhone(slotIndex);
5888 if (phone != null) {
5889 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5890 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5891 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5892 }
5893
5894 final long identity = Binder.clearCallingIdentity();
5895 try {
5896 return phone.getRadioPowerState();
5897 } finally {
5898 Binder.restoreCallingIdentity(identity);
5899 }
5900 }
5901 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5902 }
5903
5904 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005905 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5906 *
5907 * <p>Requires one of the following permissions:
5908 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5909 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5910 * privileges.
5911 *
5912 * @param subId subscription id
5913 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5914 * {@code false}.
5915 */
5916 @Override
5917 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005918 boolean isEnabled = false;
5919 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005920 try {
5921 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005922 null /* message */);
5923 Phone phone = getPhone(subId);
5924 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005925 } catch (Exception e) {
5926 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5927 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005928 } finally {
5929 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005930 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005931 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005932 }
5933
5934
5935 /**
5936 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5937 *
5938 * <p> Requires permission:
5939 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5940 * privileges.
5941 *
5942 * @param subId subscription id
5943 * @param isEnabled {@code true} means enable, {@code false} means disable.
5944 */
5945 @Override
5946 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005947 final long identity = Binder.clearCallingIdentity();
5948 try {
5949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5950 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005951
Pengquan Menga1bb6272018-09-06 09:59:22 -07005952 Phone phone = getPhone(subId);
5953 if (phone != null) {
5954 phone.setDataRoamingEnabled(isEnabled);
5955 }
5956 } finally {
5957 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005958 }
5959 }
5960
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005961 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005962 public boolean isManualNetworkSelectionAllowed(int subId) {
5963 boolean isAllowed = true;
5964 final long identity = Binder.clearCallingIdentity();
5965 try {
5966 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5967 mApp, subId, "isManualNetworkSelectionAllowed");
5968 Phone phone = getPhone(subId);
5969 if (phone != null) {
5970 isAllowed = phone.isCspPlmnEnabled();
5971 }
5972 } finally {
5973 Binder.restoreCallingIdentity(identity);
5974 }
5975 return isAllowed;
5976 }
5977
5978 @Override
Jordan Liu5aa07002018-12-18 15:44:48 -08005979 public UiccCardInfo[] getUiccCardsInfo() {
5980 enforceReadPrivilegedPermission("getUiccCardsInfo");
5981
5982 final long identity = Binder.clearCallingIdentity();
5983 try {
5984 ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos();
5985 return cards.toArray(new UiccCardInfo[cards.size()]);
5986 } finally {
5987 Binder.restoreCallingIdentity(identity);
5988 }
5989 }
5990
5991 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005992 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005993 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 final long identity = Binder.clearCallingIdentity();
5996 try {
5997 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5998 if (slots == null) {
5999 Rlog.i(LOG_TAG, "slots is null.");
6000 return null;
6001 }
6002
6003 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6004 for (int i = 0; i < slots.length; i++) {
6005 UiccSlot slot = slots[i];
6006 if (slot == null) {
6007 continue;
6008 }
6009
6010 String cardId;
6011 UiccCard card = slot.getUiccCard();
6012 if (card != null) {
6013 cardId = card.getCardId();
6014 } else {
6015 cardId = slot.getIccId();
6016 }
6017
6018 int cardState = 0;
6019 switch (slot.getCardState()) {
6020 case CARDSTATE_ABSENT:
6021 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6022 break;
6023 case CARDSTATE_PRESENT:
6024 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6025 break;
6026 case CARDSTATE_ERROR:
6027 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6028 break;
6029 case CARDSTATE_RESTRICTED:
6030 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6031 break;
6032 default:
6033 break;
6034
6035 }
6036
6037 infos[i] = new UiccSlotInfo(
6038 slot.isActive(),
6039 slot.isEuicc(),
6040 cardId,
6041 cardState,
6042 slot.getPhoneId(),
6043 slot.isExtendedApduSupported());
6044 }
6045 return infos;
6046 } finally {
6047 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006048 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006049 }
6050
6051 @Override
6052 public boolean switchSlots(int[] physicalSlots) {
6053 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006054
6055 final long identity = Binder.clearCallingIdentity();
6056 try {
6057 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6058 } finally {
6059 Binder.restoreCallingIdentity(identity);
6060 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006061 }
Jack Yu4c988042018-02-27 15:30:01 -08006062
6063 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006064 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
6065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6066 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
6067 return TelephonyManager.INVALID_CARD_ID;
6068 }
6069
6070 final long identity = Binder.clearCallingIdentity();
6071 try {
6072 return UiccController.getInstance().getCardIdForDefaultEuicc();
6073 } finally {
6074 Binder.restoreCallingIdentity(identity);
6075 }
6076 }
6077
6078 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006079 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6080 enforceModifyPermission();
6081 final Phone phone = getPhone(subId);
6082 if (phone == null) {
6083 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6084 return;
6085 }
6086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 final long identity = Binder.clearCallingIdentity();
6088 try {
6089 phone.setRadioIndicationUpdateMode(filters, mode);
6090 } finally {
6091 Binder.restoreCallingIdentity(identity);
6092 }
Jack Yu4c988042018-02-27 15:30:01 -08006093 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006094
6095 /**
goneil47ffb6e2018-04-06 15:40:58 -07006096 * A test API to reload the UICC profile.
6097 *
6098 * <p>Requires that the calling app has permission
6099 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6100 * @hide
6101 */
6102 @Override
6103 public void refreshUiccProfile(int subId) {
6104 enforceModifyPermission();
6105
6106 final long identity = Binder.clearCallingIdentity();
6107 try {
6108 Phone phone = getPhone(subId);
6109 if (phone == null) {
6110 return;
6111 }
6112 UiccCard uiccCard = phone.getUiccCard();
6113 if (uiccCard == null) {
6114 return;
6115 }
6116 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6117 if (uiccProfile == null) {
6118 return;
6119 }
6120 uiccProfile.refresh();
6121 } finally {
6122 Binder.restoreCallingIdentity(identity);
6123 }
6124 }
6125
6126 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006127 * Returns false if the mobile data is disabled by default, otherwise return true.
6128 */
6129 private boolean getDefaultDataEnabled() {
6130 return "true".equalsIgnoreCase(
6131 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6132 }
6133
6134 /**
6135 * Returns true if the data roaming is enabled by default, i.e the system property
6136 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6137 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6138 */
6139 private boolean getDefaultDataRoamingEnabled(int subId) {
6140 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006141 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006142 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6143 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6144 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6145 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6146 return isDataRoamingEnabled;
6147 }
6148
6149 /**
6150 * Returns the default network type for the given {@code subId}, if the default network type is
6151 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6152 */
6153 private int getDefaultNetworkType(int subId) {
6154 return Integer.parseInt(
6155 TelephonyManager.getTelephonyProperty(
6156 mSubscriptionController.getPhoneId(subId),
6157 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6158 String.valueOf(Phone.PREFERRED_NT_MODE)));
6159 }
fionaxua13278b2018-03-21 00:08:13 -07006160
6161 @Override
6162 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6163 gid1, String gid2, String plmn, String spn) {
6164 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165
6166 final long identity = Binder.clearCallingIdentity();
6167 try {
6168 final Phone phone = getPhone(subId);
6169 if (phone == null) {
6170 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6171 return;
6172 }
6173 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6174 } finally {
6175 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006176 }
fionaxua13278b2018-03-21 00:08:13 -07006177 }
6178
6179 @Override
6180 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006181 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182
6183 final long identity = Binder.clearCallingIdentity();
6184 try {
6185 final Phone phone = getPhone(subId);
6186 if (phone == null) {
6187 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6188 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6189 }
6190 return phone.getCarrierIdListVersion();
6191 } finally {
6192 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006193 }
fionaxua13278b2018-03-21 00:08:13 -07006194 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006195
6196 @Override
6197 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6199 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6200 return -1;
6201 }
6202
6203 final long identity = Binder.clearCallingIdentity();
6204 try {
6205 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6206 } finally {
6207 Binder.restoreCallingIdentity(identity);
6208 }
6209 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006210
6211 @Override
6212 public int getCdmaRoamingMode(int subId) {
6213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6214 mApp, subId, "getCdmaRoamingMode");
6215
6216 final long identity = Binder.clearCallingIdentity();
6217 try {
6218 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6219 } finally {
6220 Binder.restoreCallingIdentity(identity);
6221 }
6222 }
6223
6224 @Override
6225 public boolean setCdmaRoamingMode(int subId, int mode) {
6226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6227 mApp, subId, "setCdmaRoamingMode");
6228
6229 final long identity = Binder.clearCallingIdentity();
6230 try {
6231 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6232 } finally {
6233 Binder.restoreCallingIdentity(identity);
6234 }
6235 }
6236
6237 @Override
6238 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6240 mApp, subId, "setCdmaSubscriptionMode");
6241
6242 final long identity = Binder.clearCallingIdentity();
6243 try {
6244 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6245 } finally {
6246 Binder.restoreCallingIdentity(identity);
6247 }
6248 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006249
6250 private void ensureUserRunning(int userId) {
6251 if (!mUserManager.isUserRunning(userId)) {
6252 throw new IllegalStateException("User " + userId + " does not exist or not running");
6253 }
6254 }
6255
6256 /**
6257 * Returns a list of SMS apps on a given user.
6258 *
6259 * Only the shell user (UID 2000 or 0) can call it.
6260 * Target user must be running.
6261 */
6262 @Override
6263 public String[] getSmsApps(int userId) {
6264 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6265 ensureUserRunning(userId);
6266
6267 final Collection<SmsApplicationData> apps =
6268 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6269
6270 String[] ret = new String[apps.size()];
6271 int i = 0;
6272 for (SmsApplicationData app : apps) {
6273 ret[i++] = app.mPackageName;
6274 }
6275 return ret;
6276 }
6277
6278 /**
6279 * Returns the default SMS app package name 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 getDefaultSmsApp(int userId) {
6286 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6287 ensureUserRunning(userId);
6288
6289 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6290 /* updateIfNeeded= */ true, userId);
6291 return cn == null ? null : cn.getPackageName();
6292 }
6293
6294 /**
6295 * Set a package as the default SMS app on a given user.
6296 *
6297 * Only the shell user (UID 2000 or 0) can call it.
6298 * Target user must be running.
6299 */
6300 @Override
6301 public void setDefaultSmsApp(int userId, String packageName) {
6302 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6303 ensureUserRunning(userId);
6304
6305 boolean found = false;
6306 for (String pkg : getSmsApps(userId)) {
6307 if (TextUtils.equals(packageName, pkg)) {
6308 found = true;
6309 break;
6310 }
6311 }
6312 if (!found) {
6313 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6314 }
6315
6316 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6317 }
sqianc5eccab2018-10-19 18:46:41 -07006318
6319 @Override
6320 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6321 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6323 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6324 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6325 }
6326 final long identity = Binder.clearCallingIdentity();
6327 try {
sqian854d44b2018-12-12 16:48:18 -08006328 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6329 for (Phone phone: PhoneFactory.getPhones()) {
6330 if (phone.getEmergencyNumberTracker() != null
6331 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6332 emergencyNumberListInternal.put(
6333 phone.getSubId(),
6334 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6335 }
sqian11b7a0e2018-12-05 18:48:28 -08006336 }
sqian854d44b2018-12-12 16:48:18 -08006337 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006338 } finally {
6339 Binder.restoreCallingIdentity(identity);
6340 }
sqianc5eccab2018-10-19 18:46:41 -07006341 }
6342
6343 @Override
sqian11b7a0e2018-12-05 18:48:28 -08006344 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006345 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006346 if (!exactMatch) {
6347 TelephonyPermissions
6348 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006349 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006350 }
6351 final long identity = Binder.clearCallingIdentity();
6352 try {
sqian854d44b2018-12-12 16:48:18 -08006353 for (Phone phone: PhoneFactory.getPhones()) {
6354 if (phone.getEmergencyNumberTracker() != null
6355 && phone.getEmergencyNumberTracker() != null) {
6356 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6357 number, exactMatch)) {
6358 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006359 }
6360 }
sqian11b7a0e2018-12-05 18:48:28 -08006361 }
6362 return false;
6363 } finally {
6364 Binder.restoreCallingIdentity(identity);
6365 }
6366 }
6367
sqianf4ca7ed2019-01-15 18:32:07 -08006368 /**
6369 * Update emergency number list for test mode.
6370 */
6371 @Override
6372 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6373 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6374 "updateEmergencyNumberListTestMode");
6375
6376 final long identity = Binder.clearCallingIdentity();
6377 try {
6378 for (Phone phone: PhoneFactory.getPhones()) {
6379 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6380 if (tracker != null) {
6381 tracker.executeEmergencyNumberTestModeCommand(action, num);
6382 }
6383 }
6384 } finally {
6385 Binder.restoreCallingIdentity(identity);
6386 }
6387 }
6388
6389 /**
6390 * Get the full emergency number list for test mode.
6391 */
6392 @Override
6393 public List<String> getEmergencyNumberListTestMode() {
6394 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6395 "getEmergencyNumberListTestMode");
6396
6397 final long identity = Binder.clearCallingIdentity();
6398 try {
6399 Set<String> emergencyNumbers = new HashSet<>();
6400 for (Phone phone: PhoneFactory.getPhones()) {
6401 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6402 if (tracker != null) {
6403 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6404 emergencyNumbers.add(num.getNumber());
6405 }
6406 }
6407 }
6408 return new ArrayList<>(emergencyNumbers);
6409 } finally {
6410 Binder.restoreCallingIdentity(identity);
6411 }
6412 }
6413
chen xud6b45bd2018-10-30 22:27:10 -07006414 @Override
6415 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6416 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6417 Phone phone = getPhone(subId);
6418 if (phone == null) {
6419 return null;
6420 }
6421 final long identity = Binder.clearCallingIdentity();
6422 try {
6423 UiccProfile profile = UiccController.getInstance()
6424 .getUiccProfileForPhone(phone.getPhoneId());
6425 if (profile != null) {
6426 return profile.getCertsFromCarrierPrivilegeAccessRules();
6427 }
6428 } finally {
6429 Binder.restoreCallingIdentity(identity);
6430 }
6431 return null;
6432 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006433
6434 /**
6435 * Enable or disable a modem stack.
6436 */
6437 @Override
6438 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6439 enforceModifyPermission();
6440
6441 final long identity = Binder.clearCallingIdentity();
6442 try {
6443 Phone phone = PhoneFactory.getPhone(slotIndex);
6444 if (phone == null) {
6445 return false;
6446 } else {
6447 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6448 }
6449 } finally {
6450 Binder.restoreCallingIdentity(identity);
6451 }
6452 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006453}