blob: e251516cc2ef9675f040316ef849d272e6b5bf39 [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 Berionne0963c862018-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 Yu311536f2018-11-26 11:20:48 -080086import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080087import 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 Ebinger4c460712018-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 Ebinger4c460712018-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 Ebinger4c460712018-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 xu02581692018-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 Chenf144d942018-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;
sqian2fff4a32018-11-05 14:18:37 -0800132import 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;
sqian9d4df8b2019-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;
sqian2fff4a32018-11-05 14:18:37 -0800158import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800159import java.util.HashMap;
sqian9d4df8b2019-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;
sqian9d4df8b2019-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 xu1cc0abe2018-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 Meng0c05b502018-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 xu1cc0abe2018-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 Chen509b5b72019-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 Chenf144d942018-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
Micheled3107c52018-12-21 15:00:11 -0800268 // String to store multi SIM allowed
269 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
270
Derek Tan740e1672017-06-27 14:56:27 -0700271 // The AID of ISD-R.
272 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
273
yinxub1bed742017-04-17 11:45:04 -0700274 private NetworkScanRequestTracker mNetworkScanRequestTracker;
275
David Kelly5e06a7f2018-03-12 14:10:59 +0000276 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
277 private static final int MANUFACTURER_CODE_LENGTH = 8;
278
Derek Tan89e89d42014-07-08 17:00:10 -0700279 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700280 * A request object to use for transmitting data to an ICC.
281 */
282 private static final class IccAPDUArgument {
283 public int channel, cla, command, p1, p2, p3;
284 public String data;
285
286 public IccAPDUArgument(int channel, int cla, int command,
287 int p1, int p2, int p3, String data) {
288 this.channel = channel;
289 this.cla = cla;
290 this.command = command;
291 this.p1 = p1;
292 this.p2 = p2;
293 this.p3 = p3;
294 this.data = data;
295 }
296 }
297
298 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700299 * A request object to use for transmitting data to an ICC.
300 */
301 private static final class ManualNetworkSelectionArgument {
302 public OperatorInfo operatorInfo;
303 public boolean persistSelection;
304
305 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
306 this.operatorInfo = operatorInfo;
307 this.persistSelection = persistSelection;
308 }
309 }
310
311 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
313 * request after sending. The main thread will notify the request when it is complete.
314 */
315 private static final class MainThreadRequest {
316 /** The argument to use for the request */
317 public Object argument;
318 /** The result of the request that is run on the main thread */
319 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800320 // The subscriber id that this request applies to. Defaults to
321 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
322 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700323
Nathan Harold92bed182018-10-12 18:16:49 -0700324 // In cases where subId is unavailable, the caller needs to specify the phone.
325 public Phone phone;
326
vagdevie435a3e2018-08-15 16:01:53 -0700327 public WorkSource workSource;
328
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 public MainThreadRequest(Object argument) {
330 this.argument = argument;
331 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800332
Nathan Harold92bed182018-10-12 18:16:49 -0700333 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
334 this.argument = argument;
335 if (phone != null) {
336 this.phone = phone;
337 }
338 this.workSource = workSource;
339 }
340
vagdevie435a3e2018-08-15 16:01:53 -0700341 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800342 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800343 if (subId != null) {
344 this.subId = subId;
345 }
vagdevie435a3e2018-08-15 16:01:53 -0700346 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 }
349
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800350 private static final class IncomingThirdPartyCallArgs {
351 public final ComponentName component;
352 public final String callId;
353 public final String callerDisplayName;
354
355 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
356 String callerDisplayName) {
357 this.component = component;
358 this.callId = callId;
359 this.callerDisplayName = callerDisplayName;
360 }
361 }
362
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 /**
364 * A handler that processes messages on the main thread in the phone process. Since many
365 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
366 * inbound binder threads to the main thread in the phone process. The Binder thread
367 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
368 * on, which will be notified when the operation completes and will contain the result of the
369 * request.
370 *
371 * <p>If a MainThreadRequest object is provided in the msg.obj field,
372 * note that request.result must be set to something non-null for the calling thread to
373 * unblock.
374 */
375 private final class MainThreadHandler extends Handler {
376 @Override
377 public void handleMessage(Message msg) {
378 MainThreadRequest request;
379 Message onCompleted;
380 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800381 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700382 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800383 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
385 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700386 case CMD_HANDLE_USSD_REQUEST: {
387 request = (MainThreadRequest) msg.obj;
388 final Phone phone = getPhoneFromRequest(request);
389 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
390 String ussdRequest = ussdObject.first;
391 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700392
Pengquan Meng0c05b502018-09-06 09:59:22 -0700393 if (!isUssdApiAllowed(request.subId)) {
394 // Carrier does not support use of this API, return failure.
395 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
396 UssdResponse response = new UssdResponse(ussdRequest, null);
397 Bundle returnData = new Bundle();
398 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
399 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700400
Pengquan Meng0c05b502018-09-06 09:59:22 -0700401 request.result = true;
402 notifyRequester(request);
403 return;
404 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700405
Pengquan Meng0c05b502018-09-06 09:59:22 -0700406 try {
407 request.result = phone != null
408 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
409 } catch (CallStateException cse) {
410 request.result = false;
411 }
412 // Wake up the requesting thread
413 notifyRequester(request);
414 break;
pkanwar32d516d2016-10-14 19:37:38 -0700415 }
416
Yorke Lee716f67e2015-06-17 15:39:16 -0700417 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700419 final Phone phone = getPhoneFromRequest(request);
420 request.result = phone != null ?
421 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
422 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700424 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700430 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800431 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700432 if (uiccCard == null) {
433 loge("iccTransmitApduLogicalChannel: No UICC");
434 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700435 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700436 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
438 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700439 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 iccArgument.channel, iccArgument.cla, iccArgument.command,
441 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700443 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 break;
445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 ar = (AsyncResult) msg.obj;
448 request = (MainThreadRequest) ar.userObj;
449 if (ar.exception == null && ar.result != null) {
450 request.result = ar.result;
451 } else {
452 request.result = new IccIoResult(0x6F, 0, (byte[])null);
453 if (ar.result == null) {
454 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800455 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800457 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700458 } else {
459 loge("iccTransmitApduLogicalChannel: Unknown exception");
460 }
461 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700462 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 break;
464
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
466 request = (MainThreadRequest) msg.obj;
467 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800468 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700469 if (uiccCard == null) {
470 loge("iccTransmitApduBasicChannel: No UICC");
471 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700472 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700473 } else {
474 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
475 request);
476 uiccCard.iccTransmitApduBasicChannel(
477 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
478 iccArgument.p3, iccArgument.data, onCompleted);
479 }
480 break;
481
482 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
483 ar = (AsyncResult) msg.obj;
484 request = (MainThreadRequest) ar.userObj;
485 if (ar.exception == null && ar.result != null) {
486 request.result = ar.result;
487 } else {
488 request.result = new IccIoResult(0x6F, 0, (byte[])null);
489 if (ar.result == null) {
490 loge("iccTransmitApduBasicChannel: Empty response");
491 } else if (ar.exception instanceof CommandException) {
492 loge("iccTransmitApduBasicChannel: CommandException: " +
493 ar.exception);
494 } else {
495 loge("iccTransmitApduBasicChannel: Unknown exception");
496 }
497 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700498 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 break;
500
501 case CMD_EXCHANGE_SIM_IO:
502 request = (MainThreadRequest) msg.obj;
503 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800504 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 if (uiccCard == null) {
506 loge("iccExchangeSimIO: No UICC");
507 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700508 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 } else {
510 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
511 request);
512 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
513 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
514 iccArgument.data, onCompleted);
515 }
516 break;
517
518 case EVENT_EXCHANGE_SIM_IO_DONE:
519 ar = (AsyncResult) msg.obj;
520 request = (MainThreadRequest) ar.userObj;
521 if (ar.exception == null && ar.result != null) {
522 request.result = ar.result;
523 } else {
524 request.result = new IccIoResult(0x6f, 0, (byte[])null);
525 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700526 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 break;
528
Derek Tan4d5e5c12014-02-04 11:54:58 -0800529 case CMD_SEND_ENVELOPE:
530 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800531 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700532 if (uiccCard == null) {
533 loge("sendEnvelopeWithStatus: No UICC");
534 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700535 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700536 } else {
537 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
538 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
539 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800540 break;
541
542 case EVENT_SEND_ENVELOPE_DONE:
543 ar = (AsyncResult) msg.obj;
544 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700545 if (ar.exception == null && ar.result != null) {
546 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700548 request.result = new IccIoResult(0x6F, 0, (byte[])null);
549 if (ar.result == null) {
550 loge("sendEnvelopeWithStatus: Empty response");
551 } else if (ar.exception instanceof CommandException) {
552 loge("sendEnvelopeWithStatus: CommandException: " +
553 ar.exception);
554 } else {
555 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
556 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800557 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700558 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800559 break;
560
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 case CMD_OPEN_CHANNEL:
562 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800564 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 if (uiccCard == null) {
566 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800567 request.result = new IccOpenLogicalChannelResponse(-1,
568 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800572 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
573 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700574 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 break;
576
577 case EVENT_OPEN_CHANNEL_DONE:
578 ar = (AsyncResult) msg.obj;
579 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700580 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 int[] result = (int[]) ar.result;
583 int channelId = result[0];
584 byte[] selectResponse = null;
585 if (result.length > 1) {
586 selectResponse = new byte[result.length - 1];
587 for (int i = 1; i < result.length; ++i) {
588 selectResponse[i - 1] = (byte) result[i];
589 }
590 }
591 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700592 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 if (ar.result == null) {
595 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 if (ar.exception != null) {
598 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
599 }
600
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700601 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700602 if (ar.exception instanceof CommandException) {
603 CommandException.Error error =
604 ((CommandException) (ar.exception)).getCommandError();
605 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700606 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700607 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700608 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 }
610 }
611 openChannelResp = new IccOpenLogicalChannelResponse(
612 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700614 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700615 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 break;
617
618 case CMD_CLOSE_CHANNEL:
619 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800620 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700621 if (uiccCard == null) {
622 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900623 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700625 } else {
626 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
627 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
628 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 break;
630
631 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800632 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
633 break;
634
635 case CMD_NV_READ_ITEM:
636 request = (MainThreadRequest) msg.obj;
637 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800638 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
639 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800640 break;
641
642 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 ar = (AsyncResult) msg.obj;
644 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800645 if (ar.exception == null && ar.result != null) {
646 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800648 request.result = "";
649 if (ar.result == null) {
650 loge("nvReadItem: Empty response");
651 } else if (ar.exception instanceof CommandException) {
652 loge("nvReadItem: CommandException: " +
653 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800655 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 }
657 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700658 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 break;
660
Jake Hambye994d462014-02-03 13:10:13 -0800661 case CMD_NV_WRITE_ITEM:
662 request = (MainThreadRequest) msg.obj;
663 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
664 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800665 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700666 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800667 break;
668
669 case EVENT_NV_WRITE_ITEM_DONE:
670 handleNullReturnEvent(msg, "nvWriteItem");
671 break;
672
673 case CMD_NV_WRITE_CDMA_PRL:
674 request = (MainThreadRequest) msg.obj;
675 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800676 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800677 break;
678
679 case EVENT_NV_WRITE_CDMA_PRL_DONE:
680 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
681 break;
682
chen xu1cc0abe2018-10-26 17:39:23 -0700683 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800684 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700685 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800686 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800687 break;
688
chen xu1cc0abe2018-10-26 17:39:23 -0700689 case EVENT_RESET_MODEM_CONFIG_DONE:
690 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800691 break;
692
Jake Hamby7c27be32014-03-03 13:25:59 -0800693 case CMD_GET_PREFERRED_NETWORK_TYPE:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700696 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800697 break;
698
699 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
700 ar = (AsyncResult) msg.obj;
701 request = (MainThreadRequest) ar.userObj;
702 if (ar.exception == null && ar.result != null) {
703 request.result = ar.result; // Integer
704 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800705 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800706 if (ar.result == null) {
707 loge("getPreferredNetworkType: Empty response");
708 } else if (ar.exception instanceof CommandException) {
709 loge("getPreferredNetworkType: CommandException: " +
710 ar.exception);
711 } else {
712 loge("getPreferredNetworkType: Unknown exception");
713 }
714 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700715 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800716 break;
717
718 case CMD_SET_PREFERRED_NETWORK_TYPE:
719 request = (MainThreadRequest) msg.obj;
720 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
721 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700722 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 break;
724
725 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
726 handleNullReturnEvent(msg, "setPreferredNetworkType");
727 break;
728
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000729 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
730 request = (MainThreadRequest)msg.obj;
731 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800732 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000733 break;
734
735 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
736 ar = (AsyncResult)msg.obj;
737 request = (MainThreadRequest)ar.userObj;
738 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700739 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000740 break;
741
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800742 case CMD_SET_VOICEMAIL_NUMBER:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
745 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800746 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
747 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800748 break;
749
750 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
751 handleNullReturnEvent(msg, "setVoicemailNumber");
752 break;
753
Stuart Scott54788802015-03-30 13:18:01 -0700754 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
757 request);
758 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
759 break;
760
761 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
762 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
763 break;
764
Shishir Agrawal302c8692015-06-19 13:49:39 -0700765 case CMD_PERFORM_NETWORK_SCAN:
766 request = (MainThreadRequest) msg.obj;
767 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
768 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
769 break;
770
771 case EVENT_PERFORM_NETWORK_SCAN_DONE:
772 ar = (AsyncResult) msg.obj;
773 request = (MainThreadRequest) ar.userObj;
774 CellNetworkScanResult cellScanResult;
775 if (ar.exception == null && ar.result != null) {
776 cellScanResult = new CellNetworkScanResult(
777 CellNetworkScanResult.STATUS_SUCCESS,
778 (List<OperatorInfo>) ar.result);
779 } else {
780 if (ar.result == null) {
781 loge("getCellNetworkScanResults: Empty response");
782 }
783 if (ar.exception != null) {
784 loge("getCellNetworkScanResults: Exception: " + ar.exception);
785 }
786 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
787 if (ar.exception instanceof CommandException) {
788 CommandException.Error error =
789 ((CommandException) (ar.exception)).getCommandError();
790 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
791 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
792 } else if (error == CommandException.Error.GENERIC_FAILURE) {
793 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
794 }
795 }
796 cellScanResult = new CellNetworkScanResult(errorCode, null);
797 }
798 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700799 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700800 break;
801
802 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
803 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700804 ManualNetworkSelectionArgument selArg =
805 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700806 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
807 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700808 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
809 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700810 break;
811
812 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700813 ar = (AsyncResult) msg.obj;
814 request = (MainThreadRequest) ar.userObj;
815 if (ar.exception == null) {
816 request.result = true;
817 } else {
818 request.result = false;
819 loge("setNetworkSelectionModeManual " + ar.exception);
820 }
821 notifyRequester(request);
822 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700823 break;
824
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700825 case CMD_GET_MODEM_ACTIVITY_INFO:
826 request = (MainThreadRequest) msg.obj;
827 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800828 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700829 break;
830
831 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
832 ar = (AsyncResult) msg.obj;
833 request = (MainThreadRequest) ar.userObj;
834 if (ar.exception == null && ar.result != null) {
835 request.result = ar.result;
836 } else {
837 if (ar.result == null) {
838 loge("queryModemActivityInfo: Empty response");
839 } else if (ar.exception instanceof CommandException) {
840 loge("queryModemActivityInfo: CommandException: " +
841 ar.exception);
842 } else {
843 loge("queryModemActivityInfo: Unknown exception");
844 }
845 }
Amit Mahajand4766222016-01-28 15:28:28 -0800846 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
847 if (request.result == null) {
848 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
849 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700850 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700851 break;
852
Meng Wang1a7c35a2016-05-05 20:56:15 -0700853 case CMD_SET_ALLOWED_CARRIERS:
854 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800855 CarrierRestrictionRules argument =
856 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700857 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800858 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700859 break;
860
861 case EVENT_SET_ALLOWED_CARRIERS_DONE:
862 ar = (AsyncResult) msg.obj;
863 request = (MainThreadRequest) ar.userObj;
864 if (ar.exception == null && ar.result != null) {
865 request.result = ar.result;
866 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800867 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
868 if (ar.exception instanceof CommandException) {
869 loge("setAllowedCarriers: CommandException: " + ar.exception);
870 CommandException.Error error =
871 ((CommandException) (ar.exception)).getCommandError();
872 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
873 request.result =
874 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
875 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700876 } else {
877 loge("setAllowedCarriers: Unknown exception");
878 }
879 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700880 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700881 break;
882
883 case CMD_GET_ALLOWED_CARRIERS:
884 request = (MainThreadRequest) msg.obj;
885 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800886 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700887 break;
888
889 case EVENT_GET_ALLOWED_CARRIERS_DONE:
890 ar = (AsyncResult) msg.obj;
891 request = (MainThreadRequest) ar.userObj;
892 if (ar.exception == null && ar.result != null) {
893 request.result = ar.result;
894 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800895 request.result = new IllegalStateException(
896 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700897 if (ar.result == null) {
898 loge("getAllowedCarriers: Empty response");
899 } else if (ar.exception instanceof CommandException) {
900 loge("getAllowedCarriers: CommandException: " +
901 ar.exception);
902 } else {
903 loge("getAllowedCarriers: Unknown exception");
904 }
905 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700906 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700907 break;
908
Nathan Haroldb3014052017-01-25 15:57:32 -0800909 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result;
914 } else {
915 request.result = new IllegalArgumentException(
916 "Failed to retrieve Forbidden Plmns");
917 if (ar.result == null) {
918 loge("getForbiddenPlmns: Empty response");
919 } else {
920 loge("getForbiddenPlmns: Unknown exception");
921 }
922 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700923 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800924 break;
925
926 case CMD_GET_FORBIDDEN_PLMNS:
927 request = (MainThreadRequest) msg.obj;
928 uiccCard = getUiccCardFromRequest(request);
929 if (uiccCard == null) {
930 loge("getForbiddenPlmns() UiccCard is null");
931 request.result = new IllegalArgumentException(
932 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700933 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800934 break;
935 }
936 Integer appType = (Integer) request.argument;
937 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
938 if (uiccApp == null) {
939 loge("getForbiddenPlmns() no app with specified type -- "
940 + appType);
941 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700942 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800943 break;
944 } else {
945 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
946 + " specified type -- " + appType);
947 }
948 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
949 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
950 onCompleted);
951 break;
952
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000953 case CMD_SWITCH_SLOTS:
954 request = (MainThreadRequest) msg.obj;
955 int[] physicalSlots = (int[]) request.argument;
956 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
957 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
958 break;
959
960 case EVENT_SWITCH_SLOTS_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700964 notifyRequester(request);
965 break;
966 case CMD_GET_NETWORK_SELECTION_MODE:
967 request = (MainThreadRequest) msg.obj;
968 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
969 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
970 break;
971
972 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 if (ar.exception != null) {
976 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
977 } else {
978 int mode = ((int[]) ar.result)[0];
979 if (mode == 0) {
980 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
981 } else {
982 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
983 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000984 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700985 notifyRequester(request);
986 break;
987 case CMD_GET_CDMA_ROAMING_MODE:
988 request = (MainThreadRequest) msg.obj;
989 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
990 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
991 break;
992 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 if (ar.exception != null) {
996 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
997 } else {
998 request.result = ((int[]) ar.result)[0];
999 }
1000 notifyRequester(request);
1001 break;
1002 case CMD_SET_CDMA_ROAMING_MODE:
1003 request = (MainThreadRequest) msg.obj;
1004 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1005 int mode = (int) request.argument;
1006 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1007 break;
1008 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
1011 request.result = ar.exception == null;
1012 notifyRequester(request);
1013 break;
1014 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1015 request = (MainThreadRequest) msg.obj;
1016 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1017 int subscriptionMode = (int) request.argument;
1018 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1019 break;
1020 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
1023 request.result = ar.exception == null;
1024 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001025 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001026 case CMD_GET_ALL_CELL_INFO:
1027 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001028 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001029 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001030 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001031 case EVENT_GET_ALL_CELL_INFO_DONE:
1032 ar = (AsyncResult) msg.obj;
1033 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001034 // If a timeout occurs, the response will be null
1035 request.result = (ar.exception == null && ar.result != null)
1036 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001037 synchronized (request) {
1038 request.notifyAll();
1039 }
1040 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001041 case CMD_REQUEST_CELL_INFO_UPDATE:
1042 request = (MainThreadRequest) msg.obj;
1043 request.phone.requestCellInfoUpdate(request.workSource,
1044 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1045 break;
1046 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1047 ar = (AsyncResult) msg.obj;
1048 request = (MainThreadRequest) ar.userObj;
1049 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1050 try {
1051 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001052 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001053 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1054 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001055 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001056 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001057 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001058 } else {
1059 // use the result as returned
1060 cb.onCellInfo((List<CellInfo>) ar.result);
1061 }
1062 } catch (RemoteException re) {
1063 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1064 }
1065 break;
1066 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001067 request = (MainThreadRequest) msg.obj;
1068 WorkSource ws = (WorkSource) request.argument;
1069 Phone phone = getPhoneFromRequest(request);
1070 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1071 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001072 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001073 ar = (AsyncResult) msg.obj;
1074 request = (MainThreadRequest) ar.userObj;
1075 if (ar.exception == null) {
1076 request.result = ar.result;
1077 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001078 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001079 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1080 ? new CdmaCellLocation() : new GsmCellLocation();
1081 }
1082
1083 synchronized (request) {
1084 request.notifyAll();
1085 }
1086 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001087 case CMD_MODEM_REBOOT:
1088 request = (MainThreadRequest) msg.obj;
1089 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001090 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001091 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001092 case EVENT_CMD_MODEM_REBOOT_DONE:
1093 handleNullReturnEvent(msg, "rebootModem");
1094 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001095 case CMD_REQUEST_ENABLE_MODEM:
1096 request = (MainThreadRequest) msg.obj;
1097 boolean enable = (boolean) request.argument;
1098 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
1099 PhoneConfigurationManager.getInstance()
1100 .enablePhone(request.phone, enable, onCompleted);
1101 break;
1102 case EVENT_ENABLE_MODEM_DONE:
1103 ar = (AsyncResult) msg.obj;
1104 request = (MainThreadRequest) ar.userObj;
1105 request.result = (ar.exception == null);
1106 notifyRequester(request);
1107 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001108 default:
1109 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1110 break;
1111 }
1112 }
Jake Hambye994d462014-02-03 13:10:13 -08001113
Pengquan Meng0c05b502018-09-06 09:59:22 -07001114 private void notifyRequester(MainThreadRequest request) {
1115 synchronized (request) {
1116 request.notifyAll();
1117 }
1118 }
1119
Jake Hambye994d462014-02-03 13:10:13 -08001120 private void handleNullReturnEvent(Message msg, String command) {
1121 AsyncResult ar = (AsyncResult) msg.obj;
1122 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1123 if (ar.exception == null) {
1124 request.result = true;
1125 } else {
1126 request.result = false;
1127 if (ar.exception instanceof CommandException) {
1128 loge(command + ": CommandException: " + ar.exception);
1129 } else {
1130 loge(command + ": Unknown exception");
1131 }
1132 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001133 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001135 }
1136
1137 /**
1138 * Posts the specified command to be executed on the main thread,
1139 * waits for the request to complete, and returns the result.
1140 * @see #sendRequestAsync
1141 */
1142 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001143 return sendRequest(
1144 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001145 }
1146
1147 /**
1148 * Posts the specified command to be executed on the main thread,
1149 * waits for the request to complete, and returns the result.
1150 * @see #sendRequestAsync
1151 */
1152 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1153 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001154 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001155 }
1156
1157 /**
1158 * Posts the specified command to be executed on the main thread,
1159 * waits for the request to complete, and returns the result.
1160 * @see #sendRequestAsync
1161 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001162 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001163 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001164 }
1165
1166 /**
1167 * Posts the specified command to be executed on the main thread,
1168 * waits for the request to complete, and returns the result.
1169 * @see #sendRequestAsync
1170 */
Nathan Harold92bed182018-10-12 18:16:49 -07001171 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1172 return sendRequest(command, argument, subId, null, workSource);
1173 }
1174
1175 /**
1176 * Posts the specified command to be executed on the main thread,
1177 * waits for the request to complete, and returns the result.
1178 * @see #sendRequestAsync
1179 */
1180 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1181 return sendRequest(
1182 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1183 }
1184
1185 /**
1186 * Posts the specified command to be executed on the main thread,
1187 * waits for the request to complete, and returns the result.
1188 * @see #sendRequestAsync
1189 */
1190 private Object sendRequest(
1191 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1193 throw new RuntimeException("This method will deadlock if called from the main thread.");
1194 }
1195
Nathan Harold92bed182018-10-12 18:16:49 -07001196 MainThreadRequest request = null;
1197 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1198 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1199 } else if (phone != null) {
1200 request = new MainThreadRequest(argument, phone, workSource);
1201 } else {
1202 request = new MainThreadRequest(argument, subId, workSource);
1203 }
1204
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001205 Message msg = mMainThreadHandler.obtainMessage(command, request);
1206 msg.sendToTarget();
1207
1208 // Wait for the request to complete
1209 synchronized (request) {
1210 while (request.result == null) {
1211 try {
1212 request.wait();
1213 } catch (InterruptedException e) {
1214 // Do nothing, go back and wait until the request is complete
1215 }
1216 }
1217 }
1218 return request.result;
1219 }
1220
1221 /**
1222 * Asynchronous ("fire and forget") version of sendRequest():
1223 * Posts the specified command to be executed on the main thread, and
1224 * returns immediately.
1225 * @see #sendRequest
1226 */
1227 private void sendRequestAsync(int command) {
1228 mMainThreadHandler.sendEmptyMessage(command);
1229 }
1230
1231 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001232 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001233 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001234 */
1235 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001236 sendRequestAsync(command, argument, null, null);
1237 }
1238
1239 /**
1240 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1241 * @see {@link #sendRequest(int,Object)}
1242 */
1243 private void sendRequestAsync(
1244 int command, Object argument, Phone phone, WorkSource workSource) {
1245 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001246 Message msg = mMainThreadHandler.obtainMessage(command, request);
1247 msg.sendToTarget();
1248 }
1249
1250 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001251 * Initialize the singleton PhoneInterfaceManager instance.
1252 * This is only done once, at startup, from PhoneApp.onCreate().
1253 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001254 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001255 synchronized (PhoneInterfaceManager.class) {
1256 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001257 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 } else {
1259 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1260 }
1261 return sInstance;
1262 }
1263 }
1264
1265 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001266 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001267 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001268 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001269 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001270 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1271 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001272 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001273 mTelephonySharedPreferences =
1274 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001275 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001276 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001277
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 publish();
1279 }
1280
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001281 private Phone getDefaultPhone() {
1282 Phone thePhone = getPhone(getDefaultSubscription());
1283 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1284 }
1285
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 private void publish() {
1287 if (DBG) log("publish: " + this);
1288
1289 ServiceManager.addService("phone", this);
1290 }
1291
Stuart Scott584921c2015-01-15 17:10:34 -08001292 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001293 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001294 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001295 }
1296
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001297 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1298 Phone phone = getPhoneFromRequest(request);
1299 return phone == null ? null :
1300 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1301 }
1302
Wink Saville36469e72014-06-11 15:17:00 -07001303 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001304 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001305 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307
1308 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001309 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001310 }
1311
Wink Savilleb564aae2014-10-23 10:18:09 -07001312 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 if (DBG) log("dial: " + number);
1314 // No permission check needed here: This is just a wrapper around the
1315 // ACTION_DIAL intent, which is available to any app since it puts up
1316 // the UI before it does anything.
1317
Malcolm Chend965c8b2018-02-28 15:00:40 -08001318 final long identity = Binder.clearCallingIdentity();
1319 try {
1320 String url = createTelUrl(number);
1321 if (url == null) {
1322 return;
1323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324
Malcolm Chend965c8b2018-02-28 15:00:40 -08001325 // PENDING: should we just silently fail if phone is offhook or ringing?
1326 PhoneConstants.State state = mCM.getState(subId);
1327 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1328 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1329 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1330 mApp.startActivity(intent);
1331 }
1332 } finally {
1333 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001334 }
1335 }
1336
1337 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001338 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001339 }
1340
Wink Savilleb564aae2014-10-23 10:18:09 -07001341 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 if (DBG) log("call: " + number);
1343
1344 // This is just a wrapper around the ACTION_CALL intent, but we still
1345 // need to do a permission check since we're calling startActivity()
1346 // from the context of the phone app.
1347 enforceCallPermission();
1348
1349 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1350 != AppOpsManager.MODE_ALLOWED) {
1351 return;
1352 }
1353
Malcolm Chend965c8b2018-02-28 15:00:40 -08001354 final long identity = Binder.clearCallingIdentity();
1355 try {
1356 String url = createTelUrl(number);
1357 if (url == null) {
1358 return;
1359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360
Malcolm Chend965c8b2018-02-28 15:00:40 -08001361 boolean isValid = false;
1362 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1363 if (slist != null) {
1364 for (SubscriptionInfo subInfoRecord : slist) {
1365 if (subInfoRecord.getSubscriptionId() == subId) {
1366 isValid = true;
1367 break;
1368 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001369 }
Wink Saville08874612014-08-31 19:19:58 -07001370 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001371 if (!isValid) {
1372 return;
1373 }
Wink Saville08874612014-08-31 19:19:58 -07001374
Malcolm Chend965c8b2018-02-28 15:00:40 -08001375 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1376 intent.putExtra(SUBSCRIPTION_KEY, subId);
1377 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1378 mApp.startActivity(intent);
1379 } finally {
1380 Binder.restoreCallingIdentity(identity);
1381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 }
1383
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001385 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001386 }
1387
Wink Savilleb564aae2014-10-23 10:18:09 -07001388 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001389 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001390 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1391 }
1392
1393 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001394 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001395 }
1396
Wink Savilleb564aae2014-10-23 10:18:09 -07001397 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001398 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001399 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1400 }
1401
1402 /** {@hide} */
1403 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001404 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001405 }
1406
Wink Savilleb564aae2014-10-23 10:18:09 -07001407 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001408 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001409
1410 final long identity = Binder.clearCallingIdentity();
1411 try {
1412 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1413 checkSimPin.start();
1414 return checkSimPin.unlockSim(null, pin);
1415 } finally {
1416 Binder.restoreCallingIdentity(identity);
1417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001418 }
1419
Wink Saville9de0f752013-10-22 19:04:03 -07001420 /** {@hide} */
1421 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001422 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001423 }
1424
Wink Savilleb564aae2014-10-23 10:18:09 -07001425 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001427
1428 final long identity = Binder.clearCallingIdentity();
1429 try {
1430 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1431 checkSimPuk.start();
1432 return checkSimPuk.unlockSim(puk, pin);
1433 } finally {
1434 Binder.restoreCallingIdentity(identity);
1435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001436 }
1437
1438 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001439 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440 * a synchronous one.
1441 */
1442 private static class UnlockSim extends Thread {
1443
1444 private final IccCard mSimCard;
1445
1446 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001447 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1448 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449
1450 // For replies from SimCard interface
1451 private Handler mHandler;
1452
1453 // For async handler to identify request type
1454 private static final int SUPPLY_PIN_COMPLETE = 100;
1455
1456 public UnlockSim(IccCard simCard) {
1457 mSimCard = simCard;
1458 }
1459
1460 @Override
1461 public void run() {
1462 Looper.prepare();
1463 synchronized (UnlockSim.this) {
1464 mHandler = new Handler() {
1465 @Override
1466 public void handleMessage(Message msg) {
1467 AsyncResult ar = (AsyncResult) msg.obj;
1468 switch (msg.what) {
1469 case SUPPLY_PIN_COMPLETE:
1470 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1471 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001472 mRetryCount = msg.arg1;
1473 if (ar.exception != null) {
1474 if (ar.exception instanceof CommandException &&
1475 ((CommandException)(ar.exception)).getCommandError()
1476 == CommandException.Error.PASSWORD_INCORRECT) {
1477 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1478 } else {
1479 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1480 }
1481 } else {
1482 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001484 mDone = true;
1485 UnlockSim.this.notifyAll();
1486 }
1487 break;
1488 }
1489 }
1490 };
1491 UnlockSim.this.notifyAll();
1492 }
1493 Looper.loop();
1494 }
1495
1496 /*
1497 * Use PIN or PUK to unlock SIM card
1498 *
1499 * If PUK is null, unlock SIM card with PIN
1500 *
1501 * If PUK is not null, unlock SIM card with PUK and set PIN code
1502 */
Wink Saville9de0f752013-10-22 19:04:03 -07001503 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504
1505 while (mHandler == null) {
1506 try {
1507 wait();
1508 } catch (InterruptedException e) {
1509 Thread.currentThread().interrupt();
1510 }
1511 }
1512 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1513
1514 if (puk == null) {
1515 mSimCard.supplyPin(pin, callback);
1516 } else {
1517 mSimCard.supplyPuk(puk, pin, callback);
1518 }
1519
1520 while (!mDone) {
1521 try {
1522 Log.d(LOG_TAG, "wait for done");
1523 wait();
1524 } catch (InterruptedException e) {
1525 // Restore the interrupted status
1526 Thread.currentThread().interrupt();
1527 }
1528 }
1529 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001530 int[] resultArray = new int[2];
1531 resultArray[0] = mResult;
1532 resultArray[1] = mRetryCount;
1533 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534 }
1535 }
1536
1537 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001538 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001539
1540 }
1541
Wink Savilleb564aae2014-10-23 10:18:09 -07001542 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 // No permission check needed here: this call is harmless, and it's
1544 // needed for the ServiceState.requestStateUpdate() call (which is
1545 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001546 final long identity = Binder.clearCallingIdentity();
1547 try {
1548 final Phone phone = getPhone(subId);
1549 if (phone != null) {
1550 phone.updateServiceLocation();
1551 }
1552 } finally {
1553 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 }
1556
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001557 @Override
1558 public boolean isRadioOn(String callingPackage) {
1559 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001560 }
1561
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001562 @Override
1563 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001565 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001566 return false;
1567 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001568
1569 final long identity = Binder.clearCallingIdentity();
1570 try {
1571 return isRadioOnForSubscriber(subId);
1572 } finally {
1573 Binder.restoreCallingIdentity(identity);
1574 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001575 }
1576
1577 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001578 final long identity = Binder.clearCallingIdentity();
1579 try {
1580 final Phone phone = getPhone(subId);
1581 if (phone != null) {
1582 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1583 } else {
1584 return false;
1585 }
1586 } finally {
1587 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 }
1590
1591 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001592 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593 }
Wink Saville36469e72014-06-11 15:17:00 -07001594
Wink Savilleb564aae2014-10-23 10:18:09 -07001595 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001597
1598 final long identity = Binder.clearCallingIdentity();
1599 try {
1600 final Phone phone = getPhone(subId);
1601 if (phone != null) {
1602 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1603 }
1604 } finally {
1605 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001606 }
Wink Saville36469e72014-06-11 15:17:00 -07001607 }
1608
1609 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001610 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001611 }
1612
Wink Savilleb564aae2014-10-23 10:18:09 -07001613 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001614 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001615
1616 final long identity = Binder.clearCallingIdentity();
1617 try {
1618 final Phone phone = getPhone(subId);
1619 if (phone == null) {
1620 return false;
1621 }
1622 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1623 toggleRadioOnOffForSubscriber(subId);
1624 }
1625 return true;
1626 } finally {
1627 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 }
Wink Saville36469e72014-06-11 15:17:00 -07001630
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001631 public boolean needMobileRadioShutdown() {
1632 /*
1633 * If any of the Radios are available, it will need to be
1634 * shutdown. So return true if any Radio is available.
1635 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001636 final long identity = Binder.clearCallingIdentity();
1637 try {
1638 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1639 Phone phone = PhoneFactory.getPhone(i);
1640 if (phone != null && phone.isRadioAvailable()) return true;
1641 }
1642 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1643 return false;
1644 } finally {
1645 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001646 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001647 }
1648
Malcolm Chend965c8b2018-02-28 15:00:40 -08001649 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001650 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001651 enforceModifyPermission();
1652
1653 final long identity = Binder.clearCallingIdentity();
1654 try {
1655 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1656 logv("Shutting down Phone " + i);
1657 shutdownRadioUsingPhoneId(i);
1658 }
1659 } finally {
1660 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001661 }
1662 }
1663
1664 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001665 Phone phone = PhoneFactory.getPhone(phoneId);
1666 if (phone != null && phone.isRadioAvailable()) {
1667 phone.shutdownRadio();
1668 }
1669 }
1670
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001672 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001673
1674 final long identity = Binder.clearCallingIdentity();
1675 try {
1676 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1677 if (defaultPhone != null) {
1678 defaultPhone.setRadioPower(turnOn);
1679 return true;
1680 } else {
1681 loge("There's no default phone.");
1682 return false;
1683 }
1684 } finally {
1685 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001686 }
Wink Saville36469e72014-06-11 15:17:00 -07001687 }
1688
Wink Savilleb564aae2014-10-23 10:18:09 -07001689 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001691
1692 final long identity = Binder.clearCallingIdentity();
1693 try {
1694 final Phone phone = getPhone(subId);
1695 if (phone != null) {
1696 phone.setRadioPower(turnOn);
1697 return true;
1698 } else {
1699 return false;
1700 }
1701 } finally {
1702 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 }
1705
Wink Saville36469e72014-06-11 15:17:00 -07001706 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001707 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 public boolean enableDataConnectivity() {
1709 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001710
1711 final long identity = Binder.clearCallingIdentity();
1712 try {
1713 int subId = mSubscriptionController.getDefaultDataSubId();
1714 final Phone phone = getPhone(subId);
1715 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001716 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001717 return true;
1718 } else {
1719 return false;
1720 }
1721 } finally {
1722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 }
1725
Wink Saville36469e72014-06-11 15:17:00 -07001726 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001727 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 public boolean disableDataConnectivity() {
1729 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001730
1731 final long identity = Binder.clearCallingIdentity();
1732 try {
1733 int subId = mSubscriptionController.getDefaultDataSubId();
1734 final Phone phone = getPhone(subId);
1735 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001736 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001737 return true;
1738 } else {
1739 return false;
1740 }
1741 } finally {
1742 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 }
1745
Sanket Padawe356d7632015-06-22 14:03:32 -07001746 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001747 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001748 final long identity = Binder.clearCallingIdentity();
1749 try {
1750 final Phone phone = getPhone(subId);
1751 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001752 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001753 } else {
1754 return false;
1755 }
1756 } finally {
1757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001758 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 }
1760
1761 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001762 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001763 }
1764
pkanwarae03a6b2016-11-06 20:37:09 -08001765 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001766 enforceCallPermission();
1767
1768 final long identity = Binder.clearCallingIdentity();
1769 try {
1770 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1771 return;
1772 }
1773 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1774 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1775 } finally {
1776 Binder.restoreCallingIdentity(identity);
1777 }
pkanwar32d516d2016-10-14 19:37:38 -07001778 };
1779
Wink Savilleb564aae2014-10-23 10:18:09 -07001780 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001782
1783 final long identity = Binder.clearCallingIdentity();
1784 try {
1785 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1786 return false;
1787 }
1788 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1789 } finally {
1790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 }
1793
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001795 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001796 }
1797
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001798 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001799 final long identity = Binder.clearCallingIdentity();
1800 try {
1801 Phone phone = PhoneFactory.getPhone(slotIndex);
1802 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1803 PhoneConstantConversions.convertCallState(phone.getState());
1804 } finally {
1805 Binder.restoreCallingIdentity(identity);
1806 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 }
1808
Sanket Padawe356d7632015-06-22 14:03:32 -07001809 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001811 final long identity = Binder.clearCallingIdentity();
1812 try {
1813 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1814 if (phone != null) {
1815 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1816 } else {
1817 return PhoneConstantConversions.convertDataState(
1818 PhoneConstants.DataState.DISCONNECTED);
1819 }
1820 } finally {
1821 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001822 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 }
1824
Sanket Padawe356d7632015-06-22 14:03:32 -07001825 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001827 final long identity = Binder.clearCallingIdentity();
1828 try {
1829 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1830 if (phone != null) {
1831 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1832 } else {
1833 return TelephonyManager.DATA_ACTIVITY_NONE;
1834 }
1835 } finally {
1836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 }
1839
1840 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001841 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001842 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001843 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001844 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1845 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001846 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 }
1848
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001849 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001850 final long identity = Binder.clearCallingIdentity();
1851 try {
1852 if (DBG_LOC) log("getCellLocation: is active user");
1853 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001854 int subId = mSubscriptionController.getDefaultDataSubId();
1855 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1856 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001857 return data;
1858 } finally {
1859 Binder.restoreCallingIdentity(identity);
1860 }
Svetoslav64fad262015-04-14 14:35:21 -07001861 }
1862
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001864 public String getNetworkCountryIsoForPhone(int phoneId) {
1865 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1866 // registered cell info, so return a NULL country instead.
1867 final long identity = Binder.clearCallingIdentity();
1868 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001869 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1870 // Get default phone in this case.
1871 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1872 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001873 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001874 // Todo: fix this when we can get the actual cellular network info when the device
1875 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001876 if (TelephonyManager.NETWORK_TYPE_IWLAN
1877 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1878 return "";
1879 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001880 Phone phone = PhoneFactory.getPhone(phoneId);
1881 if (phone != null) {
1882 ServiceStateTracker sst = phone.getServiceStateTracker();
1883 if (sst != null) {
1884 LocaleTracker lt = sst.getLocaleTracker();
1885 if (lt != null) {
1886 return lt.getCurrentCountry();
1887 }
1888 }
1889 }
1890 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001891 } finally {
1892 Binder.restoreCallingIdentity(identity);
1893 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001894 }
1895
1896 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001898 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001899 }
1900
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001902 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 mApp.enforceCallingOrSelfPermission(
1904 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001905
1906 final long identity = Binder.clearCallingIdentity();
1907 try {
1908 final Phone phone = getPhone(subId);
1909 if (phone != null) {
1910 phone.enableLocationUpdates();
1911 }
1912 } finally {
1913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 }
1916
1917 @Override
1918 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001919 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001920 }
1921
Sanket Padawe356d7632015-06-22 14:03:32 -07001922 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001923 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 mApp.enforceCallingOrSelfPermission(
1925 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001926
1927 final long identity = Binder.clearCallingIdentity();
1928 try {
1929 final Phone phone = getPhone(subId);
1930 if (phone != null) {
1931 phone.disableLocationUpdates();
1932 }
1933 } finally {
1934 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
Nathan Harold31d7ff32018-10-15 20:20:30 -07001938 /**
1939 * Returns the target SDK version number for a given package name.
1940 *
1941 * @return target SDK if the package is found or INT_MAX.
1942 */
1943 private int getTargetSdk(String packageName) {
1944 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001945 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1946 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001947 if (ai != null) return ai.targetSdkVersion;
1948 } catch (PackageManager.NameNotFoundException unexpected) {
1949 }
1950 return Integer.MAX_VALUE;
1951 }
1952
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 @Override
1954 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001955 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1956 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001957 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1958 throw new SecurityException(
1959 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1960 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001961
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1963 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1964 return null;
1965 }
Svetoslav64fad262015-04-14 14:35:21 -07001966
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001967 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968
Nathan Haroldf180aac2018-06-01 18:43:55 -07001969 List<CellInfo> info = getAllCellInfo(callingPackage);
1970 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971
Nathan Haroldf180aac2018-06-01 18:43:55 -07001972 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1973 for (CellInfo ci : info) {
1974 if (ci instanceof CellInfoGsm) {
1975 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1976 } else if (ci instanceof CellInfoWcdma) {
1977 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1978 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001980 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 }
1982
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001983 private List<CellInfo> getCachedCellInfo() {
1984 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1985 for (Phone phone : PhoneFactory.getPhones()) {
1986 List<CellInfo> info = phone.getAllCellInfo();
1987 if (info != null) cellInfos.addAll(info);
1988 }
1989 return cellInfos;
1990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991
1992 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001993 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001994 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001995 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001996 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001997 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001998 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 }
2000
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002001 final int targetSdk = getTargetSdk(callingPackage);
2002 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2003 return getCachedCellInfo();
2004 }
2005
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002006 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002007 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002008 final long identity = Binder.clearCallingIdentity();
2009 try {
2010 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2011 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002012 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002013 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002014 if (info != null) cellInfos.addAll(info);
2015 }
2016 return cellInfos;
2017 } finally {
2018 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 }
2020 }
2021
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002022 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002023 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2024 requestCellInfoUpdateInternal(
2025 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2026 }
2027
2028 @Override
2029 public void requestCellInfoUpdateWithWorkSource(
2030 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2031 enforceModifyPermission();
2032 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2033 }
2034
2035 private void requestCellInfoUpdateInternal(
2036 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002037 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002038 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002039 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2040 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002041 return;
2042 }
2043
2044 final Phone phone = getPhone(subId);
2045 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2046
2047 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2048 }
2049
2050 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002052 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002053 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002054
2055 final long identity = Binder.clearCallingIdentity();
2056 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002057 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002058 } finally {
2059 Binder.restoreCallingIdentity(identity);
2060 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002061 }
2062
Shishir Agrawala9f32182016-04-12 12:00:16 -07002063 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002064 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002065 Phone phone = PhoneFactory.getPhone(slotIndex);
2066 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002067 return null;
2068 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002069 int subId = phone.getSubId();
2070 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2071 mApp, subId, callingPackage, "getImeiForSlot")) {
2072 return null;
2073 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002074
2075 final long identity = Binder.clearCallingIdentity();
2076 try {
2077 return phone.getImei();
2078 } finally {
2079 Binder.restoreCallingIdentity(identity);
2080 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002081 }
2082
2083 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002084 public String getTypeAllocationCodeForSlot(int slotIndex) {
2085 Phone phone = PhoneFactory.getPhone(slotIndex);
2086 String tac = null;
2087 if (phone != null) {
2088 String imei = phone.getImei();
2089 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2090 }
2091 return tac;
2092 }
2093
2094 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002095 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002096 Phone phone = PhoneFactory.getPhone(slotIndex);
2097 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002098 return null;
2099 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002100
Jeff Davidson913390f2018-02-23 17:11:49 -08002101 int subId = phone.getSubId();
2102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2103 mApp, subId, callingPackage, "getMeidForSlot")) {
2104 return null;
2105 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002106
2107 final long identity = Binder.clearCallingIdentity();
2108 try {
2109 return phone.getMeid();
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
2112 }
Jack Yu2af8d712017-03-15 17:14:14 -07002113 }
2114
2115 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002116 public String getManufacturerCodeForSlot(int slotIndex) {
2117 Phone phone = PhoneFactory.getPhone(slotIndex);
2118 String manufacturerCode = null;
2119 if (phone != null) {
2120 String meid = phone.getMeid();
2121 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2122 }
2123 return manufacturerCode;
2124 }
2125
2126 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002127 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002128 Phone phone = PhoneFactory.getPhone(slotIndex);
2129 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002130 return null;
2131 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002132 int subId = phone.getSubId();
2133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2134 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2135 return null;
2136 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002137
2138 final long identity = Binder.clearCallingIdentity();
2139 try {
2140 return phone.getDeviceSvn();
2141 } finally {
2142 Binder.restoreCallingIdentity(identity);
2143 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002144 }
2145
fionaxu43304da2017-11-27 22:51:16 -08002146 @Override
2147 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002148 final long identity = Binder.clearCallingIdentity();
2149 try {
2150 final Phone phone = getPhone(subId);
2151 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2152 } finally {
2153 Binder.restoreCallingIdentity(identity);
2154 }
fionaxu43304da2017-11-27 22:51:16 -08002155 }
2156
2157 @Override
2158 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002159 final long identity = Binder.clearCallingIdentity();
2160 try {
2161 final Phone phone = getPhone(subId);
2162 return phone == null ? null : phone.getCarrierName();
2163 } finally {
2164 Binder.restoreCallingIdentity(identity);
2165 }
fionaxu43304da2017-11-27 22:51:16 -08002166 }
2167
calvinpaneed9ae82018-11-01 19:43:06 +08002168 @Override
chen xuc93cc282018-11-04 17:17:00 -08002169 public int getSubscriptionPreciseCarrierId(int subId) {
2170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 final Phone phone = getPhone(subId);
2173 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2174 : phone.getPreciseCarrierId();
2175 } finally {
2176 Binder.restoreCallingIdentity(identity);
2177 }
2178 }
2179
2180 @Override
2181 public String getSubscriptionPreciseCarrierName(int subId) {
2182 final long identity = Binder.clearCallingIdentity();
2183 try {
2184 final Phone phone = getPhone(subId);
2185 return phone == null ? null : phone.getPreciseCarrierName();
2186 } finally {
2187 Binder.restoreCallingIdentity(identity);
2188 }
2189 }
2190
chen xu02581692018-11-11 19:03:44 -08002191 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002192 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2193 if (!isSubscriptionMccMnc) {
2194 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2195 }
chen xu02581692018-11-11 19:03:44 -08002196 final Phone phone = PhoneFactory.getPhone(slotIndex);
2197 if (phone == null) {
2198 return TelephonyManager.UNKNOWN_CARRIER_ID;
2199 }
2200 final long identity = Binder.clearCallingIdentity();
2201 try {
2202 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2203 } finally {
2204 Binder.restoreCallingIdentity(identity);
2205 }
2206 }
2207
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208 //
2209 // Internal helper methods.
2210 //
2211
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002212 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2214 *
2215 * @throws SecurityException if the caller does not have the required permission
2216 */
2217 private void enforceModifyPermission() {
2218 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2219 }
2220
2221 /**
2222 * Make sure the caller has the CALL_PHONE permission.
2223 *
2224 * @throws SecurityException if the caller does not have the required permission
2225 */
2226 private void enforceCallPermission() {
2227 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2228 }
2229
Stuart Scott8eef64f2015-04-08 15:13:54 -07002230 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002231 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002232 "ConnectivityService");
2233 }
2234
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 private String createTelUrl(String number) {
2236 if (TextUtils.isEmpty(number)) {
2237 return null;
2238 }
2239
Jake Hambye994d462014-02-03 13:10:13 -08002240 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 }
2242
Ihab Awadf9e92732013-12-05 18:02:52 -08002243 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2245 }
2246
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002247 private static void logv(String msg) {
2248 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2249 }
2250
Ihab Awadf9e92732013-12-05 18:02:52 -08002251 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2253 }
2254
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002255 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002257 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002258 }
2259
Sanket Padawe356d7632015-06-22 14:03:32 -07002260 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002261 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002262 final long identity = Binder.clearCallingIdentity();
2263 try {
2264 final Phone phone = PhoneFactory.getPhone(slotIndex);
2265 if (phone == null) {
2266 return PhoneConstants.PHONE_TYPE_NONE;
2267 } else {
2268 return phone.getPhoneType();
2269 }
2270 } finally {
2271 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 }
2274
2275 /**
2276 * Returns the CDMA ERI icon index to display
2277 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002278 @Override
2279 public int getCdmaEriIconIndex(String callingPackage) {
2280 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002281 }
2282
Sanket Padawe356d7632015-06-22 14:03:32 -07002283 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002284 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002286 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002287 return -1;
2288 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002289
2290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 final Phone phone = getPhone(subId);
2293 if (phone != null) {
2294 return phone.getCdmaEriIconIndex();
2295 } else {
2296 return -1;
2297 }
2298 } finally {
2299 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
2303 /**
2304 * Returns the CDMA ERI icon mode,
2305 * 0 - ON
2306 * 1 - FLASHING
2307 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002308 @Override
2309 public int getCdmaEriIconMode(String callingPackage) {
2310 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002311 }
2312
Sanket Padawe356d7632015-06-22 14:03:32 -07002313 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002314 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002316 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002317 return -1;
2318 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002319
2320 final long identity = Binder.clearCallingIdentity();
2321 try {
2322 final Phone phone = getPhone(subId);
2323 if (phone != null) {
2324 return phone.getCdmaEriIconMode();
2325 } else {
2326 return -1;
2327 }
2328 } finally {
2329 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 }
2332
2333 /**
2334 * Returns the CDMA ERI text,
2335 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002336 @Override
2337 public String getCdmaEriText(String callingPackage) {
2338 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002339 }
2340
Sanket Padawe356d7632015-06-22 14:03:32 -07002341 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002342 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002344 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002345 return null;
2346 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 final Phone phone = getPhone(subId);
2351 if (phone != null) {
2352 return phone.getCdmaEriText();
2353 } else {
2354 return null;
2355 }
2356 } finally {
2357 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 }
2360
2361 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002362 * Returns the CDMA MDN.
2363 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002364 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002365 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2367 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002368
2369 final long identity = Binder.clearCallingIdentity();
2370 try {
2371 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002372 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002373 return phone.getLine1Number();
2374 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002375 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002376 return null;
2377 }
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002380 }
2381 }
2382
2383 /**
2384 * Returns the CDMA MIN.
2385 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002386 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002387 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2389 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002390
2391 final long identity = Binder.clearCallingIdentity();
2392 try {
2393 final Phone phone = getPhone(subId);
2394 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2395 return phone.getCdmaMin();
2396 } else {
2397 return null;
2398 }
2399 } finally {
2400 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002401 }
2402 }
2403
Hall Liud892bec2018-11-30 14:51:45 -08002404 @Override
2405 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2406 INumberVerificationCallback callback, String callingPackage) {
2407 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2408 != PERMISSION_GRANTED) {
2409 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2410 }
2411 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2412
2413 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2414 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2415 throw new SecurityException("Calling package must be configured in the device config");
2416 }
2417
2418 if (range == null) {
2419 throw new NullPointerException("Range must be non-null");
2420 }
2421
2422 timeoutMillis = Math.min(timeoutMillis,
2423 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2424
2425 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2426 }
2427
Junda Liuca05d5d2014-08-14 22:36:34 -07002428 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 * Returns true if CDMA provisioning needs to run.
2430 */
2431 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002432 final long identity = Binder.clearCallingIdentity();
2433 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002434 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002435 } finally {
2436 Binder.restoreCallingIdentity(identity);
2437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002438 }
2439
2440 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002441 * Sets the voice mail number of a given subId.
2442 */
2443 @Override
2444 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002445 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002446
2447 final long identity = Binder.clearCallingIdentity();
2448 try {
2449 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2450 new Pair<String, String>(alphaTag, number), new Integer(subId));
2451 return success;
2452 } finally {
2453 Binder.restoreCallingIdentity(identity);
2454 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002455 }
2456
Ta-wei Yen87c49842016-05-13 21:19:52 -07002457 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002458 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2459 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002460 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002461 if (!TextUtils.equals(callingPackage, systemDialer)) {
2462 throw new SecurityException("caller must be system dialer");
2463 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002464
2465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2468 if (phoneAccountHandle == null) {
2469 return null;
2470 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002471 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002472 } finally {
2473 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002474 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002475 }
2476
2477 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002478 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002479 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002480 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002481 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002482 return null;
2483 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002484
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002485 final long identity = Binder.clearCallingIdentity();
2486 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002487 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002488 } finally {
2489 Binder.restoreCallingIdentity(identity);
2490 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002491 }
2492
2493 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002494 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2495 VisualVoicemailSmsFilterSettings settings) {
2496 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002497
2498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002501 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002502 } finally {
2503 Binder.restoreCallingIdentity(identity);
2504 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002505 }
2506
2507 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002508 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2509 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002510
2511 final long identity = Binder.clearCallingIdentity();
2512 try {
2513 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002514 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002515 } finally {
2516 Binder.restoreCallingIdentity(identity);
2517 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002518 }
2519
2520 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002521 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2522 String callingPackage, int subId) {
2523 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002524
2525 final long identity = Binder.clearCallingIdentity();
2526 try {
2527 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002528 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002529 } finally {
2530 Binder.restoreCallingIdentity(identity);
2531 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002532 }
2533
2534 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002535 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002536 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002537
2538 final long identity = Binder.clearCallingIdentity();
2539 try {
2540 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002541 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002542 } finally {
2543 Binder.restoreCallingIdentity(identity);
2544 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002545 }
2546
2547 @Override
2548 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2549 String number, int port, String text, PendingIntent sentIntent) {
2550 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002551 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002552 enforceSendSmsPermission();
2553 // Make the calls as the phone process.
2554 final long identity = Binder.clearCallingIdentity();
2555 try {
2556 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2557 if (port == 0) {
2558 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2559 sentIntent, null, false);
2560 } else {
2561 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2562 smsManager.sendDataMessageWithSelfPermissions(number, null,
2563 (short) port, data, sentIntent, null);
2564 }
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
2567 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002568 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002569 /**
fionaxu0152e512016-11-14 13:36:14 -08002570 * Sets the voice activation state of a given subId.
2571 */
2572 @Override
2573 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2575 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002576
2577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 final Phone phone = getPhone(subId);
2580 if (phone != null) {
2581 phone.setVoiceActivationState(activationState);
2582 } else {
2583 loge("setVoiceActivationState fails with invalid subId: " + subId);
2584 }
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002587 }
2588 }
2589
2590 /**
2591 * Sets the data activation state of a given subId.
2592 */
2593 @Override
2594 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2596 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002597
2598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 final Phone phone = getPhone(subId);
2601 if (phone != null) {
2602 phone.setDataActivationState(activationState);
2603 } else {
2604 loge("setVoiceActivationState fails with invalid subId: " + subId);
2605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002608 }
2609 }
2610
2611 /**
2612 * Returns the voice activation state of a given subId.
2613 */
2614 @Override
2615 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002616 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002617
fionaxu0152e512016-11-14 13:36:14 -08002618 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002619 final long identity = Binder.clearCallingIdentity();
2620 try {
2621 if (phone != null) {
2622 return phone.getVoiceActivationState();
2623 } else {
2624 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2625 }
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002628 }
2629 }
2630
2631 /**
2632 * Returns the data activation state of a given subId.
2633 */
2634 @Override
2635 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002636 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002637
fionaxu0152e512016-11-14 13:36:14 -08002638 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 if (phone != null) {
2642 return phone.getDataActivationState();
2643 } else {
2644 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2645 }
2646 } finally {
2647 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002648 }
2649 }
2650
2651 /**
Wink Saville36469e72014-06-11 15:17:00 -07002652 * Returns the unread count of voicemails for a subId
2653 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002654 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002655 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2657 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2658 return 0;
2659 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002660 final long identity = Binder.clearCallingIdentity();
2661 try {
2662 final Phone phone = getPhone(subId);
2663 if (phone != null) {
2664 return phone.getVoiceMessageCount();
2665 } else {
2666 return 0;
2667 }
2668 } finally {
2669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002671 }
2672
2673 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002674 * returns true, if the device is in a state where both voice and data
2675 * are supported simultaneously. This can change based on location or network condition.
2676 */
2677 @Override
2678 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002679 final long identity = Binder.clearCallingIdentity();
2680 try {
2681 final Phone phone = getPhone(subId);
2682 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
2685 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002686 }
2687
2688 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002689 * Send the dialer code if called from the current default dialer or the caller has
2690 * carrier privilege.
2691 * @param inputCode The dialer code to send
2692 */
2693 @Override
2694 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002695 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002697 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2698 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002699 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002700 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2701 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002702 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002703
2704 final long identity = Binder.clearCallingIdentity();
2705 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002706 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002707 } finally {
2708 Binder.restoreCallingIdentity(identity);
2709 }
fionaxu235cc5e2017-03-06 22:25:57 -08002710 }
2711
2712 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002713 * Returns the data network type.
2714 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 *
2716 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2717 */
2718 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002719 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 final Phone phone = getPhone(getDefaultSubscription());
2723 if (phone != null) {
2724 return phone.getServiceState().getDataNetworkType();
2725 } else {
2726 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2727 }
2728 } finally {
2729 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002730 }
Wink Saville36469e72014-06-11 15:17:00 -07002731 }
2732
Pengquan Meng0c05b502018-09-06 09:59:22 -07002733 @Override
2734 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002735 if (!isActiveSubscription(subId)) {
2736 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2737 }
2738
Pengquan Meng0c05b502018-09-06 09:59:22 -07002739 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2740 }
2741
Brad Ebinger4c460712018-10-01 10:40:55 -07002742 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002743 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2744 throws RemoteException {
2745 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002746 final long token = Binder.clearCallingIdentity();
2747 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002748 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002749 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002750 .addRegistrationCallbackForSubscription(c, subId);
2751 } finally {
2752 Binder.restoreCallingIdentity(token);
2753 }
2754 }
2755
2756 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002757 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2758 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2760 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2761 }
2762 Binder.withCleanCallingIdentity(() -> {
2763 try {
2764 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002765 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002766 .removeRegistrationCallbackForSubscription(c, subId);
2767 } catch (IllegalArgumentException e) {
2768 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2769 + "is inactive, ignoring unregister.");
2770 // If the subscription is no longer active, just return, since the callback
2771 // will already have been removed internally.
2772 }
2773 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002774 }
2775
2776 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002777 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2778 throws RemoteException {
2779 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002780 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2781 final long token = Binder.clearCallingIdentity();
2782 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002783 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002784 .addCapabilitiesCallbackForSubscription(c, subId);
2785 } finally {
2786 Binder.restoreCallingIdentity(token);
2787 }
2788 }
2789
2790 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002791 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2792 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002793
2794 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2795 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2796 }
2797 Binder.withCleanCallingIdentity(() -> {
2798 try {
2799 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002800 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002801 .removeCapabilitiesCallbackForSubscription(c, subId);
2802 } catch (IllegalArgumentException e) {
2803 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2804 + "is inactive, ignoring unregister.");
2805 // If the subscription is no longer active, just return, since the callback
2806 // will already have been removed internally.
2807 }
2808 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002809 }
2810
2811 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002812 public boolean isCapable(int subId, int capability, int regTech) {
2813 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002814 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2815 final long token = Binder.clearCallingIdentity();
2816 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002817 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002818 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2819 } catch (ImsException e) {
2820 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2821 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002822 } catch (IllegalArgumentException e) {
2823 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2824 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002825 } finally {
2826 Binder.restoreCallingIdentity(token);
2827 }
2828 }
2829
2830 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002831 public boolean isAvailable(int subId, int capability, int regTech) {
2832 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002833 final long token = Binder.clearCallingIdentity();
2834 try {
2835 Phone phone = getPhone(subId);
2836 if (phone == null) return false;
2837 return phone.isImsCapabilityAvailable(capability, regTech);
2838 } finally {
2839 Binder.restoreCallingIdentity(token);
2840 }
2841 }
2842
2843 @Override
2844 public boolean isAdvancedCallingSettingEnabled(int subId) {
2845 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2846 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2847 final long token = Binder.clearCallingIdentity();
2848 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002849 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002850 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2851 } finally {
2852 Binder.restoreCallingIdentity(token);
2853 }
2854 }
2855
2856 @Override
2857 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2859 "setAdvancedCallingSetting");
2860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002863 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002864 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
2867 }
2868 }
2869
2870 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002871 public boolean isVtSettingEnabled(int subId) {
2872 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002876 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002877 getSlotIndexOrException(subId)).isVtEnabledByUser();
2878 } finally {
2879 Binder.restoreCallingIdentity(identity);
2880 }
2881 }
2882
2883 @Override
2884 public void setVtSetting(int subId, boolean isEnabled) {
2885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2886 "setVtSetting");
2887 final long identity = Binder.clearCallingIdentity();
2888 try {
2889 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002890 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002891 } finally {
2892 Binder.restoreCallingIdentity(identity);
2893 }
2894 }
2895
2896 @Override
2897 public boolean isVoWiFiSettingEnabled(int subId) {
2898 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002902 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002903 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
2906 }
2907 }
2908
2909 @Override
2910 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2912 "setVoWiFiSetting");
2913 final long identity = Binder.clearCallingIdentity();
2914 try {
2915 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002916 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002917 } finally {
2918 Binder.restoreCallingIdentity(identity);
2919 }
2920 }
2921
2922 @Override
2923 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2924 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2925 final long identity = Binder.clearCallingIdentity();
2926 try {
2927 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002928 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002929 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
2932 }
2933 }
2934
2935 @Override
2936 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2938 "setVoWiFiRoamingSetting");
2939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002942 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002943 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
2946 }
2947 }
2948
2949 @Override
2950 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2952 "setVoWiFiNonPersistent");
2953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08002956 boolean isRoaming = TelephonyManager.from(
2957 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002958 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08002959 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07002960 } finally {
2961 Binder.restoreCallingIdentity(identity);
2962 }
2963 }
2964
2965 @Override
2966 public int getVoWiFiModeSetting(int subId) {
2967 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2968 final long identity = Binder.clearCallingIdentity();
2969 try {
2970 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002971 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002972 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2973 } finally {
2974 Binder.restoreCallingIdentity(identity);
2975 }
2976 }
2977
2978 @Override
2979 public void setVoWiFiModeSetting(int subId, int mode) {
2980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2981 "setVoWiFiModeSetting");
2982 final long identity = Binder.clearCallingIdentity();
2983 try {
2984 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002985 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002986 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
2989 }
2990 }
2991
2992 @Override
2993 public int getVoWiFiRoamingModeSetting(int subId) {
2994 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002998 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002999 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3000 } finally {
3001 Binder.restoreCallingIdentity(identity);
3002 }
3003 }
3004
3005 @Override
3006 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3008 "setVoWiFiRoamingModeSetting");
3009 final long identity = Binder.clearCallingIdentity();
3010 try {
3011 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003012 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003013 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3014 } finally {
3015 Binder.restoreCallingIdentity(identity);
3016 }
3017 }
3018
3019 @Override
3020 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3022 "setRttCapabilityEnabled");
3023 final long identity = Binder.clearCallingIdentity();
3024 try {
3025 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003026 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003027 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
3031 }
3032
3033 @Override
3034 public boolean isTtyOverVolteEnabled(int subId) {
3035 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3036 final long identity = Binder.clearCallingIdentity();
3037 try {
3038 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003039 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003040 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
3044 }
3045
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003046 @Override
3047 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3048 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003052 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003053 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003054 } finally {
3055 Binder.restoreCallingIdentity(identity);
3056 }
3057 }
3058
3059 @Override
3060 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3061 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3062 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003063 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3064 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3065 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003066 try {
3067 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003068 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003069 .removeProvisioningCallbackForSubscription(callback, subId);
3070 } catch (IllegalArgumentException e) {
3071 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3072 + "is inactive, ignoring unregister.");
3073 // If the subscription is no longer active, just return, since the callback will already
3074 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
3078 }
3079
3080 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003081 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3082 boolean isProvisioned) {
3083 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3084 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3085 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3086 }
3087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3088 "setProvisioningStatusForCapability");
3089 final long identity = Binder.clearCallingIdentity();
3090 try {
3091 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3092 Phone phone = getPhone(subId);
3093 if (phone == null) {
3094 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3095 + subId);
3096 return;
3097 }
3098 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3099 return;
3100 }
3101
3102 // this capability requires provisioning, route to the correct API.
3103 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3104 switch (capability) {
3105 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3106 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3107 ims.setVolteProvisioned(isProvisioned);
3108 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3109 ims.setWfcProvisioned(isProvisioned);
3110 }
3111 break;
3112 }
3113 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3114 // There is currently no difference in VT provisioning type.
3115 ims.setVtProvisioned(isProvisioned);
3116 break;
3117 }
3118 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3119 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3120 // change the capability of the feature instead if needed.
3121 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3122 == isProvisioned) {
3123 // No change in provisioning.
3124 return;
3125 }
3126 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3127 try {
3128 ims.changeMmTelCapability(capability, tech, isProvisioned);
3129 } catch (ImsException e) {
3130 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3131 + ", Exception" + e.getMessage());
3132 }
3133 break;
3134 }
3135 default: {
3136 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3137 + capability + "', which does not require provisioning.");
3138 }
3139 }
3140
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
3143 }
3144 }
3145
3146 @Override
3147 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3148 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3149 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3150 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3151 }
3152 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3153 final long identity = Binder.clearCallingIdentity();
3154 try {
3155 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3156 Phone phone = getPhone(subId);
3157 if (phone == null) {
3158 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3159 + subId);
3160 // We will fail with "true" as the provisioning status because this is the default
3161 // if we do not require provisioning.
3162 return true;
3163 }
3164
3165 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3166 return true;
3167 }
3168
3169 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3170 switch (capability) {
3171 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3172 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3173 return ims.isVolteProvisionedOnDevice();
3174 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3175 return ims.isWfcProvisionedOnDevice();
3176 }
3177 // This should never happen, since we are checking tech above to make sure it
3178 // is either LTE or IWLAN.
3179 throw new IllegalArgumentException("Invalid radio technology for voice "
3180 + "capability.");
3181 }
3182 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3183 // There is currently no difference in VT provisioning type.
3184 return ims.isVtProvisionedOnDevice();
3185 }
3186 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3187 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3188 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3189 }
3190 default: {
3191 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3192 + capability + "', which does not require provisioning.");
3193 }
3194 }
3195
3196 } finally {
3197 Binder.restoreCallingIdentity(identity);
3198 }
3199 }
3200
3201 @Override
3202 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3203 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3204 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3205 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3206 }
3207 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3208 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3209 return (provisionedBits & capability) > 0;
3210 }
3211
3212 @Override
3213 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3214 boolean isProvisioned) {
3215 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3216 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3217 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3218 }
3219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3220 "setProvisioningStatusForCapability");
3221 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3222 // If the current provisioning status for capability already matches isProvisioned,
3223 // do nothing.
3224 if (((provisionedBits & capability) > 0) == isProvisioned) {
3225 return;
3226 }
3227 if (isProvisioned) {
3228 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3229 } else {
3230 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3231 }
3232 }
3233
3234 /**
3235 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3236 * technology. The bitfield should mirror the bitfield defined by
3237 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3238 */
3239 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3240 String key = getMmTelProvisioningKey(subId, tech);
3241 // Default is no capabilities are provisioned.
3242 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3243 }
3244
3245 /**
3246 * Sets the MmTel capability provisioning bitfield (defined by
3247 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3248 * technology specified.
3249 *
3250 * Note: This is a synchronous command and should not be called on UI thread.
3251 */
3252 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3253 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3254 String key = getMmTelProvisioningKey(subId, tech);
3255 editor.putInt(key, newField);
3256 editor.commit();
3257 }
3258
3259 private static String getMmTelProvisioningKey(int subId, int tech) {
3260 // resulting key is provision_ims_mmtel_{subId}_{tech}
3261 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3262 }
3263
3264 /**
3265 * Query CarrierConfig to see if the specified capability requires provisioning for the
3266 * carrier associated with the subscription id.
3267 */
3268 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3269 int capability) {
3270 CarrierConfigManager configManager = new CarrierConfigManager(context);
3271 PersistableBundle c = configManager.getConfigForSubId(subId);
3272 boolean requireUtProvisioning = c.getBoolean(
3273 // By default, this config is true (even if there is no SIM). We also check to make
3274 // sure the subscription needs provisioning here, so we do not need to check for
3275 // the no-SIM case, where we would normally shortcut this to false.
3276 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3277 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3278 false);
3279 boolean requireVoiceVtProvisioning = c.getBoolean(
3280 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3281
3282 // First check to make sure that the capability requires provisioning.
3283 switch (capability) {
3284 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3285 // intentional fallthrough
3286 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3287 if (requireVoiceVtProvisioning) {
3288 // Voice and Video requires provisioning
3289 return true;
3290 }
3291 break;
3292 }
3293 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3294 if (requireUtProvisioning) {
3295 // UT requires provisioning
3296 return true;
3297 }
3298 break;
3299 }
3300 }
3301 return false;
3302 }
3303
3304 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003305 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003306 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3307 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3308 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003309 enforceReadPrivilegedPermission("getImsProvisioningInt");
3310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003313 int slotId = getSlotIndex(subId);
3314 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3315 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3316 + subId + "' for key:" + key);
3317 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3318 }
3319 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003320 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003321 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3322 + subId + "' for key:" + key);
3323 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003324 } finally {
3325 Binder.restoreCallingIdentity(identity);
3326 }
3327 }
3328
3329 @Override
3330 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003331 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3332 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3333 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003334 enforceReadPrivilegedPermission("getImsProvisioningString");
3335 final long identity = Binder.clearCallingIdentity();
3336 try {
3337 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003338 int slotId = getSlotIndex(subId);
3339 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3340 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3341 + subId + "' for key:" + key);
3342 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3343 }
3344 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003345 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003346 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3347 + subId + "' for key:" + key);
3348 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003349 } finally {
3350 Binder.restoreCallingIdentity(identity);
3351 }
3352 }
3353
3354 @Override
3355 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003356 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3357 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3358 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3360 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003361 final long identity = Binder.clearCallingIdentity();
3362 try {
3363 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003364 int slotId = getSlotIndex(subId);
3365 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3366 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3367 + subId + "' for key:" + key);
3368 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3369 }
3370 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003371 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003372 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3373 + "' for key:" + key);
3374 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003375 } finally {
3376 Binder.restoreCallingIdentity(identity);
3377 }
3378 }
3379
3380 @Override
3381 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003382 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3383 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3384 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3386 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003387 final long identity = Binder.clearCallingIdentity();
3388 try {
3389 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003390 int slotId = getSlotIndex(subId);
3391 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3392 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3393 + subId + "' for key:" + key);
3394 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3395 }
3396 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003397 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003398 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3399 + "' for key:" + key);
3400 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003401 } finally {
3402 Binder.restoreCallingIdentity(identity);
3403 }
3404 }
3405
Brad Ebinger4c460712018-10-01 10:40:55 -07003406 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3407 int slotId = SubscriptionManager.getSlotIndex(subId);
3408 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003409 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003410 }
3411 return slotId;
3412 }
3413
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003414 private int getSlotIndex(int subId) {
3415 int slotId = SubscriptionManager.getSlotIndex(subId);
3416 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3417 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3418 }
3419 return slotId;
3420 }
3421
Wink Saville36469e72014-06-11 15:17:00 -07003422 /**
3423 * Returns the network type for a subId
3424 */
3425 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003426 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003427 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003428 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003429 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3430 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003431
Malcolm Chend965c8b2018-02-28 15:00:40 -08003432 final long identity = Binder.clearCallingIdentity();
3433 try {
3434 final Phone phone = getPhone(subId);
3435 if (phone != null) {
3436 return phone.getServiceState().getDataNetworkType();
3437 } else {
3438 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3439 }
3440 } finally {
3441 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003443 }
3444
3445 /**
3446 * Returns the data network type
3447 */
3448 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003449 public int getDataNetworkType(String callingPackage) {
3450 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003451 }
3452
3453 /**
3454 * Returns the data network type for a subId
3455 */
3456 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003457 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003459 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003460 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3461 }
3462
Malcolm Chend965c8b2018-02-28 15:00:40 -08003463 final long identity = Binder.clearCallingIdentity();
3464 try {
3465 final Phone phone = getPhone(subId);
3466 if (phone != null) {
3467 return phone.getServiceState().getDataNetworkType();
3468 } else {
3469 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3470 }
3471 } finally {
3472 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003474 }
3475
3476 /**
Wink Saville36469e72014-06-11 15:17:00 -07003477 * Returns the Voice network type for a subId
3478 */
3479 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003480 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003482 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003483 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3484 }
3485
Malcolm Chend965c8b2018-02-28 15:00:40 -08003486 final long identity = Binder.clearCallingIdentity();
3487 try {
3488 final Phone phone = getPhone(subId);
3489 if (phone != null) {
3490 return phone.getServiceState().getVoiceNetworkType();
3491 } else {
3492 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3493 }
3494 } finally {
3495 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003497 }
3498
3499 /**
3500 * @return true if a ICC card is present
3501 */
3502 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003503 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003504 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3505 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003506 }
3507
3508 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003509 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003510 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003511 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003512 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003513 final long identity = Binder.clearCallingIdentity();
3514 try {
3515 final Phone phone = PhoneFactory.getPhone(slotIndex);
3516 if (phone != null) {
3517 return phone.getIccCard().hasIccCard();
3518 } else {
3519 return false;
3520 }
3521 } finally {
3522 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003524 }
3525
3526 /**
3527 * Return if the current radio is LTE on CDMA. This
3528 * is a tri-state return value as for a period of time
3529 * the mode may be unknown.
3530 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003531 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003532 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003533 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003534 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003535 @Override
3536 public int getLteOnCdmaMode(String callingPackage) {
3537 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003538 }
3539
Sanket Padawe356d7632015-06-22 14:03:32 -07003540 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003541 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003543 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003544 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3545 }
3546
Malcolm Chend965c8b2018-02-28 15:00:40 -08003547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 final Phone phone = getPhone(subId);
3550 if (phone == null) {
3551 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3552 } else {
3553 return phone.getLteOnCdmaMode();
3554 }
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 }
Wink Saville36469e72014-06-11 15:17:00 -07003558 }
3559
Wink Saville36469e72014-06-11 15:17:00 -07003560 /**
3561 * {@hide}
3562 * Returns Default subId, 0 in the case of single standby.
3563 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003564 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003565 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003566 }
3567
Shishir Agrawala9f32182016-04-12 12:00:16 -07003568 private int getSlotForDefaultSubscription() {
3569 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3570 }
3571
Wink Savilleb564aae2014-10-23 10:18:09 -07003572 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003573 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003574 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003575
Pengquan Meng466e2482018-09-21 15:54:48 -07003576 private boolean isActiveSubscription(int subId) {
3577 return mSubscriptionController.isActiveSubId(subId);
3578 }
3579
Ihab Awadf2177b72013-11-25 13:33:23 -08003580 /**
3581 * @see android.telephony.TelephonyManager.WifiCallingChoices
3582 */
3583 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003584 final long identity = Binder.clearCallingIdentity();
3585 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003586 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003587 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3588 getWhenToMakeWifiCallsDefaultPreference());
3589 } finally {
3590 Binder.restoreCallingIdentity(identity);
3591 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003592 }
3593
3594 /**
3595 * @see android.telephony.TelephonyManager.WifiCallingChoices
3596 */
3597 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003601 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003602 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3603 } finally {
3604 Binder.restoreCallingIdentity(identity);
3605 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003606 }
3607
Sailesh Nepald1e68152013-12-12 19:08:02 -08003608 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003609 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003610 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003611 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003612
Shishir Agrawal566b7612013-10-28 14:41:00 -07003613 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003614 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3615 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3617 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003618 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003619
Malcolm Chend965c8b2018-02-28 15:00:40 -08003620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 if (TextUtils.equals(ISDR_AID, aid)) {
3623 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003624 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3625 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003626 if (bestComponent == null
3627 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3628 loge("The calling package is not allowed to access ISD-R.");
3629 throw new SecurityException(
3630 "The calling package is not allowed to access ISD-R.");
3631 }
Derek Tan740e1672017-06-27 14:56:27 -07003632 }
Derek Tan740e1672017-06-27 14:56:27 -07003633
Malcolm Chend965c8b2018-02-28 15:00:40 -08003634 if (DBG) {
3635 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3636 }
3637 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3638 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3639 if (DBG) log("iccOpenLogicalChannel: " + response);
3640 return response;
3641 } finally {
3642 Binder.restoreCallingIdentity(identity);
3643 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003644 }
3645
3646 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003647 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3649 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003650
Malcolm Chend965c8b2018-02-28 15:00:40 -08003651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3654 if (channel < 0) {
3655 return false;
3656 }
3657 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3658 if (DBG) log("iccCloseLogicalChannel: " + success);
3659 return success;
3660 } finally {
3661 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003662 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003663 }
3664
3665 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003666 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003667 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3669 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003670
Malcolm Chend965c8b2018-02-28 15:00:40 -08003671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 if (DBG) {
3674 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3675 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3676 + p3 + " data=" + data);
3677 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003678
Malcolm Chend965c8b2018-02-28 15:00:40 -08003679 if (channel < 0) {
3680 return "";
3681 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003682
Malcolm Chend965c8b2018-02-28 15:00:40 -08003683 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3684 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3685 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003686
Malcolm Chend965c8b2018-02-28 15:00:40 -08003687 // Append the returned status code to the end of the response payload.
3688 String s = Integer.toHexString(
3689 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3690 if (response.payload != null) {
3691 s = IccUtils.bytesToHexString(response.payload) + s;
3692 }
3693 return s;
3694 } finally {
3695 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003696 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003697 }
Jake Hambye994d462014-02-03 13:10:13 -08003698
Evan Charltonc66da362014-05-16 14:06:40 -07003699 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003700 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3701 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3703 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003704 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003705
Malcolm Chend965c8b2018-02-28 15:00:40 -08003706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3709 && TextUtils.equals(ISDR_AID, data)) {
3710 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003711 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3712 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003713 if (bestComponent == null
3714 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3715 loge("The calling package is not allowed to select ISD-R.");
3716 throw new SecurityException(
3717 "The calling package is not allowed to select ISD-R.");
3718 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003719 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003720
Malcolm Chend965c8b2018-02-28 15:00:40 -08003721 if (DBG) {
3722 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3723 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3724 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003725
Malcolm Chend965c8b2018-02-28 15:00:40 -08003726 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3727 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3728 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003729
Malcolm Chend965c8b2018-02-28 15:00:40 -08003730 // Append the returned status code to the end of the response payload.
3731 String s = Integer.toHexString(
3732 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3733 if (response.payload != null) {
3734 s = IccUtils.bytesToHexString(response.payload) + s;
3735 }
3736 return s;
3737 } finally {
3738 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003739 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003740 }
3741
3742 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003743 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003744 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3746 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003747
Malcolm Chend965c8b2018-02-28 15:00:40 -08003748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 if (DBG) {
3751 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3752 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3753 }
3754
3755 IccIoResult response =
3756 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3757 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3758 subId);
3759
3760 if (DBG) {
3761 log("Exchange SIM_IO [R]" + response);
3762 }
3763
3764 byte[] result = null;
3765 int length = 2;
3766 if (response.payload != null) {
3767 length = 2 + response.payload.length;
3768 result = new byte[length];
3769 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3770 } else {
3771 result = new byte[length];
3772 }
3773
3774 result[length - 1] = (byte) response.sw2;
3775 result[length - 2] = (byte) response.sw1;
3776 return result;
3777 } finally {
3778 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003779 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003780 }
3781
Nathan Haroldb3014052017-01-25 15:57:32 -08003782 /**
3783 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3784 * on a particular subscription
3785 */
sqianb6e41952018-03-12 14:54:01 -07003786 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3787 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3788 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3789 return null;
3790 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003791
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 if (appType != TelephonyManager.APPTYPE_USIM
3795 && appType != TelephonyManager.APPTYPE_SIM) {
3796 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3797 return null;
3798 }
3799 Object response = sendRequest(
3800 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3801 if (response instanceof String[]) {
3802 return (String[]) response;
3803 }
3804 // Response is an Exception of some kind,
3805 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003806 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003807 } finally {
3808 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003809 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003810 }
3811
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003812 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003813 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3815 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003816
Malcolm Chend965c8b2018-02-28 15:00:40 -08003817 final long identity = Binder.clearCallingIdentity();
3818 try {
3819 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3820 if (response.payload == null) {
3821 return "";
3822 }
Evan Charltonc66da362014-05-16 14:06:40 -07003823
Malcolm Chend965c8b2018-02-28 15:00:40 -08003824 // Append the returned status code to the end of the response payload.
3825 String s = Integer.toHexString(
3826 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3827 s = IccUtils.bytesToHexString(response.payload) + s;
3828 return s;
3829 } finally {
3830 Binder.restoreCallingIdentity(identity);
3831 }
Evan Charltonc66da362014-05-16 14:06:40 -07003832 }
3833
Jake Hambye994d462014-02-03 13:10:13 -08003834 /**
3835 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3836 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3837 *
3838 * @param itemID the ID of the item to read
3839 * @return the NV item as a String, or null on error.
3840 */
3841 @Override
3842 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003843 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3845 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003846
3847 final long identity = Binder.clearCallingIdentity();
3848 try {
3849 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003850 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003851 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3852 return value;
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
3855 }
Jake Hambye994d462014-02-03 13:10:13 -08003856 }
3857
3858 /**
3859 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3860 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3861 *
3862 * @param itemID the ID of the item to read
3863 * @param itemValue the value to write, as a String
3864 * @return true on success; false on any failure
3865 */
3866 @Override
3867 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003868 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3870 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003871
3872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3875 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003876 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003877 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3878 return success;
3879 } finally {
3880 Binder.restoreCallingIdentity(identity);
3881 }
Jake Hambye994d462014-02-03 13:10:13 -08003882 }
3883
3884 /**
3885 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3886 * Used for device configuration by some CDMA operators.
3887 *
3888 * @param preferredRoamingList byte array containing the new PRL
3889 * @return true on success; false on any failure
3890 */
3891 @Override
3892 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3894 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003895
3896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3899 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3900 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3901 return success;
3902 } finally {
3903 Binder.restoreCallingIdentity(identity);
3904 }
Jake Hambye994d462014-02-03 13:10:13 -08003905 }
3906
3907 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003908 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003909 * Used for device configuration by some CDMA operators.
3910 *
chen xu1cc0abe2018-10-26 17:39:23 -07003911 * @param slotIndex - device slot.
3912 *
Jake Hambye994d462014-02-03 13:10:13 -08003913 * @return true on success; false on any failure
3914 */
3915 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003916 public boolean resetModemConfig(int slotIndex) {
3917 Phone phone = PhoneFactory.getPhone(slotIndex);
3918 if (phone != null) {
3919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3920 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003921
chen xu1cc0abe2018-10-26 17:39:23 -07003922 final long identity = Binder.clearCallingIdentity();
3923 try {
3924 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3925 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3926 return success;
3927 } finally {
3928 Binder.restoreCallingIdentity(identity);
3929 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003930 }
chen xu1cc0abe2018-10-26 17:39:23 -07003931 return false;
3932 }
3933
3934 /**
3935 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3936 *
3937 * @param slotIndex - device slot.
3938 *
3939 * @return true on success; false on any failure
3940 */
3941 @Override
3942 public boolean rebootModem(int slotIndex) {
3943 Phone phone = PhoneFactory.getPhone(slotIndex);
3944 if (phone != null) {
3945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3946 mApp, phone.getSubId(), "rebootModem");
3947
3948 final long identity = Binder.clearCallingIdentity();
3949 try {
3950 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3951 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3952 return success;
3953 } finally {
3954 Binder.restoreCallingIdentity(identity);
3955 }
3956 }
3957 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003958 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003959
Svet Ganovb320e182015-04-16 12:30:10 -07003960 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003961 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003963 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003964 return new String[0];
3965 }
3966
Malcolm Chend965c8b2018-02-28 15:00:40 -08003967 final long identity = Binder.clearCallingIdentity();
3968 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003969 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003970 } finally {
3971 Binder.restoreCallingIdentity(identity);
3972 }
Wink Saville36469e72014-06-11 15:17:00 -07003973 }
3974
Brad Ebinger51f743a2017-01-23 13:50:20 -08003975 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003976 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3977 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003978 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003979 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003980 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003981
3982 final long identity = Binder.clearCallingIdentity();
3983 try {
3984 PhoneFactory.getImsResolver().enableIms(slotId);
3985 } finally {
3986 Binder.restoreCallingIdentity(identity);
3987 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003988 }
3989
3990 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003991 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3992 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003993 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003994 public void disableIms(int slotId) {
3995 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003996
3997 final long identity = Binder.clearCallingIdentity();
3998 try {
3999 PhoneFactory.getImsResolver().disableIms(slotId);
4000 } finally {
4001 Binder.restoreCallingIdentity(identity);
4002 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004003 }
4004
4005 /**
4006 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4007 * feature or {@link null} if the service is not available. If the feature is available, the
4008 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4009 */
4010 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004011 IImsServiceFeatureCallback callback) {
4012 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004013
4014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004020 }
4021
4022 /**
4023 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4024 * feature during emergency calling or {@link null} if the service is not available. If the
4025 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4026 * listener for feature updates.
4027 */
4028 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4029 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004030
4031 final long identity = Binder.clearCallingIdentity();
4032 try {
4033 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
4034 } finally {
4035 Binder.restoreCallingIdentity(identity);
4036 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004037 }
4038
Brad Ebinger5f64b052017-12-14 14:26:15 -08004039 /**
4040 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
4041 * specified.
4042 */
4043 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4044 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004045
4046 final long identity = Binder.clearCallingIdentity();
4047 try {
4048 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
4049 } finally {
4050 Binder.restoreCallingIdentity(identity);
4051 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004052 }
4053
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004054 /**
4055 * Returns the {@link IImsConfig} structure associated with the slotId and feature
4056 * specified.
4057 */
4058 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4059 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004060
4061 final long identity = Binder.clearCallingIdentity();
4062 try {
4063 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
4064 } finally {
4065 Binder.restoreCallingIdentity(identity);
4066 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004067 }
4068
Brad Ebinger884c07b2018-02-15 16:17:40 -08004069 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004070 * Sets the ImsService Package Name that Telephony will bind to.
4071 *
4072 * @param slotId the slot ID that the ImsService should bind for.
4073 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4074 * ImsService is the device default ImsService.
4075 * @param packageName The package name of the application that contains the ImsService to bind
4076 * to.
4077 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4078 * @hide
4079 */
4080 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004081 int[] subIds = SubscriptionManager.getSubId(slotId);
4082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4083 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4084 "setImsService");
4085
Malcolm Chend965c8b2018-02-28 15:00:40 -08004086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
4089 isCarrierImsService, packageName);
4090 } finally {
4091 Binder.restoreCallingIdentity(identity);
4092 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004093 }
4094
4095 /**
4096 * Return the ImsService configuration.
4097 *
4098 * @param slotId The slot that the ImsService is associated with.
4099 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4100 * the device default.
4101 * @return the package name of the ImsService configuration.
4102 */
4103 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004104 int[] subIds = SubscriptionManager.getSubId(slotId);
4105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4106 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4107 "getImsService");
4108
Malcolm Chend965c8b2018-02-28 15:00:40 -08004109 final long identity = Binder.clearCallingIdentity();
4110 try {
4111 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
4112 isCarrierImsService);
4113 } finally {
4114 Binder.restoreCallingIdentity(identity);
4115 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004116 }
4117
Wink Saville36469e72014-06-11 15:17:00 -07004118 public void setImsRegistrationState(boolean registered) {
4119 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004120
4121 final long identity = Binder.clearCallingIdentity();
4122 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004123 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004124 } finally {
4125 Binder.restoreCallingIdentity(identity);
4126 }
Wink Saville36469e72014-06-11 15:17:00 -07004127 }
4128
4129 /**
Stuart Scott54788802015-03-30 13:18:01 -07004130 * Set the network selection mode to automatic.
4131 *
4132 */
4133 @Override
4134 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4136 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004137
Pengquan Meng466e2482018-09-21 15:54:48 -07004138 if (!isActiveSubscription(subId)) {
4139 return;
4140 }
4141
Malcolm Chend965c8b2018-02-28 15:00:40 -08004142 final long identity = Binder.clearCallingIdentity();
4143 try {
4144 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4145 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4146 } finally {
4147 Binder.restoreCallingIdentity(identity);
4148 }
Stuart Scott54788802015-03-30 13:18:01 -07004149 }
4150
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004151 /**
4152 * Ask the radio to connect to the input network and change selection mode to manual.
4153 *
4154 * @param subId the id of the subscription.
4155 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4156 * the operator to attach to.
4157 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4158 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4159 * normal network selection next time.
4160 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004161 */
4162 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004163 public boolean setNetworkSelectionModeManual(
4164 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4166 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004167
4168 if (!isActiveSubscription(subId)) {
4169 return false;
4170 }
4171
Malcolm Chend965c8b2018-02-28 15:00:40 -08004172 final long identity = Binder.clearCallingIdentity();
4173 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004174 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004175 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004176 if (DBG) {
4177 log("setNetworkSelectionModeManual: subId: " + subId
4178 + " operator: " + operatorInfo);
4179 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004180 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4181 } finally {
4182 Binder.restoreCallingIdentity(identity);
4183 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004184 }
4185
4186 /**
4187 * Scans for available networks.
4188 */
4189 @Override
4190 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4192 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004193
Pengquan Meng0c05b502018-09-06 09:59:22 -07004194 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004195 try {
4196 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004197 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004198 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004199 } finally {
4200 Binder.restoreCallingIdentity(identity);
4201 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004202 }
4203
4204 /**
yinxub1bed742017-04-17 11:45:04 -07004205 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004206 *
yinxub1bed742017-04-17 11:45:04 -07004207 * @param subId id of the subscription
4208 * @param request contains the radio access networks with bands/channels to scan
4209 * @param messenger callback messenger for scan results or errors
4210 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004211 * @return the id of the requested scan which can be used to stop the scan.
4212 */
4213 @Override
4214 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
4215 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4217 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004218
4219 final long identity = Binder.clearCallingIdentity();
4220 try {
4221 return mNetworkScanRequestTracker.startNetworkScan(
4222 request, messenger, binder, getPhone(subId));
4223 } finally {
4224 Binder.restoreCallingIdentity(identity);
4225 }
yinxu504e1392017-04-12 16:03:22 -07004226 }
4227
4228 /**
4229 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004230 *
4231 * @param subId id of the subscription
4232 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004233 */
4234 @Override
4235 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4237 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004238
4239 final long identity = Binder.clearCallingIdentity();
4240 try {
4241 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4242 } finally {
4243 Binder.restoreCallingIdentity(identity);
4244 }
yinxu504e1392017-04-12 16:03:22 -07004245 }
4246
4247 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004248 * Get the calculated preferred network type.
4249 * Used for debugging incorrect network type.
4250 *
4251 * @return the preferred network type, defined in RILConstants.java.
4252 */
4253 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004254 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004255 final Phone defaultPhone = getDefaultPhone();
4256 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4257 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004258 return RILConstants.PREFERRED_NETWORK_MODE;
4259 }
4260
Malcolm Chend965c8b2018-02-28 15:00:40 -08004261 final long identity = Binder.clearCallingIdentity();
4262 try {
4263 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004264 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004265 } finally {
4266 Binder.restoreCallingIdentity(identity);
4267 }
Junda Liu84d15a22014-07-02 11:21:04 -07004268 }
4269
4270 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004271 * Get the preferred network type.
4272 * Used for device configuration by some CDMA operators.
4273 *
4274 * @return the preferred network type, defined in RILConstants.java.
4275 */
4276 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004277 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004278 TelephonyPermissions
4279 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4280 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004281
4282 final long identity = Binder.clearCallingIdentity();
4283 try {
4284 if (DBG) log("getPreferredNetworkType");
4285 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4286 int networkType = (result != null ? result[0] : -1);
4287 if (DBG) log("getPreferredNetworkType: " + networkType);
4288 return networkType;
4289 } finally {
4290 Binder.restoreCallingIdentity(identity);
4291 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004292 }
4293
4294 /**
4295 * Set the preferred network type.
4296 * Used for device configuration by some CDMA operators.
4297 *
4298 * @param networkType the preferred network type, defined in RILConstants.java.
4299 * @return true on success; false on any failure.
4300 */
4301 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004302 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4304 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004305
4306 final long identity = Binder.clearCallingIdentity();
4307 try {
4308 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4309 Boolean success = (Boolean) sendRequest(
4310 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4311 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4312 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004313 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004314 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4315 }
4316 return success;
4317 } finally {
4318 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004319 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004320 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004321
4322 /**
Junda Liu475951f2014-11-07 16:45:03 -08004323 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07004324 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004325 * tethering.
4326 *
4327 * @return 0: Not required. 1: required. 2: Not set.
4328 * @hide
4329 */
4330 @Override
4331 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004332 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004333
4334 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004335 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004336 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004337 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004338 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004339 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004340 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004341 dunRequired = 1;
4342 }
4343 return dunRequired;
4344 } finally {
4345 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004346 }
Junda Liu475951f2014-11-07 16:45:03 -08004347 }
4348
4349 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004350 * Set mobile data enabled
4351 * Used by the user through settings etc to turn on/off mobile data
4352 *
4353 * @param enable {@code true} turn turn data on, else {@code false}
4354 */
4355 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004356 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4358 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004359
4360 final long identity = Binder.clearCallingIdentity();
4361 try {
4362 int phoneId = mSubscriptionController.getPhoneId(subId);
4363 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4364 Phone phone = PhoneFactory.getPhone(phoneId);
4365 if (phone != null) {
4366 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004367 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004368 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004369 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004370 }
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004373 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004374 }
4375
4376 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004377 * Get the user enabled state of Mobile Data.
4378 *
4379 * TODO: remove and use isUserDataEnabled.
4380 * This can't be removed now because some vendor codes
4381 * calls through ITelephony directly while they should
4382 * use TelephonyManager.
4383 *
4384 * @return true on enabled
4385 */
4386 @Override
4387 public boolean getDataEnabled(int subId) {
4388 return isUserDataEnabled(subId);
4389 }
4390
4391 /**
4392 * Get whether mobile data is enabled per user setting.
4393 *
4394 * There are other factors deciding whether mobile data is actually enabled, but they are
4395 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004396 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004397 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004398 *
4399 * @return {@code true} if data is enabled else {@code false}
4400 */
4401 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004402 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004403 try {
4404 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4405 null);
4406 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4408 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004409 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004410
4411 final long identity = Binder.clearCallingIdentity();
4412 try {
4413 int phoneId = mSubscriptionController.getPhoneId(subId);
4414 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4415 Phone phone = PhoneFactory.getPhone(phoneId);
4416 if (phone != null) {
4417 boolean retVal = phone.isUserDataEnabled();
4418 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4419 return retVal;
4420 } else {
4421 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4422 return false;
4423 }
4424 } finally {
4425 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004426 }
4427 }
4428
4429 /**
4430 * Get whether mobile data is enabled.
4431 *
4432 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4433 * whether mobile data is actually enabled.
4434 *
4435 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4436 *
4437 * @return {@code true} if data is enabled else {@code false}
4438 */
4439 @Override
4440 public boolean isDataEnabled(int subId) {
4441 try {
4442 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4443 null);
4444 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4446 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004447 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004448
4449 final long identity = Binder.clearCallingIdentity();
4450 try {
4451 int phoneId = mSubscriptionController.getPhoneId(subId);
4452 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4453 Phone phone = PhoneFactory.getPhone(phoneId);
4454 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004455 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004456 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4457 return retVal;
4458 } else {
4459 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4460 return false;
4461 }
4462 } finally {
4463 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004464 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004465 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004466
4467 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004468 public int getCarrierPrivilegeStatus(int subId) {
4469 final Phone phone = getPhone(subId);
4470 if (phone == null) {
4471 loge("getCarrierPrivilegeStatus: Invalid subId");
4472 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4473 }
4474 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004475 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004476 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004477 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4478 }
4479 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004480 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004481 }
Junda Liu29340342014-07-10 15:23:27 -07004482
4483 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004484 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4485 final Phone phone = getPhone(subId);
4486 if (phone == null) {
4487 loge("getCarrierPrivilegeStatus: Invalid subId");
4488 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4489 }
4490 UiccProfile profile =
4491 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4492 if (profile == null) {
4493 loge("getCarrierPrivilegeStatus: No UICC");
4494 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4495 }
4496 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4497 }
4498
4499 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004500 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004501 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004502 if (TextUtils.isEmpty(pkgName))
4503 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004504 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004505 if (card == null) {
4506 loge("checkCarrierPrivilegesForPackage: No UICC");
4507 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4508 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004509 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4510 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004511 }
4512
4513 @Override
4514 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004515 if (TextUtils.isEmpty(pkgName))
4516 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004517 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4518 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4519 UiccCard card = UiccController.getInstance().getUiccCard(i);
4520 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004521 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004522 continue;
4523 }
4524
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004525 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004526 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4527 break;
4528 }
4529 }
4530
4531 return result;
Junda Liu29340342014-07-10 15:23:27 -07004532 }
Derek Tan89e89d42014-07-08 17:00:10 -07004533
4534 @Override
Junda Liue64de782015-04-16 17:19:16 -07004535 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4536 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4537 loge("phoneId " + phoneId + " is not valid.");
4538 return null;
4539 }
4540 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004541 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004542 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004543 return null ;
4544 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004545 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004546 }
4547
Amith Yamasani6e118872016-02-19 12:53:51 -08004548 @Override
4549 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004550 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004551 List<String> privilegedPackages = new ArrayList<>();
4552 List<PackageInfo> packages = null;
4553 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4554 UiccCard card = UiccController.getInstance().getUiccCard(i);
4555 if (card == null) {
4556 // No UICC in that slot.
4557 continue;
4558 }
4559 if (card.hasCarrierPrivilegeRules()) {
4560 if (packages == null) {
4561 // Only check packages in user 0 for now
4562 packages = pm.getInstalledPackagesAsUser(
4563 PackageManager.MATCH_DISABLED_COMPONENTS
4564 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4565 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4566 }
4567 for (int p = packages.size() - 1; p >= 0; p--) {
4568 PackageInfo pkgInfo = packages.get(p);
4569 if (pkgInfo != null && pkgInfo.packageName != null
4570 && card.getCarrierPrivilegeStatus(pkgInfo)
4571 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4572 privilegedPackages.add(pkgInfo.packageName);
4573 }
4574 }
4575 }
4576 }
4577 return privilegedPackages;
4578 }
4579
Wink Savilleb564aae2014-10-23 10:18:09 -07004580 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004581 final Phone phone = getPhone(subId);
4582 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004583 if (card == null) {
4584 loge("getIccId: No UICC");
4585 return null;
4586 }
4587 String iccId = card.getIccId();
4588 if (TextUtils.isEmpty(iccId)) {
4589 loge("getIccId: ICC ID is null or empty.");
4590 return null;
4591 }
4592 return iccId;
4593 }
4594
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004595 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004596 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4597 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004598 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4599 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004600
Malcolm Chend965c8b2018-02-28 15:00:40 -08004601 final long identity = Binder.clearCallingIdentity();
4602 try {
4603 final String iccId = getIccId(subId);
4604 final Phone phone = getPhone(subId);
4605 if (phone == null) {
4606 return false;
4607 }
4608 final String subscriberId = phone.getSubscriberId();
4609
4610 if (DBG_MERGE) {
4611 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4612 + subscriberId + " to " + number);
4613 }
4614
4615 if (TextUtils.isEmpty(iccId)) {
4616 return false;
4617 }
4618
4619 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4620
4621 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4622 if (alphaTag == null) {
4623 editor.remove(alphaTagPrefKey);
4624 } else {
4625 editor.putString(alphaTagPrefKey, alphaTag);
4626 }
4627
4628 // Record both the line number and IMSI for this ICCID, since we need to
4629 // track all merged IMSIs based on line number
4630 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4631 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4632 if (number == null) {
4633 editor.remove(numberPrefKey);
4634 editor.remove(subscriberPrefKey);
4635 } else {
4636 editor.putString(numberPrefKey, number);
4637 editor.putString(subscriberPrefKey, subscriberId);
4638 }
4639
4640 editor.commit();
4641 return true;
4642 } finally {
4643 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004644 }
Derek Tan7226c842014-07-02 17:42:23 -07004645 }
4646
4647 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004648 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004649 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004650 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004651 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004652 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004653 return null;
4654 }
Derek Tan97ebb422014-09-05 16:55:38 -07004655
Malcolm Chend965c8b2018-02-28 15:00:40 -08004656 final long identity = Binder.clearCallingIdentity();
4657 try {
4658 String iccId = getIccId(subId);
4659 if (iccId != null) {
4660 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4661 if (DBG_MERGE) {
4662 log("getLine1NumberForDisplay returning "
4663 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4664 }
4665 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004666 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004667 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4668 return null;
4669 } finally {
4670 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004671 }
Derek Tan7226c842014-07-02 17:42:23 -07004672 }
4673
4674 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004675 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004676 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004677 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004678 return null;
4679 }
Derek Tan97ebb422014-09-05 16:55:38 -07004680
Malcolm Chend965c8b2018-02-28 15:00:40 -08004681 final long identity = Binder.clearCallingIdentity();
4682 try {
4683 String iccId = getIccId(subId);
4684 if (iccId != null) {
4685 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4686 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4687 }
4688 return null;
4689 } finally {
4690 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004691 }
Derek Tan7226c842014-07-02 17:42:23 -07004692 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004693
4694 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004695 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004696 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4697 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004698 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004699 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4700 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004701 return null;
4702 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004703
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004704 final long identity = Binder.clearCallingIdentity();
4705 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004706 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004707 final TelephonyManager tele = TelephonyManager.from(context);
4708 final SubscriptionManager sub = SubscriptionManager.from(context);
4709
4710 // Figure out what subscribers are currently active
4711 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4712 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4713 // the process, where TelephonyManager was instantiated.
4714 // Otherwise AppOps check will fail.
4715
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004716 final int[] subIds = sub.getActiveSubscriptionIdList();
4717 for (int subId : subIds) {
4718 activeSubscriberIds.add(tele.getSubscriberId(subId));
4719 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004720
4721 // First pass, find a number override for an active subscriber
4722 String mergeNumber = null;
4723 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4724 for (String key : prefs.keySet()) {
4725 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4726 final String subscriberId = (String) prefs.get(key);
4727 if (activeSubscriberIds.contains(subscriberId)) {
4728 final String iccId = key.substring(
4729 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4730 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4731 mergeNumber = (String) prefs.get(numberKey);
4732 if (DBG_MERGE) {
4733 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4734 + " for active subscriber " + subscriberId);
4735 }
4736 if (!TextUtils.isEmpty(mergeNumber)) {
4737 break;
4738 }
4739 }
4740 }
4741 }
4742
4743 // Shortcut when no active merged subscribers
4744 if (TextUtils.isEmpty(mergeNumber)) {
4745 return null;
4746 }
4747
4748 // Second pass, find all subscribers under that line override
4749 final ArraySet<String> result = new ArraySet<>();
4750 for (String key : prefs.keySet()) {
4751 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4752 final String number = (String) prefs.get(key);
4753 if (mergeNumber.equals(number)) {
4754 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4755 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4756 final String subscriberId = (String) prefs.get(subscriberKey);
4757 if (!TextUtils.isEmpty(subscriberId)) {
4758 result.add(subscriberId);
4759 }
4760 }
4761 }
4762 }
4763
4764 final String[] resultArray = result.toArray(new String[result.size()]);
4765 Arrays.sort(resultArray);
4766 if (DBG_MERGE) {
4767 Slog.d(LOG_TAG,
4768 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4769 }
4770 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004771 } finally {
4772 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004773 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004774 }
4775
4776 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004777 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004778 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4779 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004780
4781 final long identity = Binder.clearCallingIdentity();
4782 try {
4783 final Phone phone = getPhone(subId);
4784 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4785 } finally {
4786 Binder.restoreCallingIdentity(identity);
4787 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004788 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004789
4790 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004791 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004792 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4793 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004794 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004795
4796 final long identity = Binder.clearCallingIdentity();
4797 try {
4798 final Phone phone = getPhone(subId);
4799 if (phone == null) {
4800 return false;
4801 }
4802 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4803 cdmaNonRoamingList);
4804 } finally {
4805 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004806 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004807 }
4808
4809 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004810 @Deprecated
4811 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4812 enforceModifyPermission();
4813
4814 int returnValue = 0;
4815 try {
vagdevie435a3e2018-08-15 16:01:53 -07004816 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004817 if(result.exception == null) {
4818 if (result.result != null) {
4819 byte[] responseData = (byte[])(result.result);
4820 if(responseData.length > oemResp.length) {
4821 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4822 responseData.length + "bytes. Buffer Size is " +
4823 oemResp.length + "bytes.");
4824 }
4825 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4826 returnValue = responseData.length;
4827 }
4828 } else {
4829 CommandException ex = (CommandException) result.exception;
4830 returnValue = ex.getCommandError().ordinal();
4831 if(returnValue > 0) returnValue *= -1;
4832 }
4833 } catch (RuntimeException e) {
4834 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4835 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4836 if(returnValue > 0) returnValue *= -1;
4837 }
4838
4839 return returnValue;
4840 }
4841
4842 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004843 public void setRadioCapability(RadioAccessFamily[] rafs) {
4844 try {
4845 ProxyController.getInstance().setRadioCapability(rafs);
4846 } catch (RuntimeException e) {
4847 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4848 }
4849 }
4850
4851 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004852 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004853 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004854 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004855 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004856 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004857 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004858 final long identity = Binder.clearCallingIdentity();
4859 try {
chen xufeeed752018-10-26 14:17:57 -07004860 TelephonyPermissions
4861 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4862 mApp, phone.getSubId(), "getRadioAccessFamily");
4863 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004864 } finally {
4865 Binder.restoreCallingIdentity(identity);
4866 }
chen xufeeed752018-10-26 14:17:57 -07004867 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004868 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004869
4870 @Override
4871 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004872 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004873 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004874
4875 final long identity = Binder.clearCallingIdentity();
4876 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004877 ImsManager.getInstance(defaultPhone.getContext(),
4878 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004879 } finally {
4880 Binder.restoreCallingIdentity(identity);
4881 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004882 }
4883
4884 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004885 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004886 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004887 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004888 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004889 return false;
4890 }
Svet Ganovb320e182015-04-16 12:30:10 -07004891
Malcolm Chend965c8b2018-02-28 15:00:40 -08004892 final long identity = Binder.clearCallingIdentity();
4893 try {
4894 // Check the user preference and the system-level IMS setting. Even if the user has
4895 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4896 // In the long run, we may instead need to check if there exists a connection service
4897 // which can support video calling.
4898 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004899 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004900 return imsManager.isVtEnabledByPlatform()
4901 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4902 && imsManager.isVtEnabledByUser();
4903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004906 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004907
Andrew Leea1239f22015-03-02 17:44:07 -08004908 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004909 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4910 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4911 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4912 return false;
4913 }
4914
4915 final long identity = Binder.clearCallingIdentity();
4916 try {
4917 CarrierConfigManager configManager =
4918 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004919 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004920 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4921 } finally {
4922 Binder.restoreCallingIdentity(identity);
4923 }
Andrew Leea1239f22015-03-02 17:44:07 -08004924 }
4925
4926 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004927 public boolean isWorldPhone(int subId, String callingPackage) {
4928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4929 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4930 return false;
4931 }
4932
4933 final long identity = Binder.clearCallingIdentity();
4934 try {
4935 CarrierConfigManager configManager =
4936 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004937 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004938 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4939 } finally {
4940 Binder.restoreCallingIdentity(identity);
4941 }
Andrew Leea1239f22015-03-02 17:44:07 -08004942 }
4943
Andrew Lee9431b832015-03-09 18:46:45 -07004944 @Override
4945 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004946 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004947 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004948 }
4949
4950 @Override
4951 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004952 final long identity = Binder.clearCallingIdentity();
4953 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004954 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004955 } finally {
4956 Binder.restoreCallingIdentity(identity);
4957 }
Andrew Lee9431b832015-03-09 18:46:45 -07004958 }
4959
Hall Liuf6668912018-10-31 17:05:23 -07004960 /**
4961 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4962 * support for the feature and device firmware support.
4963 *
4964 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4965 */
4966 @Override
4967 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004968 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004969 final Phone phone = getPhone(subscriptionId);
4970 if (phone == null) {
4971 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4972 return false;
4973 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004974 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004975 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004976 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4977 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004978 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004979 return isCarrierSupported && isDeviceSupported;
4980 } finally {
4981 Binder.restoreCallingIdentity(identity);
4982 }
Hall Liu98187582018-01-22 19:15:32 -08004983 }
4984
Hall Liuf6668912018-10-31 17:05:23 -07004985 /**
4986 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4987 * both also support RTT.
4988 */
4989 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004990 final long identity = Binder.clearCallingIdentity();
4991 try {
Hall Liuf6668912018-10-31 17:05:23 -07004992 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004993 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004994 } finally {
4995 Binder.restoreCallingIdentity(identity);
4996 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004997 }
4998
Sanket Padawe7310cc72015-01-14 09:53:20 -08004999 /**
5000 * Returns the unique device ID of phone, for example, the IMEI for
5001 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5002 *
5003 * <p>Requires Permission:
5004 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5005 */
5006 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005007 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005008 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005009 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005010 return null;
5011 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005012 int subId = phone.getSubId();
5013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5014 mApp, subId, callingPackage, "getDeviceId")) {
5015 return null;
5016 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005017
5018 final long identity = Binder.clearCallingIdentity();
5019 try {
5020 return phone.getDeviceId();
5021 } finally {
5022 Binder.restoreCallingIdentity(identity);
5023 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005024 }
5025
Ping Sunc67b7c22016-03-02 19:16:45 +08005026 /**
5027 * {@hide}
5028 * Returns the IMS Registration Status on a particular subid
5029 *
5030 * @param subId
5031 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005032 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005033 Phone phone = getPhone(subId);
5034 if (phone != null) {
5035 return phone.isImsRegistered();
5036 } else {
5037 return false;
5038 }
5039 }
5040
Santos Cordon7a1885b2015-02-03 11:15:19 -08005041 @Override
5042 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005043 final long identity = Binder.clearCallingIdentity();
5044 try {
5045 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5046 } finally {
5047 Binder.restoreCallingIdentity(identity);
5048 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005049 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005050
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005051 /**
5052 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005053 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005054 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005055 final long identity = Binder.clearCallingIdentity();
5056 try {
5057 Phone phone = getPhone(subId);
5058 if (phone != null) {
5059 return phone.isWifiCallingEnabled();
5060 } else {
5061 return false;
5062 }
5063 } finally {
5064 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005065 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005066 }
5067
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005068 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005069 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005070 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005071 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005072 final long identity = Binder.clearCallingIdentity();
5073 try {
5074 Phone phone = getPhone(subId);
5075 if (phone != null) {
5076 return phone.isVideoEnabled();
5077 } else {
5078 return false;
5079 }
5080 } finally {
5081 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005082 }
5083 }
5084
5085 /**
5086 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5087 * defined in {@link ImsRegistrationImplBase}.
5088 */
5089 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005090 final long identity = Binder.clearCallingIdentity();
5091 try {
5092 Phone phone = getPhone(subId);
5093 if (phone != null) {
5094 return phone.getImsRegistrationTech();
5095 } else {
5096 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5097 }
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005100 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005101 }
5102
Stuart Scott8eef64f2015-04-08 15:13:54 -07005103 @Override
5104 public void factoryReset(int subId) {
5105 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005106 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5107 return;
5108 }
5109
Svet Ganovcc087f82015-05-12 20:35:54 -07005110 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005111
Svet Ganovcc087f82015-05-12 20:35:54 -07005112 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005113 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5114 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005115 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005116 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005117 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005118 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5119 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005120 }
5121 } finally {
5122 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005123 }
5124 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005125
5126 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005127 public String getSimLocaleForSubscriber(int subId) {
5128 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5129 final Phone phone = getPhone(subId);
5130 if (phone == null) {
5131 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005132 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005133 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005134 final long identity = Binder.clearCallingIdentity();
5135 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005136 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5137 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005138 // Try and fetch the locale from the carrier properties or from the SIM language
5139 // preferences (EF-PL and EF-LI)...
5140 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005141 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005142 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5143 if (localeFromDefaultSim != null) {
5144 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5145 if (DBG) log("Using locale from subId: " + subId + " locale: "
5146 + localeFromDefaultSim);
5147 return localeFromDefaultSim.toLanguageTag();
5148 } else {
5149 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005150 }
5151 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005152
Malcolm Chend965c8b2018-02-28 15:00:40 -08005153 // The SIM language preferences only store a language (e.g. fr = French), not an
5154 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5155 // the SIM and carrier preferences does not include a country we add the country
5156 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005157 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005158 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005159 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005160 return mccLocale.toLanguageTag();
5161 }
5162
5163 if (DBG) log("No locale found - returning null");
5164 return null;
5165 } finally {
5166 Binder.restoreCallingIdentity(identity);
5167 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005168 }
5169
5170 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005171 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005172 }
5173
Malcolm Chend965c8b2018-02-28 15:00:40 -08005174 /**
5175 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5176 */
5177 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005178 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005179 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005180
Chenjie Yu1ba97252018-01-11 18:16:20 -08005181 private final ModemActivityInfo mLastModemActivityInfo =
5182 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5183
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005184 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005185 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5186 * representing the state of the modem.
5187 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005188 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5189 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005190 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005191 */
5192 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005193 public void requestModemActivityInfo(ResultReceiver result) {
5194 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005195 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005196
5197 final long identity = Binder.clearCallingIdentity();
5198 try {
5199 ModemActivityInfo ret = null;
5200 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005201 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5202 CMD_GET_MODEM_ACTIVITY_INFO,
5203 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005204 if (isModemActivityInfoValid(info)) {
5205 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5206 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5207 mergedTxTimeMs[i] =
5208 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5209 }
5210 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5211 mLastModemActivityInfo.setSleepTimeMillis(
5212 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5213 mLastModemActivityInfo.setIdleTimeMillis(
5214 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5215 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5216 mLastModemActivityInfo.setRxTimeMillis(
5217 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5218 mLastModemActivityInfo.setEnergyUsed(
5219 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005220 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005221 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5222 mLastModemActivityInfo.getSleepTimeMillis(),
5223 mLastModemActivityInfo.getIdleTimeMillis(),
5224 mLastModemActivityInfo.getTxTimeMillis(),
5225 mLastModemActivityInfo.getRxTimeMillis(),
5226 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005227 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005228 Bundle bundle = new Bundle();
5229 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5230 result.send(0, bundle);
5231 } finally {
5232 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005233 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005234 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005235
Siddharth Rayf5d29552018-06-17 15:02:38 -07005236 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5237 // less than total activity duration.
5238 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5239 if (info == null) {
5240 return false;
5241 }
5242 int activityDurationMs =
5243 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5244 int totalTxTimeMs = 0;
5245 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5246 totalTxTimeMs += info.getTxTimeMillis()[i];
5247 }
5248 return (info.isValid()
5249 && (info.getSleepTimeMillis() <= activityDurationMs)
5250 && (info.getIdleTimeMillis() <= activityDurationMs)
5251 && (info.getRxTimeMillis() <= activityDurationMs)
5252 && (totalTxTimeMs <= activityDurationMs));
5253 }
5254
Jack Yu85bd38a2015-11-09 11:34:32 -08005255 /**
5256 * {@hide}
5257 * Returns the service state information on specified subscription.
5258 */
5259 @Override
5260 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005261 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005262 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005263 return null;
5264 }
5265
Malcolm Chend965c8b2018-02-28 15:00:40 -08005266 final long identity = Binder.clearCallingIdentity();
5267 try {
5268 final Phone phone = getPhone(subId);
5269 if (phone == null) {
5270 return null;
5271 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005272
Malcolm Chend965c8b2018-02-28 15:00:40 -08005273 return phone.getServiceState();
5274 } finally {
5275 Binder.restoreCallingIdentity(identity);
5276 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005277 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005278
5279 /**
5280 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5281 *
5282 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5283 * voicemail ringtone.
5284 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5285 * PhoneAccount.
5286 */
5287 @Override
5288 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005289 final long identity = Binder.clearCallingIdentity();
5290 try {
5291 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5292 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005293 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005294 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005295
Malcolm Chend965c8b2018-02-28 15:00:40 -08005296 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5297 } finally {
5298 Binder.restoreCallingIdentity(identity);
5299 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005300 }
5301
5302 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005303 * Sets the per-account voicemail ringtone.
5304 *
5305 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5306 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5307 *
5308 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5309 * voicemail ringtone.
5310 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5311 * PhoneAccount.
5312 */
5313 @Override
5314 public void setVoicemailRingtoneUri(String callingPackage,
5315 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005316 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005317 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5318 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005319 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5321 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5322 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005323 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005324
5325 final long identity = Binder.clearCallingIdentity();
5326 try {
5327 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5328 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005329 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005330 }
5331 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5332 } finally {
5333 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005334 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005335 }
5336
5337 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005338 * Returns whether vibration is set for voicemail notification in Phone settings.
5339 *
5340 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5341 * voicemail vibration setting.
5342 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5343 */
5344 @Override
5345 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005346 final long identity = Binder.clearCallingIdentity();
5347 try {
5348 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5349 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005350 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005351 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005352
Malcolm Chend965c8b2018-02-28 15:00:40 -08005353 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5354 } finally {
5355 Binder.restoreCallingIdentity(identity);
5356 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005357 }
5358
Youhan Wange64578a2016-05-02 15:32:42 -07005359 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005360 * Sets the per-account voicemail vibration.
5361 *
5362 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5363 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5364 *
5365 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5366 * voicemail vibration setting.
5367 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5368 * specific PhoneAccount.
5369 */
5370 @Override
5371 public void setVoicemailVibrationEnabled(String callingPackage,
5372 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005373 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005374 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5375 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005376 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5378 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5379 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005380 }
5381
Malcolm Chend965c8b2018-02-28 15:00:40 -08005382 final long identity = Binder.clearCallingIdentity();
5383 try {
5384 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5385 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005386 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005387 }
5388 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5389 } finally {
5390 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005391 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005392 }
5393
5394 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005395 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5396 *
5397 * @throws SecurityException if the caller does not have the required permission
5398 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005399 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005400 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005401 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005402 }
5403
5404 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005405 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5406 * permission.
5407 *
5408 * @throws SecurityException if the caller does not have the required permission
5409 */
5410 private void enforceSendSmsPermission() {
5411 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5412 }
5413
5414 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005415 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005416 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005417 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005418 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005419 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005420 final long identity = Binder.clearCallingIdentity();
5421 try {
5422 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005423 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005424 if (componentName == null) {
5425 throw new SecurityException(
5426 "Caller not current active visual voicemail package[null]");
5427 }
5428 String vvmPackage = componentName.getPackageName();
5429 if (!callingPackage.equals(vvmPackage)) {
5430 throw new SecurityException("Caller not current active visual voicemail package["
5431 + vvmPackage + "]");
5432 }
5433 } finally {
5434 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005435 }
5436 }
5437
5438 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005439 * Return the application ID for the app type.
5440 *
5441 * @param subId the subscription ID that this request applies to.
5442 * @param appType the uicc app type.
5443 * @return Application ID for specificied app type, or null if no uicc.
5444 */
5445 @Override
5446 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005447 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005448 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005449
5450 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005451 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005452 if (phone == null) {
5453 return null;
5454 }
5455 String aid = null;
5456 try {
5457 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5458 .getApplicationByType(appType).getAid();
5459 } catch (Exception e) {
5460 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5461 }
5462 return aid;
5463 } finally {
5464 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005465 }
Youhan Wange64578a2016-05-02 15:32:42 -07005466 }
5467
Youhan Wang4001d252016-05-11 10:29:41 -07005468 /**
5469 * Return the Electronic Serial Number.
5470 *
5471 * @param subId the subscription ID that this request applies to.
5472 * @return ESN or null if error.
5473 */
5474 @Override
5475 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005476 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005477 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005478
5479 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005480 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005481 if (phone == null) {
5482 return null;
5483 }
5484 String esn = null;
5485 try {
5486 esn = phone.getEsn();
5487 } catch (Exception e) {
5488 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5489 }
5490 return esn;
5491 } finally {
5492 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005493 }
Youhan Wang4001d252016-05-11 10:29:41 -07005494 }
5495
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005496 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005497 * Return the Preferred Roaming List Version.
5498 *
5499 * @param subId the subscription ID that this request applies to.
5500 * @return PRLVersion or null if error.
5501 */
5502 @Override
5503 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005504 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005505 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005506
5507 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005508 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005509 if (phone == null) {
5510 return null;
5511 }
5512 String cdmaPrlVersion = null;
5513 try {
5514 cdmaPrlVersion = phone.getCdmaPrlVersion();
5515 } catch (Exception e) {
5516 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5517 }
5518 return cdmaPrlVersion;
5519 } finally {
5520 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005521 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005522 }
5523
5524 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005525 * Get snapshot of Telephony histograms
5526 * @return List of Telephony histograms
5527 * @hide
5528 */
5529 @Override
5530 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5532 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005533
5534 final long identity = Binder.clearCallingIdentity();
5535 try {
5536 return RIL.getTelephonyRILTimingHistograms();
5537 } finally {
5538 Binder.restoreCallingIdentity(identity);
5539 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005540 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005541
5542 /**
5543 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005544 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5545 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005546 * Require system privileges. In the future we may add this to carrier APIs.
5547 *
Michele Berionne0963c862018-11-27 18:57:59 -08005548 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005549 */
5550 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005551 @TelephonyManager.SetCarrierRestrictionResult
5552 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005553 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005554 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005555
Michele Berionne0963c862018-11-27 18:57:59 -08005556 if (carrierRestrictionRules == null) {
5557 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005558 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005559
Malcolm Chend965c8b2018-02-28 15:00:40 -08005560 final long identity = Binder.clearCallingIdentity();
5561 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005562 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005563 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005564 } finally {
5565 Binder.restoreCallingIdentity(identity);
5566 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005567 }
5568
5569 /**
5570 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005571 * Get the allowed carrier list and the excluded carrier list, including the priority between
5572 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005573 * Require system privileges. In the future we may add this to carrier APIs.
5574 *
Michele Berionne0963c862018-11-27 18:57:59 -08005575 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005576 */
5577 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005578 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005579 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005580 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005581
5582 final long identity = Binder.clearCallingIdentity();
5583 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005584 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5585 if (response instanceof CarrierRestrictionRules) {
5586 return (CarrierRestrictionRules) response;
5587 }
5588 // Response is an Exception of some kind,
5589 // which is signalled to the user as a NULL retval
5590 return null;
5591 } catch (Exception e) {
5592 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5593 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005594 } finally {
5595 Binder.restoreCallingIdentity(identity);
5596 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005597 }
5598
fionaxu59545b42016-05-25 15:53:37 -07005599 /**
5600 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5601 * @param subId the subscription ID that this action applies to.
5602 * @param enabled control enable or disable metered apns.
5603 * {@hide}
5604 */
5605 @Override
5606 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5607 enforceModifyPermission();
5608 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005609
5610 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005611 if (phone == null) {
5612 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5613 return;
5614 }
5615 try {
5616 phone.carrierActionSetMeteredApnsEnabled(enabled);
5617 } catch (Exception e) {
5618 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005619 } finally {
5620 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005621 }
5622 }
5623
5624 /**
5625 * Action set from carrier signalling broadcast receivers to enable/disable radio
5626 * @param subId the subscription ID that this action applies to.
5627 * @param enabled control enable or disable radio.
5628 * {@hide}
5629 */
5630 @Override
5631 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5632 enforceModifyPermission();
5633 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005634
5635 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005636 if (phone == null) {
5637 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5638 return;
5639 }
5640 try {
5641 phone.carrierActionSetRadioEnabled(enabled);
5642 } catch (Exception e) {
5643 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005644 } finally {
5645 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005646 }
5647 }
5648
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005649 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005650 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5651 * network status based on which carrier apps could apply actions accordingly,
5652 * enable/disable default url handler for example.
5653 *
5654 * @param subId the subscription ID that this action applies to.
5655 * @param report control start/stop reporting the default network status.
5656 * {@hide}
5657 */
5658 @Override
5659 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5660 enforceModifyPermission();
5661 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005662
5663 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005664 if (phone == null) {
5665 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5666 return;
5667 }
5668 try {
5669 phone.carrierActionReportDefaultNetworkStatus(report);
5670 } catch (Exception e) {
5671 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005672 } finally {
5673 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005674 }
5675 }
5676
5677 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005678 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5679 * bug report is being generated.
5680 */
5681 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005682 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005683 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5684 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005685 writer.println("Permission Denial: can't dump Phone from pid="
5686 + Binder.getCallingPid()
5687 + ", uid=" + Binder.getCallingUid()
5688 + "without permission "
5689 + android.Manifest.permission.DUMP);
5690 return;
5691 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005692 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005693 }
Jack Yueb89b242016-06-22 13:27:47 -07005694
Brad Ebingerdac2f002018-04-03 15:17:52 -07005695 @Override
5696 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5697 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5698 throws RemoteException {
5699 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5700 }
5701
Jack Yueb89b242016-06-22 13:27:47 -07005702 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005703 * Get aggregated video call data usage since boot.
5704 *
5705 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5706 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005707 * {@hide}
5708 */
5709 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005710 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005711 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5712 null);
5713
Malcolm Chend965c8b2018-02-28 15:00:40 -08005714 final long identity = Binder.clearCallingIdentity();
5715 try {
5716 // NetworkStatsService keeps tracking the active network interface and identity. It
5717 // records the delta with the corresponding network identity.
5718 // We just return the total video call data usage snapshot since boot.
5719 Phone phone = getPhone(subId);
5720 if (phone != null) {
5721 return phone.getVtDataUsage(perUidStats);
5722 }
5723 return null;
5724 } finally {
5725 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005726 }
Jack Yueb89b242016-06-22 13:27:47 -07005727 }
Jack Yu75ab2952016-07-08 14:29:33 -07005728
5729 /**
5730 * Policy control of data connection. Usually used when data limit is passed.
5731 * @param enabled True if enabling the data, otherwise disabling.
5732 * @param subId Subscription index
5733 * {@hide}
5734 */
5735 @Override
5736 public void setPolicyDataEnabled(boolean enabled, int subId) {
5737 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005738
5739 final long identity = Binder.clearCallingIdentity();
5740 try {
5741 Phone phone = getPhone(subId);
5742 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005743 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005744 }
5745 } finally {
5746 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005747 }
5748 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005749
5750 /**
5751 * Get Client request stats
5752 * @return List of Client Request Stats
5753 * @hide
5754 */
5755 @Override
5756 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005758 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005759 return null;
5760 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005761 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005762
Malcolm Chend965c8b2018-02-28 15:00:40 -08005763 final long identity = Binder.clearCallingIdentity();
5764 try {
5765 if (phone != null) {
5766 return phone.getClientRequestStats();
5767 }
5768
5769 return null;
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005773 }
5774
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005775 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005776 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005777 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005778 }
Jack Yueb4124c2017-02-16 15:32:43 -08005779
5780 /**
Grace Chen70990072017-03-24 17:21:30 -07005781 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005782 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005783 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005784 * @param state State of SIM (power down, power up, pass through)
5785 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5786 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5787 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005788 *
5789 **/
5790 @Override
Grace Chen70990072017-03-24 17:21:30 -07005791 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005792 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005793 Phone phone = PhoneFactory.getPhone(slotIndex);
5794
vagdevie435a3e2018-08-15 16:01:53 -07005795 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5796
Malcolm Chend965c8b2018-02-28 15:00:40 -08005797 final long identity = Binder.clearCallingIdentity();
5798 try {
5799 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005800 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005801 }
5802 } finally {
5803 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005804 }
5805 }
Shuo Qiandd210312017-04-12 22:11:33 +00005806
Tyler Gunn65d45c22017-06-05 11:22:26 -07005807 private boolean isUssdApiAllowed(int subId) {
5808 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005809 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005810 if (configManager == null) {
5811 return false;
5812 }
5813 PersistableBundle pb = configManager.getConfigForSubId(subId);
5814 if (pb == null) {
5815 return false;
5816 }
5817 return pb.getBoolean(
5818 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5819 }
5820
Shuo Qiandd210312017-04-12 22:11:33 +00005821 /**
5822 * Check if phone is in emergency callback mode
5823 * @return true if phone is in emergency callback mode
5824 * @param subId sub id
5825 */
goneil9c5f4872017-12-05 14:07:56 -08005826 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005827 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005828 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005829 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005830
5831 final long identity = Binder.clearCallingIdentity();
5832 try {
5833 if (phone != null) {
5834 return phone.isInEcm();
5835 } else {
5836 return false;
5837 }
5838 } finally {
5839 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005840 }
5841 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005842
5843 /**
5844 * Get the current signal strength information for the given subscription.
5845 * Because this information is not updated when the device is in a low power state
5846 * it should not be relied-upon to be current.
5847 * @param subId Subscription index
5848 * @return the most recent cached signal strength info from the modem
5849 */
5850 @Override
5851 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005852 final long identity = Binder.clearCallingIdentity();
5853 try {
5854 Phone p = getPhone(subId);
5855 if (p == null) {
5856 return null;
5857 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005858
Malcolm Chend965c8b2018-02-28 15:00:40 -08005859 return p.getSignalStrength();
5860 } finally {
5861 Binder.restoreCallingIdentity(identity);
5862 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005863 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005864
Pengquan Meng9140aec2018-08-22 14:49:57 -07005865 /**
chen xu907e5a22018-10-11 13:21:04 -07005866 * Get the current modem radio state for the given slot.
5867 * @param slotIndex slot index.
5868 * @param callingPackage the name of the package making the call.
5869 * @return the current radio power state from the modem
5870 */
5871 @Override
5872 public int getRadioPowerState(int slotIndex, String callingPackage) {
5873 Phone phone = PhoneFactory.getPhone(slotIndex);
5874 if (phone != null) {
5875 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5876 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5877 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5878 }
5879
5880 final long identity = Binder.clearCallingIdentity();
5881 try {
5882 return phone.getRadioPowerState();
5883 } finally {
5884 Binder.restoreCallingIdentity(identity);
5885 }
5886 }
5887 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5888 }
5889
5890 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005891 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5892 *
5893 * <p>Requires one of the following permissions:
5894 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5895 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5896 * privileges.
5897 *
5898 * @param subId subscription id
5899 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5900 * {@code false}.
5901 */
5902 @Override
5903 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005904 boolean isEnabled = false;
5905 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005906 try {
5907 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005908 null /* message */);
5909 Phone phone = getPhone(subId);
5910 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005911 } catch (Exception e) {
5912 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5913 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005914 } finally {
5915 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005916 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005917 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005918 }
5919
5920
5921 /**
5922 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5923 *
5924 * <p> Requires permission:
5925 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5926 * privileges.
5927 *
5928 * @param subId subscription id
5929 * @param isEnabled {@code true} means enable, {@code false} means disable.
5930 */
5931 @Override
5932 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005933 final long identity = Binder.clearCallingIdentity();
5934 try {
5935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5936 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005937
Pengquan Meng0c05b502018-09-06 09:59:22 -07005938 Phone phone = getPhone(subId);
5939 if (phone != null) {
5940 phone.setDataRoamingEnabled(isEnabled);
5941 }
5942 } finally {
5943 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005944 }
5945 }
5946
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005947 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005948 public boolean isManualNetworkSelectionAllowed(int subId) {
5949 boolean isAllowed = true;
5950 final long identity = Binder.clearCallingIdentity();
5951 try {
5952 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5953 mApp, subId, "isManualNetworkSelectionAllowed");
5954 Phone phone = getPhone(subId);
5955 if (phone != null) {
5956 isAllowed = phone.isCspPlmnEnabled();
5957 }
5958 } finally {
5959 Binder.restoreCallingIdentity(identity);
5960 }
5961 return isAllowed;
5962 }
5963
5964 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08005965 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
5966 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
5967 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5968 throw new SecurityException("Caller does not have carrier privileges on any UICC.");
5969 }
Jordan Liu5aa07002018-12-18 15:44:48 -08005970
5971 final long identity = Binder.clearCallingIdentity();
5972 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08005973 UiccController uiccController = UiccController.getInstance();
5974 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
5975
5976 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
5977 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
5978 // Remove private info if the caller doesn't have access
5979 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
5980 for (UiccCardInfo cardInfo : cardInfos) {
5981 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
5982 UiccProfile profile = card.getUiccProfile();
5983 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
5984 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5985 filteredInfos.add(cardInfo.getUnprivileged());
5986 } else {
5987 filteredInfos.add(cardInfo);
5988 }
5989 }
5990 return filteredInfos;
5991 }
5992 return cardInfos;
5993 } catch (PackageManager.NameNotFoundException e) {
5994 // This should not happen since we pass the package info in from TelephonyManager
5995 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08005996 } finally {
5997 Binder.restoreCallingIdentity(identity);
5998 }
5999 }
6000
6001 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006002 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006003 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006004
Malcolm Chend965c8b2018-02-28 15:00:40 -08006005 final long identity = Binder.clearCallingIdentity();
6006 try {
6007 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6008 if (slots == null) {
6009 Rlog.i(LOG_TAG, "slots is null.");
6010 return null;
6011 }
6012
6013 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6014 for (int i = 0; i < slots.length; i++) {
6015 UiccSlot slot = slots[i];
6016 if (slot == null) {
6017 continue;
6018 }
6019
6020 String cardId;
6021 UiccCard card = slot.getUiccCard();
6022 if (card != null) {
6023 cardId = card.getCardId();
6024 } else {
6025 cardId = slot.getIccId();
6026 }
6027
6028 int cardState = 0;
6029 switch (slot.getCardState()) {
6030 case CARDSTATE_ABSENT:
6031 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6032 break;
6033 case CARDSTATE_PRESENT:
6034 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6035 break;
6036 case CARDSTATE_ERROR:
6037 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6038 break;
6039 case CARDSTATE_RESTRICTED:
6040 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6041 break;
6042 default:
6043 break;
6044
6045 }
6046
6047 infos[i] = new UiccSlotInfo(
6048 slot.isActive(),
6049 slot.isEuicc(),
6050 cardId,
6051 cardState,
6052 slot.getPhoneId(),
6053 slot.isExtendedApduSupported());
6054 }
6055 return infos;
6056 } finally {
6057 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006058 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006059 }
6060
6061 @Override
6062 public boolean switchSlots(int[] physicalSlots) {
6063 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006064
6065 final long identity = Binder.clearCallingIdentity();
6066 try {
6067 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6068 } finally {
6069 Binder.restoreCallingIdentity(identity);
6070 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006071 }
Jack Yu4c988042018-02-27 15:30:01 -08006072
6073 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006074 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006075 final long identity = Binder.clearCallingIdentity();
6076 try {
6077 return UiccController.getInstance().getCardIdForDefaultEuicc();
6078 } finally {
6079 Binder.restoreCallingIdentity(identity);
6080 }
6081 }
6082
6083 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006084 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6085 enforceModifyPermission();
6086 final Phone phone = getPhone(subId);
6087 if (phone == null) {
6088 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6089 return;
6090 }
6091
Malcolm Chend965c8b2018-02-28 15:00:40 -08006092 final long identity = Binder.clearCallingIdentity();
6093 try {
6094 phone.setRadioIndicationUpdateMode(filters, mode);
6095 } finally {
6096 Binder.restoreCallingIdentity(identity);
6097 }
Jack Yu4c988042018-02-27 15:30:01 -08006098 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006099
6100 /**
goneil47ffb6e2018-04-06 15:40:58 -07006101 * A test API to reload the UICC profile.
6102 *
6103 * <p>Requires that the calling app has permission
6104 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6105 * @hide
6106 */
6107 @Override
6108 public void refreshUiccProfile(int subId) {
6109 enforceModifyPermission();
6110
6111 final long identity = Binder.clearCallingIdentity();
6112 try {
6113 Phone phone = getPhone(subId);
6114 if (phone == null) {
6115 return;
6116 }
6117 UiccCard uiccCard = phone.getUiccCard();
6118 if (uiccCard == null) {
6119 return;
6120 }
6121 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6122 if (uiccProfile == null) {
6123 return;
6124 }
6125 uiccProfile.refresh();
6126 } finally {
6127 Binder.restoreCallingIdentity(identity);
6128 }
6129 }
6130
6131 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006132 * Returns false if the mobile data is disabled by default, otherwise return true.
6133 */
6134 private boolean getDefaultDataEnabled() {
6135 return "true".equalsIgnoreCase(
6136 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6137 }
6138
6139 /**
6140 * Returns true if the data roaming is enabled by default, i.e the system property
6141 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6142 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6143 */
6144 private boolean getDefaultDataRoamingEnabled(int subId) {
6145 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006146 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006147 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6148 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6149 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6150 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6151 return isDataRoamingEnabled;
6152 }
6153
6154 /**
6155 * Returns the default network type for the given {@code subId}, if the default network type is
6156 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6157 */
6158 private int getDefaultNetworkType(int subId) {
6159 return Integer.parseInt(
6160 TelephonyManager.getTelephonyProperty(
6161 mSubscriptionController.getPhoneId(subId),
6162 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6163 String.valueOf(Phone.PREFERRED_NT_MODE)));
6164 }
fionaxua13278b2018-03-21 00:08:13 -07006165
6166 @Override
6167 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6168 gid1, String gid2, String plmn, String spn) {
6169 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006170
6171 final long identity = Binder.clearCallingIdentity();
6172 try {
6173 final Phone phone = getPhone(subId);
6174 if (phone == null) {
6175 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6176 return;
6177 }
6178 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6179 } finally {
6180 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006181 }
fionaxua13278b2018-03-21 00:08:13 -07006182 }
6183
6184 @Override
6185 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006186 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006187
6188 final long identity = Binder.clearCallingIdentity();
6189 try {
6190 final Phone phone = getPhone(subId);
6191 if (phone == null) {
6192 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6193 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6194 }
6195 return phone.getCarrierIdListVersion();
6196 } finally {
6197 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006198 }
fionaxua13278b2018-03-21 00:08:13 -07006199 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006200
6201 @Override
6202 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6203 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6204 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6205 return -1;
6206 }
6207
6208 final long identity = Binder.clearCallingIdentity();
6209 try {
6210 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6211 } finally {
6212 Binder.restoreCallingIdentity(identity);
6213 }
6214 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006215
6216 @Override
6217 public int getCdmaRoamingMode(int subId) {
6218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6219 mApp, subId, "getCdmaRoamingMode");
6220
6221 final long identity = Binder.clearCallingIdentity();
6222 try {
6223 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6224 } finally {
6225 Binder.restoreCallingIdentity(identity);
6226 }
6227 }
6228
6229 @Override
6230 public boolean setCdmaRoamingMode(int subId, int mode) {
6231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6232 mApp, subId, "setCdmaRoamingMode");
6233
6234 final long identity = Binder.clearCallingIdentity();
6235 try {
6236 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
6240 }
6241
6242 @Override
6243 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6245 mApp, subId, "setCdmaSubscriptionMode");
6246
6247 final long identity = Binder.clearCallingIdentity();
6248 try {
6249 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6250 } finally {
6251 Binder.restoreCallingIdentity(identity);
6252 }
6253 }
chen xu7ee67862018-10-30 22:27:10 -07006254
sqian2fff4a32018-11-05 14:18:37 -08006255 private void ensureUserRunning(int userId) {
6256 if (!mUserManager.isUserRunning(userId)) {
6257 throw new IllegalStateException("User " + userId + " does not exist or not running");
6258 }
6259 }
6260
6261 /**
6262 * Returns a list of SMS apps on a given user.
6263 *
6264 * Only the shell user (UID 2000 or 0) can call it.
6265 * Target user must be running.
6266 */
6267 @Override
6268 public String[] getSmsApps(int userId) {
6269 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6270 ensureUserRunning(userId);
6271
6272 final Collection<SmsApplicationData> apps =
6273 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6274
6275 String[] ret = new String[apps.size()];
6276 int i = 0;
6277 for (SmsApplicationData app : apps) {
6278 ret[i++] = app.mPackageName;
6279 }
6280 return ret;
6281 }
6282
6283 /**
6284 * Returns the default SMS app package name on a given user.
6285 *
6286 * Only the shell user (UID 2000 or 0) can call it.
6287 * Target user must be running.
6288 */
6289 @Override
6290 public String getDefaultSmsApp(int userId) {
6291 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6292 ensureUserRunning(userId);
6293
6294 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6295 /* updateIfNeeded= */ true, userId);
6296 return cn == null ? null : cn.getPackageName();
6297 }
6298
6299 /**
6300 * Set a package as the default SMS app on a given user.
6301 *
6302 * Only the shell user (UID 2000 or 0) can call it.
6303 * Target user must be running.
6304 */
6305 @Override
6306 public void setDefaultSmsApp(int userId, String packageName) {
6307 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6308 ensureUserRunning(userId);
6309
6310 boolean found = false;
6311 for (String pkg : getSmsApps(userId)) {
6312 if (TextUtils.equals(packageName, pkg)) {
6313 found = true;
6314 break;
6315 }
6316 }
6317 if (!found) {
6318 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6319 }
6320
6321 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6322 }
6323
chen xu7ee67862018-10-30 22:27:10 -07006324 @Override
sqian04b86072018-11-07 14:02:21 -08006325 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6326 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006327 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6328 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6329 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6330 }
6331 final long identity = Binder.clearCallingIdentity();
6332 try {
sqian991b35e2018-12-12 16:48:18 -08006333 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6334 for (Phone phone: PhoneFactory.getPhones()) {
6335 if (phone.getEmergencyNumberTracker() != null
6336 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6337 emergencyNumberListInternal.put(
6338 phone.getSubId(),
6339 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6340 }
sqian03bca152018-12-05 18:48:28 -08006341 }
sqian991b35e2018-12-12 16:48:18 -08006342 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006343 } finally {
6344 Binder.restoreCallingIdentity(identity);
6345 }
sqian04b86072018-11-07 14:02:21 -08006346 }
6347
6348 @Override
sqian03bca152018-12-05 18:48:28 -08006349 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6350 final Phone defaultPhone = getDefaultPhone();
6351 if (!exactMatch) {
6352 TelephonyPermissions
6353 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6354 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6355 }
6356 final long identity = Binder.clearCallingIdentity();
6357 try {
sqian991b35e2018-12-12 16:48:18 -08006358 for (Phone phone: PhoneFactory.getPhones()) {
6359 if (phone.getEmergencyNumberTracker() != null
6360 && phone.getEmergencyNumberTracker() != null) {
6361 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6362 number, exactMatch)) {
6363 return true;
sqian03bca152018-12-05 18:48:28 -08006364 }
6365 }
sqian03bca152018-12-05 18:48:28 -08006366 }
6367 return false;
6368 } finally {
6369 Binder.restoreCallingIdentity(identity);
6370 }
6371 }
6372
sqian9d4df8b2019-01-15 18:32:07 -08006373 /**
6374 * Update emergency number list for test mode.
6375 */
6376 @Override
6377 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6378 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6379 "updateEmergencyNumberListTestMode");
6380
6381 final long identity = Binder.clearCallingIdentity();
6382 try {
6383 for (Phone phone: PhoneFactory.getPhones()) {
6384 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6385 if (tracker != null) {
6386 tracker.executeEmergencyNumberTestModeCommand(action, num);
6387 }
6388 }
6389 } finally {
6390 Binder.restoreCallingIdentity(identity);
6391 }
6392 }
6393
6394 /**
6395 * Get the full emergency number list for test mode.
6396 */
6397 @Override
6398 public List<String> getEmergencyNumberListTestMode() {
6399 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6400 "getEmergencyNumberListTestMode");
6401
6402 final long identity = Binder.clearCallingIdentity();
6403 try {
6404 Set<String> emergencyNumbers = new HashSet<>();
6405 for (Phone phone: PhoneFactory.getPhones()) {
6406 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6407 if (tracker != null) {
6408 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6409 emergencyNumbers.add(num.getNumber());
6410 }
6411 }
6412 }
6413 return new ArrayList<>(emergencyNumbers);
6414 } finally {
6415 Binder.restoreCallingIdentity(identity);
6416 }
6417 }
6418
sqian04b86072018-11-07 14:02:21 -08006419 @Override
chen xu7ee67862018-10-30 22:27:10 -07006420 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6421 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6422 Phone phone = getPhone(subId);
6423 if (phone == null) {
6424 return null;
6425 }
6426 final long identity = Binder.clearCallingIdentity();
6427 try {
6428 UiccProfile profile = UiccController.getInstance()
6429 .getUiccProfileForPhone(phone.getPhoneId());
6430 if (profile != null) {
6431 return profile.getCertsFromCarrierPrivilegeAccessRules();
6432 }
6433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435 }
6436 return null;
6437 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006438
6439 /**
6440 * Enable or disable a modem stack.
6441 */
6442 @Override
6443 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6444 enforceModifyPermission();
6445
6446 final long identity = Binder.clearCallingIdentity();
6447 try {
6448 Phone phone = PhoneFactory.getPhone(slotIndex);
6449 if (phone == null) {
6450 return false;
6451 } else {
6452 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6453 }
6454 } finally {
6455 Binder.restoreCallingIdentity(identity);
6456 }
6457 }
Micheled3107c52018-12-21 15:00:11 -08006458
6459 @Override
6460 public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) {
6461 enforceModifyPermission();
6462
6463 final long identity = Binder.clearCallingIdentity();
6464 try {
6465 mTelephonySharedPreferences.edit()
6466 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted)
6467 .commit();
6468 } finally {
6469 Binder.restoreCallingIdentity(identity);
6470 }
6471 }
6472
6473 @Override
6474 public boolean isMultisimCarrierRestricted() {
6475 enforceReadPrivilegedPermission("isMultisimCarrierRestricted");
6476
6477 final long identity = Binder.clearCallingIdentity();
6478 try {
6479 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6480 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6481 if (numPhysicalSlots < 2) {
6482 loge("isMultisimCarrierRestricted: requires at least 2 cards");
6483 return true;
6484 }
6485
6486 // Default value is false. Multi SIM is allowed unless explicitly restricted.
6487 return mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false);
6488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
6491 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006492
6493 /**
6494 * Switch configs to enable multi-sim or switch back to single-sim
6495 * @param numOfSims number of active sims we want to switch to
6496 */
6497 @Override
6498 public void switchMultiSimConfig(int numOfSims) {
6499 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6500 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6501 final long identity = Binder.clearCallingIdentity();
6502 try {
6503 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6504 } finally {
6505 Binder.restoreCallingIdentity(identity);
6506 }
6507 }
6508
6509 /**
6510 * Get how many sims have been activated on the phone
6511 */
6512 @Override
6513 public int getNumOfActiveSims() {
6514 final long identity = Binder.clearCallingIdentity();
6515 try {
6516 return mPhoneConfigurationManager.getNumOfActiveSims();
6517 } finally {
6518 Binder.restoreCallingIdentity(identity);
6519 }
6520 }
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006521
6522 /**
6523 * Get whether reboot is required or not after making changes to modem configurations.
6524 * Return value defaults to false
6525 */
6526 @Override
6527 public boolean isRebootRequiredForModemConfigChange() {
6528 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6529 final long identity = Binder.clearCallingIdentity();
6530 try {
6531 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6532 } finally {
6533 Binder.restoreCallingIdentity(identity);
6534 }
6535 }
6536
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006537}