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