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