blob: fbfb00b570a861833b99ef3e5c308e48bdc8c9c1 [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;
Meng Wang1a7c35a2016-05-05 20:56:15 -070055import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080056import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080057import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070058import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070059import android.telephony.CarrierConfigManager;
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;
sqian03bca152018-12-05 18:48:28 -080072import android.telephony.PhoneNumberUtils;
Wink Saville5d475dd2014-10-17 15:00:58 -070073import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070074import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080076import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070077import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080078import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080079import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070080import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070081import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080082import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000083import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070084import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070085import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070086import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080087import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080088import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070089import android.telephony.gsm.GsmCellLocation;
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 Ebinger1f2b5082018-02-08 16:11:32 -080097import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080099import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800101import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800102import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800103
Brad Ebinger4c460712018-10-01 10:40:55 -0700104import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700105import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800106import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700107import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700108import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700109import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800110import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700111import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700112import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113import com.android.internal.telephony.DefaultPhoneNotifier;
Hall Liud892bec2018-11-30 14:51:45 -0800114import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800116import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700117import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100118import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700119import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700120import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700122import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800123import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700124import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700125import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700126import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700127import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700128import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700129import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800130import com.android.internal.telephony.SmsApplication;
131import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800132import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800133import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700134import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700135import com.android.internal.telephony.uicc.IccIoResult;
136import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800137import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700138import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800139import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800141import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000142import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700143import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800144import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700145import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800146import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700147import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700148import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800149
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700150import java.io.FileDescriptor;
151import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800152import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800154import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800155import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800156import java.util.HashMap;
157import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800158import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100159import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800160import java.util.Map;
sqian03bca152018-12-05 18:48:28 -0800161import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162
163/**
164 * Implementation of the ITelephony interface.
165 */
Santos Cordon117fee72014-05-16 17:56:12 -0700166public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167 private static final String LOG_TAG = "PhoneInterfaceManager";
168 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
169 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800170 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171
172 // Message codes used with mMainThreadHandler
173 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700174 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
175 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176 private static final int CMD_OPEN_CHANNEL = 9;
177 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
178 private static final int CMD_CLOSE_CHANNEL = 11;
179 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800180 private static final int CMD_NV_READ_ITEM = 13;
181 private static final int EVENT_NV_READ_ITEM_DONE = 14;
182 private static final int CMD_NV_WRITE_ITEM = 15;
183 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
184 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
185 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700186 private static final int CMD_RESET_MODEM_CONFIG = 19;
187 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800188 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
189 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
190 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
191 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800192 private static final int CMD_SEND_ENVELOPE = 25;
193 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000194 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
195 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700196 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
197 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
198 private static final int CMD_EXCHANGE_SIM_IO = 31;
199 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800200 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
201 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700202 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
203 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700204 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
205 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700206 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
207 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
208 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
209 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700210 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
211 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
212 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
213 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700214 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800215 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
216 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000217 private static final int CMD_SWITCH_SLOTS = 50;
218 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700219 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
220 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
221 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
222 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
223 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
224 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
225 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
226 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700227 private static final int CMD_GET_ALL_CELL_INFO = 60;
228 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
229 private static final int CMD_GET_CELL_LOCATION = 62;
230 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700231 private static final int CMD_MODEM_REBOOT = 64;
232 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700233 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
234 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800236 // Parameters of select command.
237 private static final int SELECT_COMMAND = 0xA4;
238 private static final int SELECT_P1 = 0x04;
239 private static final int SELECT_P2 = 0;
240 private static final int SELECT_P3 = 0x10;
241
Pengquan Meng85728fb2018-03-12 16:31:21 -0700242 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
243 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
244 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
245
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246 /** The singleton instance. */
247 private static PhoneInterfaceManager sInstance;
248
Wink Saville3ab207e2014-11-20 13:07:20 -0800249 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800250 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700251 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800252 private AppOpsManager mAppOps;
253 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800254 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800255 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700256 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257
Derek Tan97ebb422014-09-05 16:55:38 -0700258 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
259 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800260 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700261
Derek Tan740e1672017-06-27 14:56:27 -0700262 // The AID of ISD-R.
263 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
264
yinxub1bed742017-04-17 11:45:04 -0700265 private NetworkScanRequestTracker mNetworkScanRequestTracker;
266
David Kelly5e06a7f2018-03-12 14:10:59 +0000267 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
268 private static final int MANUFACTURER_CODE_LENGTH = 8;
269
Derek Tan89e89d42014-07-08 17:00:10 -0700270 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700271 * A request object to use for transmitting data to an ICC.
272 */
273 private static final class IccAPDUArgument {
274 public int channel, cla, command, p1, p2, p3;
275 public String data;
276
277 public IccAPDUArgument(int channel, int cla, int command,
278 int p1, int p2, int p3, String data) {
279 this.channel = channel;
280 this.cla = cla;
281 this.command = command;
282 this.p1 = p1;
283 this.p2 = p2;
284 this.p3 = p3;
285 this.data = data;
286 }
287 }
288
289 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700290 * A request object to use for transmitting data to an ICC.
291 */
292 private static final class ManualNetworkSelectionArgument {
293 public OperatorInfo operatorInfo;
294 public boolean persistSelection;
295
296 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
297 this.operatorInfo = operatorInfo;
298 this.persistSelection = persistSelection;
299 }
300 }
301
302 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
304 * request after sending. The main thread will notify the request when it is complete.
305 */
306 private static final class MainThreadRequest {
307 /** The argument to use for the request */
308 public Object argument;
309 /** The result of the request that is run on the main thread */
310 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800311 // The subscriber id that this request applies to. Defaults to
312 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
313 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700314
Nathan Harold92bed182018-10-12 18:16:49 -0700315 // In cases where subId is unavailable, the caller needs to specify the phone.
316 public Phone phone;
317
vagdevie435a3e2018-08-15 16:01:53 -0700318 public WorkSource workSource;
319
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700320 public MainThreadRequest(Object argument) {
321 this.argument = argument;
322 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800323
Nathan Harold92bed182018-10-12 18:16:49 -0700324 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
325 this.argument = argument;
326 if (phone != null) {
327 this.phone = phone;
328 }
329 this.workSource = workSource;
330 }
331
vagdevie435a3e2018-08-15 16:01:53 -0700332 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800333 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800334 if (subId != null) {
335 this.subId = subId;
336 }
vagdevie435a3e2018-08-15 16:01:53 -0700337 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 }
340
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800341 private static final class IncomingThirdPartyCallArgs {
342 public final ComponentName component;
343 public final String callId;
344 public final String callerDisplayName;
345
346 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
347 String callerDisplayName) {
348 this.component = component;
349 this.callId = callId;
350 this.callerDisplayName = callerDisplayName;
351 }
352 }
353
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 /**
355 * A handler that processes messages on the main thread in the phone process. Since many
356 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
357 * inbound binder threads to the main thread in the phone process. The Binder thread
358 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
359 * on, which will be notified when the operation completes and will contain the result of the
360 * request.
361 *
362 * <p>If a MainThreadRequest object is provided in the msg.obj field,
363 * note that request.result must be set to something non-null for the calling thread to
364 * unblock.
365 */
366 private final class MainThreadHandler extends Handler {
367 @Override
368 public void handleMessage(Message msg) {
369 MainThreadRequest request;
370 Message onCompleted;
371 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800372 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700373 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800374 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375
376 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700377 case CMD_HANDLE_USSD_REQUEST: {
378 request = (MainThreadRequest) msg.obj;
379 final Phone phone = getPhoneFromRequest(request);
380 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
381 String ussdRequest = ussdObject.first;
382 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700383
Pengquan Meng0c05b502018-09-06 09:59:22 -0700384 if (!isUssdApiAllowed(request.subId)) {
385 // Carrier does not support use of this API, return failure.
386 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
387 UssdResponse response = new UssdResponse(ussdRequest, null);
388 Bundle returnData = new Bundle();
389 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
390 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700391
Pengquan Meng0c05b502018-09-06 09:59:22 -0700392 request.result = true;
393 notifyRequester(request);
394 return;
395 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700396
Pengquan Meng0c05b502018-09-06 09:59:22 -0700397 try {
398 request.result = phone != null
399 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
400 } catch (CallStateException cse) {
401 request.result = false;
402 }
403 // Wake up the requesting thread
404 notifyRequester(request);
405 break;
pkanwar32d516d2016-10-14 19:37:38 -0700406 }
407
Yorke Lee716f67e2015-06-17 15:39:16 -0700408 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700410 final Phone phone = getPhoneFromRequest(request);
411 request.result = phone != null ?
412 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
413 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700415 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700419 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700420 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700421 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800422 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700423 if (uiccCard == null) {
424 loge("iccTransmitApduLogicalChannel: No UICC");
425 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700426 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700427 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
429 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700430 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 iccArgument.channel, iccArgument.cla, iccArgument.command,
432 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700434 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 break;
436
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 ar = (AsyncResult) msg.obj;
439 request = (MainThreadRequest) ar.userObj;
440 if (ar.exception == null && ar.result != null) {
441 request.result = ar.result;
442 } else {
443 request.result = new IccIoResult(0x6F, 0, (byte[])null);
444 if (ar.result == null) {
445 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800446 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800448 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 } else {
450 loge("iccTransmitApduLogicalChannel: Unknown exception");
451 }
452 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700453 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 break;
455
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700456 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
457 request = (MainThreadRequest) msg.obj;
458 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800459 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 if (uiccCard == null) {
461 loge("iccTransmitApduBasicChannel: No UICC");
462 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700463 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 } else {
465 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
466 request);
467 uiccCard.iccTransmitApduBasicChannel(
468 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
469 iccArgument.p3, iccArgument.data, onCompleted);
470 }
471 break;
472
473 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
474 ar = (AsyncResult) msg.obj;
475 request = (MainThreadRequest) ar.userObj;
476 if (ar.exception == null && ar.result != null) {
477 request.result = ar.result;
478 } else {
479 request.result = new IccIoResult(0x6F, 0, (byte[])null);
480 if (ar.result == null) {
481 loge("iccTransmitApduBasicChannel: Empty response");
482 } else if (ar.exception instanceof CommandException) {
483 loge("iccTransmitApduBasicChannel: CommandException: " +
484 ar.exception);
485 } else {
486 loge("iccTransmitApduBasicChannel: Unknown exception");
487 }
488 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700489 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 break;
491
492 case CMD_EXCHANGE_SIM_IO:
493 request = (MainThreadRequest) msg.obj;
494 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800495 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 if (uiccCard == null) {
497 loge("iccExchangeSimIO: No UICC");
498 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700499 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 } else {
501 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
502 request);
503 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
504 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
505 iccArgument.data, onCompleted);
506 }
507 break;
508
509 case EVENT_EXCHANGE_SIM_IO_DONE:
510 ar = (AsyncResult) msg.obj;
511 request = (MainThreadRequest) ar.userObj;
512 if (ar.exception == null && ar.result != null) {
513 request.result = ar.result;
514 } else {
515 request.result = new IccIoResult(0x6f, 0, (byte[])null);
516 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700517 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700518 break;
519
Derek Tan4d5e5c12014-02-04 11:54:58 -0800520 case CMD_SEND_ENVELOPE:
521 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800522 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700523 if (uiccCard == null) {
524 loge("sendEnvelopeWithStatus: No UICC");
525 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700526 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700527 } else {
528 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
529 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
530 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800531 break;
532
533 case EVENT_SEND_ENVELOPE_DONE:
534 ar = (AsyncResult) msg.obj;
535 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700536 if (ar.exception == null && ar.result != null) {
537 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800538 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700539 request.result = new IccIoResult(0x6F, 0, (byte[])null);
540 if (ar.result == null) {
541 loge("sendEnvelopeWithStatus: Empty response");
542 } else if (ar.exception instanceof CommandException) {
543 loge("sendEnvelopeWithStatus: CommandException: " +
544 ar.exception);
545 } else {
546 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
547 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800548 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700549 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800550 break;
551
Shishir Agrawal566b7612013-10-28 14:41:00 -0700552 case CMD_OPEN_CHANNEL:
553 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800554 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800555 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 if (uiccCard == null) {
557 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800558 request.result = new IccOpenLogicalChannelResponse(-1,
559 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 } else {
562 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800563 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
564 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 break;
567
568 case EVENT_OPEN_CHANNEL_DONE:
569 ar = (AsyncResult) msg.obj;
570 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 int[] result = (int[]) ar.result;
574 int channelId = result[0];
575 byte[] selectResponse = null;
576 if (result.length > 1) {
577 selectResponse = new byte[result.length - 1];
578 for (int i = 1; i < result.length; ++i) {
579 selectResponse[i - 1] = (byte) result[i];
580 }
581 }
582 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700583 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 if (ar.result == null) {
586 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 if (ar.exception != null) {
589 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
590 }
591
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700592 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700593 if (ar.exception instanceof CommandException) {
594 CommandException.Error error =
595 ((CommandException) (ar.exception)).getCommandError();
596 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700597 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700598 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700599 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 }
601 }
602 openChannelResp = new IccOpenLogicalChannelResponse(
603 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700605 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700606 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 break;
608
609 case CMD_CLOSE_CHANNEL:
610 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800611 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700612 if (uiccCard == null) {
613 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900614 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700615 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700616 } else {
617 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
618 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
619 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 break;
621
622 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800623 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
624 break;
625
626 case CMD_NV_READ_ITEM:
627 request = (MainThreadRequest) msg.obj;
628 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800629 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
630 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800631 break;
632
633 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 ar = (AsyncResult) msg.obj;
635 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800636 if (ar.exception == null && ar.result != null) {
637 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800639 request.result = "";
640 if (ar.result == null) {
641 loge("nvReadItem: Empty response");
642 } else if (ar.exception instanceof CommandException) {
643 loge("nvReadItem: CommandException: " +
644 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800646 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 }
648 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700649 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
Jake Hambye994d462014-02-03 13:10:13 -0800652 case CMD_NV_WRITE_ITEM:
653 request = (MainThreadRequest) msg.obj;
654 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
655 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800656 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700657 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800658 break;
659
660 case EVENT_NV_WRITE_ITEM_DONE:
661 handleNullReturnEvent(msg, "nvWriteItem");
662 break;
663
664 case CMD_NV_WRITE_CDMA_PRL:
665 request = (MainThreadRequest) msg.obj;
666 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800667 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800668 break;
669
670 case EVENT_NV_WRITE_CDMA_PRL_DONE:
671 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
672 break;
673
chen xu1cc0abe2018-10-26 17:39:23 -0700674 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800675 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700676 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800677 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800678 break;
679
chen xu1cc0abe2018-10-26 17:39:23 -0700680 case EVENT_RESET_MODEM_CONFIG_DONE:
681 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800682 break;
683
Jake Hamby7c27be32014-03-03 13:25:59 -0800684 case CMD_GET_PREFERRED_NETWORK_TYPE:
685 request = (MainThreadRequest) msg.obj;
686 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700687 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800688 break;
689
690 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
691 ar = (AsyncResult) msg.obj;
692 request = (MainThreadRequest) ar.userObj;
693 if (ar.exception == null && ar.result != null) {
694 request.result = ar.result; // Integer
695 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800696 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800697 if (ar.result == null) {
698 loge("getPreferredNetworkType: Empty response");
699 } else if (ar.exception instanceof CommandException) {
700 loge("getPreferredNetworkType: CommandException: " +
701 ar.exception);
702 } else {
703 loge("getPreferredNetworkType: Unknown exception");
704 }
705 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700706 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800707 break;
708
709 case CMD_SET_PREFERRED_NETWORK_TYPE:
710 request = (MainThreadRequest) msg.obj;
711 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
712 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700713 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 break;
715
716 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
717 handleNullReturnEvent(msg, "setPreferredNetworkType");
718 break;
719
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000720 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
721 request = (MainThreadRequest)msg.obj;
722 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800723 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000724 break;
725
726 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
727 ar = (AsyncResult)msg.obj;
728 request = (MainThreadRequest)ar.userObj;
729 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700730 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000731 break;
732
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800733 case CMD_SET_VOICEMAIL_NUMBER:
734 request = (MainThreadRequest) msg.obj;
735 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
736 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800737 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
738 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800739 break;
740
741 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
742 handleNullReturnEvent(msg, "setVoicemailNumber");
743 break;
744
Stuart Scott54788802015-03-30 13:18:01 -0700745 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
746 request = (MainThreadRequest) msg.obj;
747 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
748 request);
749 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
750 break;
751
752 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
753 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
754 break;
755
Shishir Agrawal302c8692015-06-19 13:49:39 -0700756 case CMD_PERFORM_NETWORK_SCAN:
757 request = (MainThreadRequest) msg.obj;
758 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
759 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
760 break;
761
762 case EVENT_PERFORM_NETWORK_SCAN_DONE:
763 ar = (AsyncResult) msg.obj;
764 request = (MainThreadRequest) ar.userObj;
765 CellNetworkScanResult cellScanResult;
766 if (ar.exception == null && ar.result != null) {
767 cellScanResult = new CellNetworkScanResult(
768 CellNetworkScanResult.STATUS_SUCCESS,
769 (List<OperatorInfo>) ar.result);
770 } else {
771 if (ar.result == null) {
772 loge("getCellNetworkScanResults: Empty response");
773 }
774 if (ar.exception != null) {
775 loge("getCellNetworkScanResults: Exception: " + ar.exception);
776 }
777 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
778 if (ar.exception instanceof CommandException) {
779 CommandException.Error error =
780 ((CommandException) (ar.exception)).getCommandError();
781 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
782 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
783 } else if (error == CommandException.Error.GENERIC_FAILURE) {
784 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
785 }
786 }
787 cellScanResult = new CellNetworkScanResult(errorCode, null);
788 }
789 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700790 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700791 break;
792
793 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
794 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700795 ManualNetworkSelectionArgument selArg =
796 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700797 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
798 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700799 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
800 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700801 break;
802
803 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700804 ar = (AsyncResult) msg.obj;
805 request = (MainThreadRequest) ar.userObj;
806 if (ar.exception == null) {
807 request.result = true;
808 } else {
809 request.result = false;
810 loge("setNetworkSelectionModeManual " + ar.exception);
811 }
812 notifyRequester(request);
813 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700814 break;
815
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700816 case CMD_GET_MODEM_ACTIVITY_INFO:
817 request = (MainThreadRequest) msg.obj;
818 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800819 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700820 break;
821
822 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
823 ar = (AsyncResult) msg.obj;
824 request = (MainThreadRequest) ar.userObj;
825 if (ar.exception == null && ar.result != null) {
826 request.result = ar.result;
827 } else {
828 if (ar.result == null) {
829 loge("queryModemActivityInfo: Empty response");
830 } else if (ar.exception instanceof CommandException) {
831 loge("queryModemActivityInfo: CommandException: " +
832 ar.exception);
833 } else {
834 loge("queryModemActivityInfo: Unknown exception");
835 }
836 }
Amit Mahajand4766222016-01-28 15:28:28 -0800837 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
838 if (request.result == null) {
839 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
840 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700841 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700842 break;
843
Meng Wang1a7c35a2016-05-05 20:56:15 -0700844 case CMD_SET_ALLOWED_CARRIERS:
845 request = (MainThreadRequest) msg.obj;
846 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800847 defaultPhone.setAllowedCarriers(
Meng Wang1a7c35a2016-05-05 20:56:15 -0700848 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700849 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700850 break;
851
852 case EVENT_SET_ALLOWED_CARRIERS_DONE:
853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null && ar.result != null) {
856 request.result = ar.result;
857 } else {
858 if (ar.result == null) {
859 loge("setAllowedCarriers: Empty response");
860 } else if (ar.exception instanceof CommandException) {
861 loge("setAllowedCarriers: CommandException: " +
862 ar.exception);
863 } else {
864 loge("setAllowedCarriers: Unknown exception");
865 }
866 }
867 // Result cannot be null. Return -1 on error.
868 if (request.result == null) {
869 request.result = new int[]{-1};
870 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700871 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700872 break;
873
874 case CMD_GET_ALLOWED_CARRIERS:
875 request = (MainThreadRequest) msg.obj;
876 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800877 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700878 break;
879
880 case EVENT_GET_ALLOWED_CARRIERS_DONE:
881 ar = (AsyncResult) msg.obj;
882 request = (MainThreadRequest) ar.userObj;
883 if (ar.exception == null && ar.result != null) {
884 request.result = ar.result;
885 } else {
886 if (ar.result == null) {
887 loge("getAllowedCarriers: Empty response");
888 } else if (ar.exception instanceof CommandException) {
889 loge("getAllowedCarriers: CommandException: " +
890 ar.exception);
891 } else {
892 loge("getAllowedCarriers: Unknown exception");
893 }
894 }
895 // Result cannot be null. Return empty list of CarrierIdentifier.
896 if (request.result == null) {
897 request.result = new ArrayList<CarrierIdentifier>(0);
898 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700899 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700900 break;
901
Nathan Haroldb3014052017-01-25 15:57:32 -0800902 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
903 ar = (AsyncResult) msg.obj;
904 request = (MainThreadRequest) ar.userObj;
905 if (ar.exception == null && ar.result != null) {
906 request.result = ar.result;
907 } else {
908 request.result = new IllegalArgumentException(
909 "Failed to retrieve Forbidden Plmns");
910 if (ar.result == null) {
911 loge("getForbiddenPlmns: Empty response");
912 } else {
913 loge("getForbiddenPlmns: Unknown exception");
914 }
915 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700916 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800917 break;
918
919 case CMD_GET_FORBIDDEN_PLMNS:
920 request = (MainThreadRequest) msg.obj;
921 uiccCard = getUiccCardFromRequest(request);
922 if (uiccCard == null) {
923 loge("getForbiddenPlmns() UiccCard is null");
924 request.result = new IllegalArgumentException(
925 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700926 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800927 break;
928 }
929 Integer appType = (Integer) request.argument;
930 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
931 if (uiccApp == null) {
932 loge("getForbiddenPlmns() no app with specified type -- "
933 + appType);
934 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700935 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800936 break;
937 } else {
938 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
939 + " specified type -- " + appType);
940 }
941 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
942 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
943 onCompleted);
944 break;
945
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000946 case CMD_SWITCH_SLOTS:
947 request = (MainThreadRequest) msg.obj;
948 int[] physicalSlots = (int[]) request.argument;
949 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
950 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
951 break;
952
953 case EVENT_SWITCH_SLOTS_DONE:
954 ar = (AsyncResult) msg.obj;
955 request = (MainThreadRequest) ar.userObj;
956 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700957 notifyRequester(request);
958 break;
959 case CMD_GET_NETWORK_SELECTION_MODE:
960 request = (MainThreadRequest) msg.obj;
961 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
962 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
963 break;
964
965 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
966 ar = (AsyncResult) msg.obj;
967 request = (MainThreadRequest) ar.userObj;
968 if (ar.exception != null) {
969 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
970 } else {
971 int mode = ((int[]) ar.result)[0];
972 if (mode == 0) {
973 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
974 } else {
975 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
976 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000977 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700978 notifyRequester(request);
979 break;
980 case CMD_GET_CDMA_ROAMING_MODE:
981 request = (MainThreadRequest) msg.obj;
982 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
983 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
984 break;
985 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
986 ar = (AsyncResult) msg.obj;
987 request = (MainThreadRequest) ar.userObj;
988 if (ar.exception != null) {
989 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
990 } else {
991 request.result = ((int[]) ar.result)[0];
992 }
993 notifyRequester(request);
994 break;
995 case CMD_SET_CDMA_ROAMING_MODE:
996 request = (MainThreadRequest) msg.obj;
997 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
998 int mode = (int) request.argument;
999 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1000 break;
1001 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
1004 request.result = ar.exception == null;
1005 notifyRequester(request);
1006 break;
1007 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1008 request = (MainThreadRequest) msg.obj;
1009 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1010 int subscriptionMode = (int) request.argument;
1011 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1012 break;
1013 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1014 ar = (AsyncResult) msg.obj;
1015 request = (MainThreadRequest) ar.userObj;
1016 request.result = ar.exception == null;
1017 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001018 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001019 case CMD_GET_ALL_CELL_INFO:
1020 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001021 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001022 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001023 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001024 case EVENT_GET_ALL_CELL_INFO_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001027 // If a timeout occurs, the response will be null
1028 request.result = (ar.exception == null && ar.result != null)
1029 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001030 synchronized (request) {
1031 request.notifyAll();
1032 }
1033 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001034 case CMD_REQUEST_CELL_INFO_UPDATE:
1035 request = (MainThreadRequest) msg.obj;
1036 request.phone.requestCellInfoUpdate(request.workSource,
1037 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1038 break;
1039 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
1042 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1043 try {
1044 if (ar.exception != null) {
1045 // something went wrong... the response is null
1046 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1047 cb.onCellInfo(null);
1048 } else if (ar.result == null) {
1049 // timeout occurred, so force the result to non-null "empty"
1050 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1051 cb.onCellInfo(new ArrayList<CellInfo>());
1052 } else {
1053 // use the result as returned
1054 cb.onCellInfo((List<CellInfo>) ar.result);
1055 }
1056 } catch (RemoteException re) {
1057 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1058 }
1059 break;
1060 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 request = (MainThreadRequest) msg.obj;
1062 WorkSource ws = (WorkSource) request.argument;
1063 Phone phone = getPhoneFromRequest(request);
1064 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1065 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001066 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
1069 if (ar.exception == null) {
1070 request.result = ar.result;
1071 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001072 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001073 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1074 ? new CdmaCellLocation() : new GsmCellLocation();
1075 }
1076
1077 synchronized (request) {
1078 request.notifyAll();
1079 }
1080 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001081 case CMD_MODEM_REBOOT:
1082 request = (MainThreadRequest) msg.obj;
1083 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001084 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001085 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001086 case EVENT_CMD_MODEM_REBOOT_DONE:
1087 handleNullReturnEvent(msg, "rebootModem");
1088 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001089 default:
1090 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1091 break;
1092 }
1093 }
Jake Hambye994d462014-02-03 13:10:13 -08001094
Pengquan Meng0c05b502018-09-06 09:59:22 -07001095 private void notifyRequester(MainThreadRequest request) {
1096 synchronized (request) {
1097 request.notifyAll();
1098 }
1099 }
1100
Jake Hambye994d462014-02-03 13:10:13 -08001101 private void handleNullReturnEvent(Message msg, String command) {
1102 AsyncResult ar = (AsyncResult) msg.obj;
1103 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1104 if (ar.exception == null) {
1105 request.result = true;
1106 } else {
1107 request.result = false;
1108 if (ar.exception instanceof CommandException) {
1109 loge(command + ": CommandException: " + ar.exception);
1110 } else {
1111 loge(command + ": Unknown exception");
1112 }
1113 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001114 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001115 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001116 }
1117
1118 /**
1119 * Posts the specified command to be executed on the main thread,
1120 * waits for the request to complete, and returns the result.
1121 * @see #sendRequestAsync
1122 */
1123 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001124 return sendRequest(
1125 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001126 }
1127
1128 /**
1129 * Posts the specified command to be executed on the main thread,
1130 * waits for the request to complete, and returns the result.
1131 * @see #sendRequestAsync
1132 */
1133 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1134 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001135 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001136 }
1137
1138 /**
1139 * Posts the specified command to be executed on the main thread,
1140 * waits for the request to complete, and returns the result.
1141 * @see #sendRequestAsync
1142 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001143 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001144 return sendRequest(command, argument, subId, 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 */
Nathan Harold92bed182018-10-12 18:16:49 -07001152 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1153 return sendRequest(command, argument, subId, null, workSource);
1154 }
1155
1156 /**
1157 * Posts the specified command to be executed on the main thread,
1158 * waits for the request to complete, and returns the result.
1159 * @see #sendRequestAsync
1160 */
1161 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1162 return sendRequest(
1163 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1164 }
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 */
1171 private Object sendRequest(
1172 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001173 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1174 throw new RuntimeException("This method will deadlock if called from the main thread.");
1175 }
1176
Nathan Harold92bed182018-10-12 18:16:49 -07001177 MainThreadRequest request = null;
1178 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1179 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1180 } else if (phone != null) {
1181 request = new MainThreadRequest(argument, phone, workSource);
1182 } else {
1183 request = new MainThreadRequest(argument, subId, workSource);
1184 }
1185
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001186 Message msg = mMainThreadHandler.obtainMessage(command, request);
1187 msg.sendToTarget();
1188
1189 // Wait for the request to complete
1190 synchronized (request) {
1191 while (request.result == null) {
1192 try {
1193 request.wait();
1194 } catch (InterruptedException e) {
1195 // Do nothing, go back and wait until the request is complete
1196 }
1197 }
1198 }
1199 return request.result;
1200 }
1201
1202 /**
1203 * Asynchronous ("fire and forget") version of sendRequest():
1204 * Posts the specified command to be executed on the main thread, and
1205 * returns immediately.
1206 * @see #sendRequest
1207 */
1208 private void sendRequestAsync(int command) {
1209 mMainThreadHandler.sendEmptyMessage(command);
1210 }
1211
1212 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001213 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001214 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001215 */
1216 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001217 sendRequestAsync(command, argument, null, null);
1218 }
1219
1220 /**
1221 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1222 * @see {@link #sendRequest(int,Object)}
1223 */
1224 private void sendRequestAsync(
1225 int command, Object argument, Phone phone, WorkSource workSource) {
1226 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001227 Message msg = mMainThreadHandler.obtainMessage(command, request);
1228 msg.sendToTarget();
1229 }
1230
1231 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232 * Initialize the singleton PhoneInterfaceManager instance.
1233 * This is only done once, at startup, from PhoneApp.onCreate().
1234 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001235 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001236 synchronized (PhoneInterfaceManager.class) {
1237 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001238 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001239 } else {
1240 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1241 }
1242 return sInstance;
1243 }
1244 }
1245
1246 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001247 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001250 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001251 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1252 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001253 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001254 mTelephonySharedPreferences =
1255 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001256 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001257 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001258
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259 publish();
1260 }
1261
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001262 private Phone getDefaultPhone() {
1263 Phone thePhone = getPhone(getDefaultSubscription());
1264 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1265 }
1266
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001267 private void publish() {
1268 if (DBG) log("publish: " + this);
1269
1270 ServiceManager.addService("phone", this);
1271 }
1272
Stuart Scott584921c2015-01-15 17:10:34 -08001273 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001274 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001275 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001276 }
1277
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001278 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1279 Phone phone = getPhoneFromRequest(request);
1280 return phone == null ? null :
1281 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1282 }
1283
Wink Saville36469e72014-06-11 15:17:00 -07001284 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001285 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001286 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001288
1289 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001290 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001291 }
1292
Wink Savilleb564aae2014-10-23 10:18:09 -07001293 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001294 if (DBG) log("dial: " + number);
1295 // No permission check needed here: This is just a wrapper around the
1296 // ACTION_DIAL intent, which is available to any app since it puts up
1297 // the UI before it does anything.
1298
Malcolm Chend965c8b2018-02-28 15:00:40 -08001299 final long identity = Binder.clearCallingIdentity();
1300 try {
1301 String url = createTelUrl(number);
1302 if (url == null) {
1303 return;
1304 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305
Malcolm Chend965c8b2018-02-28 15:00:40 -08001306 // PENDING: should we just silently fail if phone is offhook or ringing?
1307 PhoneConstants.State state = mCM.getState(subId);
1308 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1309 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1310 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1311 mApp.startActivity(intent);
1312 }
1313 } finally {
1314 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 }
1316 }
1317
1318 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001319 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001320 }
1321
Wink Savilleb564aae2014-10-23 10:18:09 -07001322 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001323 if (DBG) log("call: " + number);
1324
1325 // This is just a wrapper around the ACTION_CALL intent, but we still
1326 // need to do a permission check since we're calling startActivity()
1327 // from the context of the phone app.
1328 enforceCallPermission();
1329
1330 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1331 != AppOpsManager.MODE_ALLOWED) {
1332 return;
1333 }
1334
Malcolm Chend965c8b2018-02-28 15:00:40 -08001335 final long identity = Binder.clearCallingIdentity();
1336 try {
1337 String url = createTelUrl(number);
1338 if (url == null) {
1339 return;
1340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001341
Malcolm Chend965c8b2018-02-28 15:00:40 -08001342 boolean isValid = false;
1343 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1344 if (slist != null) {
1345 for (SubscriptionInfo subInfoRecord : slist) {
1346 if (subInfoRecord.getSubscriptionId() == subId) {
1347 isValid = true;
1348 break;
1349 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001350 }
Wink Saville08874612014-08-31 19:19:58 -07001351 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001352 if (!isValid) {
1353 return;
1354 }
Wink Saville08874612014-08-31 19:19:58 -07001355
Malcolm Chend965c8b2018-02-28 15:00:40 -08001356 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1357 intent.putExtra(SUBSCRIPTION_KEY, subId);
1358 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1359 mApp.startActivity(intent);
1360 } finally {
1361 Binder.restoreCallingIdentity(identity);
1362 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363 }
1364
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001366 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001367 }
1368
Wink Savilleb564aae2014-10-23 10:18:09 -07001369 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001370 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001371 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1372 }
1373
1374 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001376 }
1377
Wink Savilleb564aae2014-10-23 10:18:09 -07001378 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001379 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001380 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1381 }
1382
1383 /** {@hide} */
1384 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001385 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001386 }
1387
Wink Savilleb564aae2014-10-23 10:18:09 -07001388 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001389 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001390
1391 final long identity = Binder.clearCallingIdentity();
1392 try {
1393 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1394 checkSimPin.start();
1395 return checkSimPin.unlockSim(null, pin);
1396 } finally {
1397 Binder.restoreCallingIdentity(identity);
1398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001399 }
1400
Wink Saville9de0f752013-10-22 19:04:03 -07001401 /** {@hide} */
1402 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001403 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001404 }
1405
Wink Savilleb564aae2014-10-23 10:18:09 -07001406 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001408
1409 final long identity = Binder.clearCallingIdentity();
1410 try {
1411 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1412 checkSimPuk.start();
1413 return checkSimPuk.unlockSim(puk, pin);
1414 } finally {
1415 Binder.restoreCallingIdentity(identity);
1416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001417 }
1418
1419 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001420 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001421 * a synchronous one.
1422 */
1423 private static class UnlockSim extends Thread {
1424
1425 private final IccCard mSimCard;
1426
1427 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001428 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1429 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001430
1431 // For replies from SimCard interface
1432 private Handler mHandler;
1433
1434 // For async handler to identify request type
1435 private static final int SUPPLY_PIN_COMPLETE = 100;
1436
1437 public UnlockSim(IccCard simCard) {
1438 mSimCard = simCard;
1439 }
1440
1441 @Override
1442 public void run() {
1443 Looper.prepare();
1444 synchronized (UnlockSim.this) {
1445 mHandler = new Handler() {
1446 @Override
1447 public void handleMessage(Message msg) {
1448 AsyncResult ar = (AsyncResult) msg.obj;
1449 switch (msg.what) {
1450 case SUPPLY_PIN_COMPLETE:
1451 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1452 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001453 mRetryCount = msg.arg1;
1454 if (ar.exception != null) {
1455 if (ar.exception instanceof CommandException &&
1456 ((CommandException)(ar.exception)).getCommandError()
1457 == CommandException.Error.PASSWORD_INCORRECT) {
1458 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1459 } else {
1460 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1461 }
1462 } else {
1463 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1464 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001465 mDone = true;
1466 UnlockSim.this.notifyAll();
1467 }
1468 break;
1469 }
1470 }
1471 };
1472 UnlockSim.this.notifyAll();
1473 }
1474 Looper.loop();
1475 }
1476
1477 /*
1478 * Use PIN or PUK to unlock SIM card
1479 *
1480 * If PUK is null, unlock SIM card with PIN
1481 *
1482 * If PUK is not null, unlock SIM card with PUK and set PIN code
1483 */
Wink Saville9de0f752013-10-22 19:04:03 -07001484 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001485
1486 while (mHandler == null) {
1487 try {
1488 wait();
1489 } catch (InterruptedException e) {
1490 Thread.currentThread().interrupt();
1491 }
1492 }
1493 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1494
1495 if (puk == null) {
1496 mSimCard.supplyPin(pin, callback);
1497 } else {
1498 mSimCard.supplyPuk(puk, pin, callback);
1499 }
1500
1501 while (!mDone) {
1502 try {
1503 Log.d(LOG_TAG, "wait for done");
1504 wait();
1505 } catch (InterruptedException e) {
1506 // Restore the interrupted status
1507 Thread.currentThread().interrupt();
1508 }
1509 }
1510 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001511 int[] resultArray = new int[2];
1512 resultArray[0] = mResult;
1513 resultArray[1] = mRetryCount;
1514 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001515 }
1516 }
1517
1518 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001519 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001520
1521 }
1522
Wink Savilleb564aae2014-10-23 10:18:09 -07001523 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 // No permission check needed here: this call is harmless, and it's
1525 // needed for the ServiceState.requestStateUpdate() call (which is
1526 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001527 final long identity = Binder.clearCallingIdentity();
1528 try {
1529 final Phone phone = getPhone(subId);
1530 if (phone != null) {
1531 phone.updateServiceLocation();
1532 }
1533 } finally {
1534 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 }
1537
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001538 @Override
1539 public boolean isRadioOn(String callingPackage) {
1540 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001541 }
1542
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001543 @Override
1544 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001545 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001546 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001547 return false;
1548 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001549
1550 final long identity = Binder.clearCallingIdentity();
1551 try {
1552 return isRadioOnForSubscriber(subId);
1553 } finally {
1554 Binder.restoreCallingIdentity(identity);
1555 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001556 }
1557
1558 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001559 final long identity = Binder.clearCallingIdentity();
1560 try {
1561 final Phone phone = getPhone(subId);
1562 if (phone != null) {
1563 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1564 } else {
1565 return false;
1566 }
1567 } finally {
1568 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 }
1571
1572 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001573 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 }
Wink Saville36469e72014-06-11 15:17:00 -07001575
Wink Savilleb564aae2014-10-23 10:18:09 -07001576 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001578
1579 final long identity = Binder.clearCallingIdentity();
1580 try {
1581 final Phone phone = getPhone(subId);
1582 if (phone != null) {
1583 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1584 }
1585 } finally {
1586 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001587 }
Wink Saville36469e72014-06-11 15:17:00 -07001588 }
1589
1590 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001591 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001592 }
1593
Wink Savilleb564aae2014-10-23 10:18:09 -07001594 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001595 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001596
1597 final long identity = Binder.clearCallingIdentity();
1598 try {
1599 final Phone phone = getPhone(subId);
1600 if (phone == null) {
1601 return false;
1602 }
1603 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1604 toggleRadioOnOffForSubscriber(subId);
1605 }
1606 return true;
1607 } finally {
1608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 }
Wink Saville36469e72014-06-11 15:17:00 -07001611
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001612 public boolean needMobileRadioShutdown() {
1613 /*
1614 * If any of the Radios are available, it will need to be
1615 * shutdown. So return true if any Radio is available.
1616 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001617 final long identity = Binder.clearCallingIdentity();
1618 try {
1619 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1620 Phone phone = PhoneFactory.getPhone(i);
1621 if (phone != null && phone.isRadioAvailable()) return true;
1622 }
1623 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1624 return false;
1625 } finally {
1626 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001627 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001628 }
1629
Malcolm Chend965c8b2018-02-28 15:00:40 -08001630 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001631 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001632 enforceModifyPermission();
1633
1634 final long identity = Binder.clearCallingIdentity();
1635 try {
1636 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1637 logv("Shutting down Phone " + i);
1638 shutdownRadioUsingPhoneId(i);
1639 }
1640 } finally {
1641 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001642 }
1643 }
1644
1645 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001646 Phone phone = PhoneFactory.getPhone(phoneId);
1647 if (phone != null && phone.isRadioAvailable()) {
1648 phone.shutdownRadio();
1649 }
1650 }
1651
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001653 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001654
1655 final long identity = Binder.clearCallingIdentity();
1656 try {
1657 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1658 if (defaultPhone != null) {
1659 defaultPhone.setRadioPower(turnOn);
1660 return true;
1661 } else {
1662 loge("There's no default phone.");
1663 return false;
1664 }
1665 } finally {
1666 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001667 }
Wink Saville36469e72014-06-11 15:17:00 -07001668 }
1669
Wink Savilleb564aae2014-10-23 10:18:09 -07001670 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001672
1673 final long identity = Binder.clearCallingIdentity();
1674 try {
1675 final Phone phone = getPhone(subId);
1676 if (phone != null) {
1677 phone.setRadioPower(turnOn);
1678 return true;
1679 } else {
1680 return false;
1681 }
1682 } finally {
1683 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001684 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 }
1686
Wink Saville36469e72014-06-11 15:17:00 -07001687 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001688 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 public boolean enableDataConnectivity() {
1690 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001691
1692 final long identity = Binder.clearCallingIdentity();
1693 try {
1694 int subId = mSubscriptionController.getDefaultDataSubId();
1695 final Phone phone = getPhone(subId);
1696 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001697 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001698 return true;
1699 } else {
1700 return false;
1701 }
1702 } finally {
1703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 }
1706
Wink Saville36469e72014-06-11 15:17:00 -07001707 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001708 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709 public boolean disableDataConnectivity() {
1710 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001711
1712 final long identity = Binder.clearCallingIdentity();
1713 try {
1714 int subId = mSubscriptionController.getDefaultDataSubId();
1715 final Phone phone = getPhone(subId);
1716 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001717 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001718 return true;
1719 } else {
1720 return false;
1721 }
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
Sanket Padawe356d7632015-06-22 14:03:32 -07001727 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001728 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001729 final long identity = Binder.clearCallingIdentity();
1730 try {
1731 final Phone phone = getPhone(subId);
1732 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001733 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001734 } else {
1735 return false;
1736 }
1737 } finally {
1738 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 }
1741
1742 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001743 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001744 }
1745
pkanwarae03a6b2016-11-06 20:37:09 -08001746 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001747 enforceCallPermission();
1748
1749 final long identity = Binder.clearCallingIdentity();
1750 try {
1751 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1752 return;
1753 }
1754 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1755 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1756 } finally {
1757 Binder.restoreCallingIdentity(identity);
1758 }
pkanwar32d516d2016-10-14 19:37:38 -07001759 };
1760
Wink Savilleb564aae2014-10-23 10:18:09 -07001761 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001763
1764 final long identity = Binder.clearCallingIdentity();
1765 try {
1766 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1767 return false;
1768 }
1769 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1770 } finally {
1771 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 }
1774
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001776 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001777 }
1778
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001779 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001780 final long identity = Binder.clearCallingIdentity();
1781 try {
1782 Phone phone = PhoneFactory.getPhone(slotIndex);
1783 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1784 PhoneConstantConversions.convertCallState(phone.getState());
1785 } finally {
1786 Binder.restoreCallingIdentity(identity);
1787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
1789
Sanket Padawe356d7632015-06-22 14:03:32 -07001790 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1795 if (phone != null) {
1796 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1797 } else {
1798 return PhoneConstantConversions.convertDataState(
1799 PhoneConstants.DataState.DISCONNECTED);
1800 }
1801 } finally {
1802 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001803 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 }
1805
Sanket Padawe356d7632015-06-22 14:03:32 -07001806 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001808 final long identity = Binder.clearCallingIdentity();
1809 try {
1810 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1811 if (phone != null) {
1812 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1813 } else {
1814 return TelephonyManager.DATA_ACTIVITY_NONE;
1815 }
1816 } finally {
1817 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 }
1820
1821 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001822 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001823 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001824 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001825 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1826 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001827 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 }
1829
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001830 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001831 final long identity = Binder.clearCallingIdentity();
1832 try {
1833 if (DBG_LOC) log("getCellLocation: is active user");
1834 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001835 int subId = mSubscriptionController.getDefaultDataSubId();
1836 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1837 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001838 return data;
1839 } finally {
1840 Binder.restoreCallingIdentity(identity);
1841 }
Svetoslav64fad262015-04-14 14:35:21 -07001842 }
1843
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001844 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001845 public String getNetworkCountryIsoForPhone(int phoneId) {
1846 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1847 // registered cell info, so return a NULL country instead.
1848 final long identity = Binder.clearCallingIdentity();
1849 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001850 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1851 // Get default phone in this case.
1852 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1853 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001854 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001855 // Todo: fix this when we can get the actual cellular network info when the device
1856 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001857 if (TelephonyManager.NETWORK_TYPE_IWLAN
1858 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1859 return "";
1860 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001861 Phone phone = PhoneFactory.getPhone(phoneId);
1862 if (phone != null) {
1863 ServiceStateTracker sst = phone.getServiceStateTracker();
1864 if (sst != null) {
1865 LocaleTracker lt = sst.getLocaleTracker();
1866 if (lt != null) {
1867 return lt.getCurrentCountry();
1868 }
1869 }
1870 }
1871 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001872 } finally {
1873 Binder.restoreCallingIdentity(identity);
1874 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001875 }
1876
1877 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001879 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001880 }
1881
Sanket Padawe356d7632015-06-22 14:03:32 -07001882 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001883 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 mApp.enforceCallingOrSelfPermission(
1885 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001886
1887 final long identity = Binder.clearCallingIdentity();
1888 try {
1889 final Phone phone = getPhone(subId);
1890 if (phone != null) {
1891 phone.enableLocationUpdates();
1892 }
1893 } finally {
1894 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 }
1897
1898 @Override
1899 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001900 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001901 }
1902
Sanket Padawe356d7632015-06-22 14:03:32 -07001903 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001904 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 mApp.enforceCallingOrSelfPermission(
1906 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001907
1908 final long identity = Binder.clearCallingIdentity();
1909 try {
1910 final Phone phone = getPhone(subId);
1911 if (phone != null) {
1912 phone.disableLocationUpdates();
1913 }
1914 } finally {
1915 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001916 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917 }
1918
Nathan Harold31d7ff32018-10-15 20:20:30 -07001919 /**
1920 * Returns the target SDK version number for a given package name.
1921 *
1922 * @return target SDK if the package is found or INT_MAX.
1923 */
1924 private int getTargetSdk(String packageName) {
1925 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001926 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1927 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001928 if (ai != null) return ai.targetSdkVersion;
1929 } catch (PackageManager.NameNotFoundException unexpected) {
1930 }
1931 return Integer.MAX_VALUE;
1932 }
1933
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 @Override
1935 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001936 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1937 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001938 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1939 throw new SecurityException(
1940 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1941 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001942
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1944 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1945 return null;
1946 }
Svetoslav64fad262015-04-14 14:35:21 -07001947
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001948 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949
Nathan Haroldf180aac2018-06-01 18:43:55 -07001950 List<CellInfo> info = getAllCellInfo(callingPackage);
1951 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952
Nathan Haroldf180aac2018-06-01 18:43:55 -07001953 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1954 for (CellInfo ci : info) {
1955 if (ci instanceof CellInfoGsm) {
1956 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1957 } else if (ci instanceof CellInfoWcdma) {
1958 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001960 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001961 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 }
1963
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001964 private List<CellInfo> getCachedCellInfo() {
1965 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1966 for (Phone phone : PhoneFactory.getPhones()) {
1967 List<CellInfo> info = phone.getAllCellInfo();
1968 if (info != null) cellInfos.addAll(info);
1969 }
1970 return cellInfos;
1971 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001972
1973 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001974 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001975 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001976 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001977 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001978 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001979 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001980 }
1981
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001982 final int targetSdk = getTargetSdk(callingPackage);
1983 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1984 return getCachedCellInfo();
1985 }
1986
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001987 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001988 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001989 final long identity = Binder.clearCallingIdentity();
1990 try {
1991 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1992 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001993 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001994 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001995 if (info != null) cellInfos.addAll(info);
1996 }
1997 return cellInfos;
1998 } finally {
1999 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 }
2001 }
2002
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002003 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002004 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2005 requestCellInfoUpdateInternal(
2006 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2007 }
2008
2009 @Override
2010 public void requestCellInfoUpdateWithWorkSource(
2011 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2012 enforceModifyPermission();
2013 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2014 }
2015
2016 private void requestCellInfoUpdateInternal(
2017 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002018 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002019 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002020 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2021 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002022 return;
2023 }
2024
2025 final Phone phone = getPhone(subId);
2026 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2027
2028 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2029 }
2030
2031 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002033 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002034 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002035
2036 final long identity = Binder.clearCallingIdentity();
2037 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002038 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002039 } finally {
2040 Binder.restoreCallingIdentity(identity);
2041 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002042 }
2043
Shishir Agrawala9f32182016-04-12 12:00:16 -07002044 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002045 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002046 Phone phone = PhoneFactory.getPhone(slotIndex);
2047 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002048 return null;
2049 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002050 int subId = phone.getSubId();
2051 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2052 mApp, subId, callingPackage, "getImeiForSlot")) {
2053 return null;
2054 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002055
2056 final long identity = Binder.clearCallingIdentity();
2057 try {
2058 return phone.getImei();
2059 } finally {
2060 Binder.restoreCallingIdentity(identity);
2061 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002062 }
2063
2064 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002065 public String getTypeAllocationCodeForSlot(int slotIndex) {
2066 Phone phone = PhoneFactory.getPhone(slotIndex);
2067 String tac = null;
2068 if (phone != null) {
2069 String imei = phone.getImei();
2070 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2071 }
2072 return tac;
2073 }
2074
2075 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002076 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002077 Phone phone = PhoneFactory.getPhone(slotIndex);
2078 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002079 return null;
2080 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002081
Jeff Davidson913390f2018-02-23 17:11:49 -08002082 int subId = phone.getSubId();
2083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2084 mApp, subId, callingPackage, "getMeidForSlot")) {
2085 return null;
2086 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002087
2088 final long identity = Binder.clearCallingIdentity();
2089 try {
2090 return phone.getMeid();
2091 } finally {
2092 Binder.restoreCallingIdentity(identity);
2093 }
Jack Yu2af8d712017-03-15 17:14:14 -07002094 }
2095
2096 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002097 public String getManufacturerCodeForSlot(int slotIndex) {
2098 Phone phone = PhoneFactory.getPhone(slotIndex);
2099 String manufacturerCode = null;
2100 if (phone != null) {
2101 String meid = phone.getMeid();
2102 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2103 }
2104 return manufacturerCode;
2105 }
2106
2107 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002108 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002109 Phone phone = PhoneFactory.getPhone(slotIndex);
2110 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002111 return null;
2112 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002113 int subId = phone.getSubId();
2114 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2115 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2116 return null;
2117 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002118
2119 final long identity = Binder.clearCallingIdentity();
2120 try {
2121 return phone.getDeviceSvn();
2122 } finally {
2123 Binder.restoreCallingIdentity(identity);
2124 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002125 }
2126
fionaxu43304da2017-11-27 22:51:16 -08002127 @Override
2128 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002129 final long identity = Binder.clearCallingIdentity();
2130 try {
2131 final Phone phone = getPhone(subId);
2132 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2133 } finally {
2134 Binder.restoreCallingIdentity(identity);
2135 }
fionaxu43304da2017-11-27 22:51:16 -08002136 }
2137
2138 @Override
2139 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002140 final long identity = Binder.clearCallingIdentity();
2141 try {
2142 final Phone phone = getPhone(subId);
2143 return phone == null ? null : phone.getCarrierName();
2144 } finally {
2145 Binder.restoreCallingIdentity(identity);
2146 }
fionaxu43304da2017-11-27 22:51:16 -08002147 }
2148
calvinpaneed9ae82018-11-01 19:43:06 +08002149 @Override
chen xuc93cc282018-11-04 17:17:00 -08002150 public int getSubscriptionPreciseCarrierId(int subId) {
2151 final long identity = Binder.clearCallingIdentity();
2152 try {
2153 final Phone phone = getPhone(subId);
2154 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2155 : phone.getPreciseCarrierId();
2156 } finally {
2157 Binder.restoreCallingIdentity(identity);
2158 }
2159 }
2160
2161 @Override
2162 public String getSubscriptionPreciseCarrierName(int subId) {
2163 final long identity = Binder.clearCallingIdentity();
2164 try {
2165 final Phone phone = getPhone(subId);
2166 return phone == null ? null : phone.getPreciseCarrierName();
2167 } finally {
2168 Binder.restoreCallingIdentity(identity);
2169 }
2170 }
2171
chen xu02581692018-11-11 19:03:44 -08002172 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002173 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2174 if (!isSubscriptionMccMnc) {
2175 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2176 }
chen xu02581692018-11-11 19:03:44 -08002177 final Phone phone = PhoneFactory.getPhone(slotIndex);
2178 if (phone == null) {
2179 return TelephonyManager.UNKNOWN_CARRIER_ID;
2180 }
2181 final long identity = Binder.clearCallingIdentity();
2182 try {
2183 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2184 } finally {
2185 Binder.restoreCallingIdentity(identity);
2186 }
2187 }
2188
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 //
2190 // Internal helper methods.
2191 //
2192
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002193 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2195 *
2196 * @throws SecurityException if the caller does not have the required permission
2197 */
2198 private void enforceModifyPermission() {
2199 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2200 }
2201
2202 /**
2203 * Make sure the caller has the CALL_PHONE permission.
2204 *
2205 * @throws SecurityException if the caller does not have the required permission
2206 */
2207 private void enforceCallPermission() {
2208 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2209 }
2210
Stuart Scott8eef64f2015-04-08 15:13:54 -07002211 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002212 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002213 "ConnectivityService");
2214 }
2215
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 private String createTelUrl(String number) {
2217 if (TextUtils.isEmpty(number)) {
2218 return null;
2219 }
2220
Jake Hambye994d462014-02-03 13:10:13 -08002221 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002222 }
2223
Ihab Awadf9e92732013-12-05 18:02:52 -08002224 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2226 }
2227
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002228 private static void logv(String msg) {
2229 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2230 }
2231
Ihab Awadf9e92732013-12-05 18:02:52 -08002232 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002233 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2234 }
2235
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002236 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002238 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002239 }
2240
Sanket Padawe356d7632015-06-22 14:03:32 -07002241 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002242 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002243 final long identity = Binder.clearCallingIdentity();
2244 try {
2245 final Phone phone = PhoneFactory.getPhone(slotIndex);
2246 if (phone == null) {
2247 return PhoneConstants.PHONE_TYPE_NONE;
2248 } else {
2249 return phone.getPhoneType();
2250 }
2251 } finally {
2252 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 }
2255
2256 /**
2257 * Returns the CDMA ERI icon index to display
2258 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002259 @Override
2260 public int getCdmaEriIconIndex(String callingPackage) {
2261 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002262 }
2263
Sanket Padawe356d7632015-06-22 14:03:32 -07002264 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002265 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002266 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002267 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002268 return -1;
2269 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002270
2271 final long identity = Binder.clearCallingIdentity();
2272 try {
2273 final Phone phone = getPhone(subId);
2274 if (phone != null) {
2275 return phone.getCdmaEriIconIndex();
2276 } else {
2277 return -1;
2278 }
2279 } finally {
2280 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 }
2283
2284 /**
2285 * Returns the CDMA ERI icon mode,
2286 * 0 - ON
2287 * 1 - FLASHING
2288 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002289 @Override
2290 public int getCdmaEriIconMode(String callingPackage) {
2291 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002292 }
2293
Sanket Padawe356d7632015-06-22 14:03:32 -07002294 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002295 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002297 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002298 return -1;
2299 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002300
2301 final long identity = Binder.clearCallingIdentity();
2302 try {
2303 final Phone phone = getPhone(subId);
2304 if (phone != null) {
2305 return phone.getCdmaEriIconMode();
2306 } else {
2307 return -1;
2308 }
2309 } finally {
2310 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313
2314 /**
2315 * Returns the CDMA ERI text,
2316 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002317 @Override
2318 public String getCdmaEriText(String callingPackage) {
2319 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002320 }
2321
Sanket Padawe356d7632015-06-22 14:03:32 -07002322 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002323 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002325 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002326 return null;
2327 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002328
2329 final long identity = Binder.clearCallingIdentity();
2330 try {
2331 final Phone phone = getPhone(subId);
2332 if (phone != null) {
2333 return phone.getCdmaEriText();
2334 } else {
2335 return null;
2336 }
2337 } finally {
2338 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 }
2341
2342 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002343 * Returns the CDMA MDN.
2344 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002345 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002346 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2348 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002349
2350 final long identity = Binder.clearCallingIdentity();
2351 try {
2352 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002353 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002354 return phone.getLine1Number();
2355 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002356 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002357 return null;
2358 }
2359 } finally {
2360 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002361 }
2362 }
2363
2364 /**
2365 * Returns the CDMA MIN.
2366 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002367 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002368 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2370 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002371
2372 final long identity = Binder.clearCallingIdentity();
2373 try {
2374 final Phone phone = getPhone(subId);
2375 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2376 return phone.getCdmaMin();
2377 } else {
2378 return null;
2379 }
2380 } finally {
2381 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002382 }
2383 }
2384
Hall Liud892bec2018-11-30 14:51:45 -08002385 @Override
2386 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2387 INumberVerificationCallback callback, String callingPackage) {
2388 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2389 != PERMISSION_GRANTED) {
2390 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2391 }
2392 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2393
2394 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2395 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2396 throw new SecurityException("Calling package must be configured in the device config");
2397 }
2398
2399 if (range == null) {
2400 throw new NullPointerException("Range must be non-null");
2401 }
2402
2403 timeoutMillis = Math.min(timeoutMillis,
2404 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2405
2406 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2407 }
2408
Junda Liuca05d5d2014-08-14 22:36:34 -07002409 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 * Returns true if CDMA provisioning needs to run.
2411 */
2412 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002413 final long identity = Binder.clearCallingIdentity();
2414 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002415 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002416 } finally {
2417 Binder.restoreCallingIdentity(identity);
2418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 }
2420
2421 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002422 * Sets the voice mail number of a given subId.
2423 */
2424 @Override
2425 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002426 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002427
2428 final long identity = Binder.clearCallingIdentity();
2429 try {
2430 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2431 new Pair<String, String>(alphaTag, number), new Integer(subId));
2432 return success;
2433 } finally {
2434 Binder.restoreCallingIdentity(identity);
2435 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002436 }
2437
Ta-wei Yen87c49842016-05-13 21:19:52 -07002438 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002439 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2440 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002441 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002442 if (!TextUtils.equals(callingPackage, systemDialer)) {
2443 throw new SecurityException("caller must be system dialer");
2444 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002445
2446 final long identity = Binder.clearCallingIdentity();
2447 try {
2448 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2449 if (phoneAccountHandle == null) {
2450 return null;
2451 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002452 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002453 } finally {
2454 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002455 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002456 }
2457
2458 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002459 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002460 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002462 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002463 return null;
2464 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002465
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002466 final long identity = Binder.clearCallingIdentity();
2467 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002468 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002469 } finally {
2470 Binder.restoreCallingIdentity(identity);
2471 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002472 }
2473
2474 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002475 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2476 VisualVoicemailSmsFilterSettings settings) {
2477 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002478
2479 final long identity = Binder.clearCallingIdentity();
2480 try {
2481 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002482 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002483 } finally {
2484 Binder.restoreCallingIdentity(identity);
2485 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002486 }
2487
2488 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002489 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2490 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002491
2492 final long identity = Binder.clearCallingIdentity();
2493 try {
2494 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002495 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002496 } finally {
2497 Binder.restoreCallingIdentity(identity);
2498 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002499 }
2500
2501 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002502 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2503 String callingPackage, int subId) {
2504 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002509 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002510 } finally {
2511 Binder.restoreCallingIdentity(identity);
2512 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002513 }
2514
2515 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002516 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002517 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002518
2519 final long identity = Binder.clearCallingIdentity();
2520 try {
2521 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002522 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002523 } finally {
2524 Binder.restoreCallingIdentity(identity);
2525 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002526 }
2527
2528 @Override
2529 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2530 String number, int port, String text, PendingIntent sentIntent) {
2531 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002532 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002533 enforceSendSmsPermission();
2534 // Make the calls as the phone process.
2535 final long identity = Binder.clearCallingIdentity();
2536 try {
2537 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2538 if (port == 0) {
2539 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2540 sentIntent, null, false);
2541 } else {
2542 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2543 smsManager.sendDataMessageWithSelfPermissions(number, null,
2544 (short) port, data, sentIntent, null);
2545 }
2546 } finally {
2547 Binder.restoreCallingIdentity(identity);
2548 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002549 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002550 /**
fionaxu0152e512016-11-14 13:36:14 -08002551 * Sets the voice activation state of a given subId.
2552 */
2553 @Override
2554 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2556 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002557
2558 final long identity = Binder.clearCallingIdentity();
2559 try {
2560 final Phone phone = getPhone(subId);
2561 if (phone != null) {
2562 phone.setVoiceActivationState(activationState);
2563 } else {
2564 loge("setVoiceActivationState fails with invalid subId: " + subId);
2565 }
2566 } finally {
2567 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002568 }
2569 }
2570
2571 /**
2572 * Sets the data activation state of a given subId.
2573 */
2574 @Override
2575 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2577 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002578
2579 final long identity = Binder.clearCallingIdentity();
2580 try {
2581 final Phone phone = getPhone(subId);
2582 if (phone != null) {
2583 phone.setDataActivationState(activationState);
2584 } else {
2585 loge("setVoiceActivationState fails with invalid subId: " + subId);
2586 }
2587 } finally {
2588 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002589 }
2590 }
2591
2592 /**
2593 * Returns the voice activation state of a given subId.
2594 */
2595 @Override
2596 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002597 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002598
fionaxu0152e512016-11-14 13:36:14 -08002599 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 if (phone != null) {
2603 return phone.getVoiceActivationState();
2604 } else {
2605 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2606 }
2607 } finally {
2608 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002609 }
2610 }
2611
2612 /**
2613 * Returns the data activation state of a given subId.
2614 */
2615 @Override
2616 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002617 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002618
fionaxu0152e512016-11-14 13:36:14 -08002619 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002620 final long identity = Binder.clearCallingIdentity();
2621 try {
2622 if (phone != null) {
2623 return phone.getDataActivationState();
2624 } else {
2625 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2626 }
2627 } finally {
2628 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002629 }
2630 }
2631
2632 /**
Wink Saville36469e72014-06-11 15:17:00 -07002633 * Returns the unread count of voicemails for a subId
2634 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002635 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002636 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2637 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2638 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2639 return 0;
2640 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 final Phone phone = getPhone(subId);
2644 if (phone != null) {
2645 return phone.getVoiceMessageCount();
2646 } else {
2647 return 0;
2648 }
2649 } finally {
2650 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 }
2653
2654 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002655 * returns true, if the device is in a state where both voice and data
2656 * are supported simultaneously. This can change based on location or network condition.
2657 */
2658 @Override
2659 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002660 final long identity = Binder.clearCallingIdentity();
2661 try {
2662 final Phone phone = getPhone(subId);
2663 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2664 } finally {
2665 Binder.restoreCallingIdentity(identity);
2666 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002667 }
2668
2669 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002670 * Send the dialer code if called from the current default dialer or the caller has
2671 * carrier privilege.
2672 * @param inputCode The dialer code to send
2673 */
2674 @Override
2675 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002676 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002677 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002678 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2679 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002680 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002681 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2682 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002683 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002684
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002687 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002688 } finally {
2689 Binder.restoreCallingIdentity(identity);
2690 }
fionaxu235cc5e2017-03-06 22:25:57 -08002691 }
2692
2693 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002694 * Returns the data network type.
2695 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 *
2697 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2698 */
2699 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002700 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 final Phone phone = getPhone(getDefaultSubscription());
2704 if (phone != null) {
2705 return phone.getServiceState().getDataNetworkType();
2706 } else {
2707 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2708 }
2709 } finally {
2710 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002711 }
Wink Saville36469e72014-06-11 15:17:00 -07002712 }
2713
Pengquan Meng0c05b502018-09-06 09:59:22 -07002714 @Override
2715 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002716 if (!isActiveSubscription(subId)) {
2717 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2718 }
2719
Pengquan Meng0c05b502018-09-06 09:59:22 -07002720 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2721 }
2722
Brad Ebinger4c460712018-10-01 10:40:55 -07002723 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002724 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2725 throws RemoteException {
2726 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002727 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2728 final long token = Binder.clearCallingIdentity();
2729 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002730 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002731 .addRegistrationCallbackForSubscription(c, subId);
2732 } finally {
2733 Binder.restoreCallingIdentity(token);
2734 }
2735 }
2736
2737 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002738 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2739 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002740 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2741 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002742 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002743 .removeRegistrationCallbackForSubscription(c, subId));
2744 }
2745
2746 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002747 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2748 throws RemoteException {
2749 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002750 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2751 final long token = Binder.clearCallingIdentity();
2752 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002753 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002754 .addCapabilitiesCallbackForSubscription(c, subId);
2755 } finally {
2756 Binder.restoreCallingIdentity(token);
2757 }
2758 }
2759
2760 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002761 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2762 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002763 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2764 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002765 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002766 .removeCapabilitiesCallbackForSubscription(c, subId));
2767 }
2768
2769 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002770 public boolean isCapable(int subId, int capability, int regTech) {
2771 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002772 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2773 final long token = Binder.clearCallingIdentity();
2774 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002775 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002776 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2777 } catch (ImsException e) {
2778 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2779 return false;
2780 } finally {
2781 Binder.restoreCallingIdentity(token);
2782 }
2783 }
2784
2785 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002786 public boolean isAvailable(int subId, int capability, int regTech) {
2787 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002788 final long token = Binder.clearCallingIdentity();
2789 try {
2790 Phone phone = getPhone(subId);
2791 if (phone == null) return false;
2792 return phone.isImsCapabilityAvailable(capability, regTech);
2793 } finally {
2794 Binder.restoreCallingIdentity(token);
2795 }
2796 }
2797
2798 @Override
2799 public boolean isAdvancedCallingSettingEnabled(int subId) {
2800 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2801 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2802 final long token = Binder.clearCallingIdentity();
2803 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002804 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002805 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2806 } finally {
2807 Binder.restoreCallingIdentity(token);
2808 }
2809 }
2810
2811 @Override
2812 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2814 "setAdvancedCallingSetting");
2815 final long identity = Binder.clearCallingIdentity();
2816 try {
2817 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002818 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002819 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2820 } finally {
2821 Binder.restoreCallingIdentity(identity);
2822 }
2823 }
2824
2825 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002826 public boolean isVtSettingEnabled(int subId) {
2827 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002828 final long identity = Binder.clearCallingIdentity();
2829 try {
2830 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002831 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002832 getSlotIndexOrException(subId)).isVtEnabledByUser();
2833 } finally {
2834 Binder.restoreCallingIdentity(identity);
2835 }
2836 }
2837
2838 @Override
2839 public void setVtSetting(int subId, boolean isEnabled) {
2840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2841 "setVtSetting");
2842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002845 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002846 } finally {
2847 Binder.restoreCallingIdentity(identity);
2848 }
2849 }
2850
2851 @Override
2852 public boolean isVoWiFiSettingEnabled(int subId) {
2853 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2854 final long identity = Binder.clearCallingIdentity();
2855 try {
2856 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002857 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002858 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2859 } finally {
2860 Binder.restoreCallingIdentity(identity);
2861 }
2862 }
2863
2864 @Override
2865 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2867 "setVoWiFiSetting");
2868 final long identity = Binder.clearCallingIdentity();
2869 try {
2870 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002871 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002872 } finally {
2873 Binder.restoreCallingIdentity(identity);
2874 }
2875 }
2876
2877 @Override
2878 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2879 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2880 final long identity = Binder.clearCallingIdentity();
2881 try {
2882 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002883 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002884 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2885 } finally {
2886 Binder.restoreCallingIdentity(identity);
2887 }
2888 }
2889
2890 @Override
2891 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2893 "setVoWiFiRoamingSetting");
2894 final long identity = Binder.clearCallingIdentity();
2895 try {
2896 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002897 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002898 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2899 } finally {
2900 Binder.restoreCallingIdentity(identity);
2901 }
2902 }
2903
2904 @Override
2905 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2907 "setVoWiFiNonPersistent");
2908 final long identity = Binder.clearCallingIdentity();
2909 try {
2910 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002911 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002912 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2913 } finally {
2914 Binder.restoreCallingIdentity(identity);
2915 }
2916 }
2917
2918 @Override
2919 public int getVoWiFiModeSetting(int subId) {
2920 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2921 final long identity = Binder.clearCallingIdentity();
2922 try {
2923 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002924 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002925 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2926 } finally {
2927 Binder.restoreCallingIdentity(identity);
2928 }
2929 }
2930
2931 @Override
2932 public void setVoWiFiModeSetting(int subId, int mode) {
2933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2934 "setVoWiFiModeSetting");
2935 final long identity = Binder.clearCallingIdentity();
2936 try {
2937 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002938 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002939 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
2942 }
2943 }
2944
2945 @Override
2946 public int getVoWiFiRoamingModeSetting(int subId) {
2947 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002951 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002952 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2953 } finally {
2954 Binder.restoreCallingIdentity(identity);
2955 }
2956 }
2957
2958 @Override
2959 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2961 "setVoWiFiRoamingModeSetting");
2962 final long identity = Binder.clearCallingIdentity();
2963 try {
2964 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002965 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002966 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
2970 }
2971
2972 @Override
2973 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2975 "setRttCapabilityEnabled");
2976 final long identity = Binder.clearCallingIdentity();
2977 try {
2978 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002979 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002980 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2981 } finally {
2982 Binder.restoreCallingIdentity(identity);
2983 }
2984 }
2985
2986 @Override
2987 public boolean isTtyOverVolteEnabled(int subId) {
2988 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2989 final long identity = Binder.clearCallingIdentity();
2990 try {
2991 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002992 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002993 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2994 } finally {
2995 Binder.restoreCallingIdentity(identity);
2996 }
2997 }
2998
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002999 @Override
3000 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3001 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003005 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003006 .getConfigInterface().addConfigCallback(callback);
3007 } catch (ImsException e) {
3008 throw new IllegalArgumentException(e.getMessage());
3009 } finally {
3010 Binder.restoreCallingIdentity(identity);
3011 }
3012 }
3013
3014 @Override
3015 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3016 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3017 final long identity = Binder.clearCallingIdentity();
3018 try {
3019 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003020 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003021 .getConfigInterface().removeConfigCallback(callback);
3022 } catch (ImsException e) {
3023 throw new IllegalArgumentException(e.getMessage());
3024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
3027 }
3028
3029 @Override
3030 public int getImsProvisioningInt(int subId, int key) {
3031 enforceReadPrivilegedPermission("getImsProvisioningInt");
3032 final long identity = Binder.clearCallingIdentity();
3033 try {
3034 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003035 return ImsManager.getInstance(mApp,
3036 getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003037 } catch (ImsException e) {
3038 throw new IllegalArgumentException(e.getMessage());
3039 } finally {
3040 Binder.restoreCallingIdentity(identity);
3041 }
3042 }
3043
3044 @Override
3045 public String getImsProvisioningString(int subId, int key) {
3046 enforceReadPrivilegedPermission("getImsProvisioningString");
3047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003050 return ImsManager.getInstance(mApp,
3051 getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003052 } catch (ImsException e) {
3053 throw new IllegalArgumentException(e.getMessage());
3054 } finally {
3055 Binder.restoreCallingIdentity(identity);
3056 }
3057 }
3058
3059 @Override
3060 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3062 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003063 final long identity = Binder.clearCallingIdentity();
3064 try {
3065 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003066 return ImsManager.getInstance(mApp,
3067 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003068 } catch (ImsException e) {
3069 throw new IllegalArgumentException(e.getMessage());
3070 } finally {
3071 Binder.restoreCallingIdentity(identity);
3072 }
3073 }
3074
3075 @Override
3076 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3078 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003079 final long identity = Binder.clearCallingIdentity();
3080 try {
3081 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003082 return ImsManager.getInstance(mApp,
3083 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003084 } catch (ImsException e) {
3085 throw new IllegalArgumentException(e.getMessage());
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
3088 }
3089 }
3090
Brad Ebinger4c460712018-10-01 10:40:55 -07003091 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3092 int slotId = SubscriptionManager.getSlotIndex(subId);
3093 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3094 throw new IllegalArgumentException("Invalid Subscription Id.");
3095 }
3096 return slotId;
3097 }
3098
Wink Saville36469e72014-06-11 15:17:00 -07003099 /**
3100 * Returns the network type for a subId
3101 */
3102 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003103 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003104 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003105 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003106 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3107 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003108
Malcolm Chend965c8b2018-02-28 15:00:40 -08003109 final long identity = Binder.clearCallingIdentity();
3110 try {
3111 final Phone phone = getPhone(subId);
3112 if (phone != null) {
3113 return phone.getServiceState().getDataNetworkType();
3114 } else {
3115 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3116 }
3117 } finally {
3118 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003120 }
3121
3122 /**
3123 * Returns the data network type
3124 */
3125 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003126 public int getDataNetworkType(String callingPackage) {
3127 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003128 }
3129
3130 /**
3131 * Returns the data network type for a subId
3132 */
3133 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003134 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003135 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003136 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003137 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3138 }
3139
Malcolm Chend965c8b2018-02-28 15:00:40 -08003140 final long identity = Binder.clearCallingIdentity();
3141 try {
3142 final Phone phone = getPhone(subId);
3143 if (phone != null) {
3144 return phone.getServiceState().getDataNetworkType();
3145 } else {
3146 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3147 }
3148 } finally {
3149 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003150 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003151 }
3152
3153 /**
Wink Saville36469e72014-06-11 15:17:00 -07003154 * Returns the Voice network type for a subId
3155 */
3156 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003157 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003159 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003160 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3161 }
3162
Malcolm Chend965c8b2018-02-28 15:00:40 -08003163 final long identity = Binder.clearCallingIdentity();
3164 try {
3165 final Phone phone = getPhone(subId);
3166 if (phone != null) {
3167 return phone.getServiceState().getVoiceNetworkType();
3168 } else {
3169 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3170 }
3171 } finally {
3172 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003173 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003174 }
3175
3176 /**
3177 * @return true if a ICC card is present
3178 */
3179 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003180 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003181 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3182 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003183 }
3184
3185 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003186 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003187 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003188 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003189 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003190 final long identity = Binder.clearCallingIdentity();
3191 try {
3192 final Phone phone = PhoneFactory.getPhone(slotIndex);
3193 if (phone != null) {
3194 return phone.getIccCard().hasIccCard();
3195 } else {
3196 return false;
3197 }
3198 } finally {
3199 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003201 }
3202
3203 /**
3204 * Return if the current radio is LTE on CDMA. This
3205 * is a tri-state return value as for a period of time
3206 * the mode may be unknown.
3207 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003208 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003210 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003212 @Override
3213 public int getLteOnCdmaMode(String callingPackage) {
3214 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003215 }
3216
Sanket Padawe356d7632015-06-22 14:03:32 -07003217 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003218 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003220 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003221 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3222 }
3223
Malcolm Chend965c8b2018-02-28 15:00:40 -08003224 final long identity = Binder.clearCallingIdentity();
3225 try {
3226 final Phone phone = getPhone(subId);
3227 if (phone == null) {
3228 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3229 } else {
3230 return phone.getLteOnCdmaMode();
3231 }
3232 } finally {
3233 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003234 }
Wink Saville36469e72014-06-11 15:17:00 -07003235 }
3236
Wink Saville36469e72014-06-11 15:17:00 -07003237 /**
3238 * {@hide}
3239 * Returns Default subId, 0 in the case of single standby.
3240 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003241 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003242 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003243 }
3244
Shishir Agrawala9f32182016-04-12 12:00:16 -07003245 private int getSlotForDefaultSubscription() {
3246 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3247 }
3248
Wink Savilleb564aae2014-10-23 10:18:09 -07003249 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003250 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003251 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003252
Pengquan Meng466e2482018-09-21 15:54:48 -07003253 private boolean isActiveSubscription(int subId) {
3254 return mSubscriptionController.isActiveSubId(subId);
3255 }
3256
Ihab Awadf2177b72013-11-25 13:33:23 -08003257 /**
3258 * @see android.telephony.TelephonyManager.WifiCallingChoices
3259 */
3260 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003261 final long identity = Binder.clearCallingIdentity();
3262 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003263 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003264 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3265 getWhenToMakeWifiCallsDefaultPreference());
3266 } finally {
3267 Binder.restoreCallingIdentity(identity);
3268 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003269 }
3270
3271 /**
3272 * @see android.telephony.TelephonyManager.WifiCallingChoices
3273 */
3274 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003275 final long identity = Binder.clearCallingIdentity();
3276 try {
3277 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003278 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003279 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3280 } finally {
3281 Binder.restoreCallingIdentity(identity);
3282 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003283 }
3284
Sailesh Nepald1e68152013-12-12 19:08:02 -08003285 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003286 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003287 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003288 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003289
Shishir Agrawal566b7612013-10-28 14:41:00 -07003290 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003291 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3292 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3294 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003295 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003296
Malcolm Chend965c8b2018-02-28 15:00:40 -08003297 final long identity = Binder.clearCallingIdentity();
3298 try {
3299 if (TextUtils.equals(ISDR_AID, aid)) {
3300 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003301 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3302 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003303 if (bestComponent == null
3304 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3305 loge("The calling package is not allowed to access ISD-R.");
3306 throw new SecurityException(
3307 "The calling package is not allowed to access ISD-R.");
3308 }
Derek Tan740e1672017-06-27 14:56:27 -07003309 }
Derek Tan740e1672017-06-27 14:56:27 -07003310
Malcolm Chend965c8b2018-02-28 15:00:40 -08003311 if (DBG) {
3312 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3313 }
3314 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3315 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3316 if (DBG) log("iccOpenLogicalChannel: " + response);
3317 return response;
3318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003321 }
3322
3323 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003324 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3326 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003327
Malcolm Chend965c8b2018-02-28 15:00:40 -08003328 final long identity = Binder.clearCallingIdentity();
3329 try {
3330 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3331 if (channel < 0) {
3332 return false;
3333 }
3334 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3335 if (DBG) log("iccCloseLogicalChannel: " + success);
3336 return success;
3337 } finally {
3338 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003339 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003340 }
3341
3342 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003343 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003344 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3346 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003347
Malcolm Chend965c8b2018-02-28 15:00:40 -08003348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 if (DBG) {
3351 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3352 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3353 + p3 + " data=" + data);
3354 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003355
Malcolm Chend965c8b2018-02-28 15:00:40 -08003356 if (channel < 0) {
3357 return "";
3358 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003359
Malcolm Chend965c8b2018-02-28 15:00:40 -08003360 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3361 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3362 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003363
Malcolm Chend965c8b2018-02-28 15:00:40 -08003364 // Append the returned status code to the end of the response payload.
3365 String s = Integer.toHexString(
3366 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3367 if (response.payload != null) {
3368 s = IccUtils.bytesToHexString(response.payload) + s;
3369 }
3370 return s;
3371 } finally {
3372 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003373 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003374 }
Jake Hambye994d462014-02-03 13:10:13 -08003375
Evan Charltonc66da362014-05-16 14:06:40 -07003376 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003377 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3378 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3380 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003381 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003382
Malcolm Chend965c8b2018-02-28 15:00:40 -08003383 final long identity = Binder.clearCallingIdentity();
3384 try {
3385 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3386 && TextUtils.equals(ISDR_AID, data)) {
3387 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003388 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3389 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003390 if (bestComponent == null
3391 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3392 loge("The calling package is not allowed to select ISD-R.");
3393 throw new SecurityException(
3394 "The calling package is not allowed to select ISD-R.");
3395 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003396 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003397
Malcolm Chend965c8b2018-02-28 15:00:40 -08003398 if (DBG) {
3399 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3400 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3401 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003402
Malcolm Chend965c8b2018-02-28 15:00:40 -08003403 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3404 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3405 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003406
Malcolm Chend965c8b2018-02-28 15:00:40 -08003407 // Append the returned status code to the end of the response payload.
3408 String s = Integer.toHexString(
3409 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3410 if (response.payload != null) {
3411 s = IccUtils.bytesToHexString(response.payload) + s;
3412 }
3413 return s;
3414 } finally {
3415 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003416 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003417 }
3418
3419 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003420 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003421 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3423 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003424
Malcolm Chend965c8b2018-02-28 15:00:40 -08003425 final long identity = Binder.clearCallingIdentity();
3426 try {
3427 if (DBG) {
3428 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3429 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3430 }
3431
3432 IccIoResult response =
3433 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3434 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3435 subId);
3436
3437 if (DBG) {
3438 log("Exchange SIM_IO [R]" + response);
3439 }
3440
3441 byte[] result = null;
3442 int length = 2;
3443 if (response.payload != null) {
3444 length = 2 + response.payload.length;
3445 result = new byte[length];
3446 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3447 } else {
3448 result = new byte[length];
3449 }
3450
3451 result[length - 1] = (byte) response.sw2;
3452 result[length - 2] = (byte) response.sw1;
3453 return result;
3454 } finally {
3455 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003456 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003457 }
3458
Nathan Haroldb3014052017-01-25 15:57:32 -08003459 /**
3460 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3461 * on a particular subscription
3462 */
sqianb6e41952018-03-12 14:54:01 -07003463 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3465 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3466 return null;
3467 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003468
3469 final long identity = Binder.clearCallingIdentity();
3470 try {
3471 if (appType != TelephonyManager.APPTYPE_USIM
3472 && appType != TelephonyManager.APPTYPE_SIM) {
3473 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3474 return null;
3475 }
3476 Object response = sendRequest(
3477 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3478 if (response instanceof String[]) {
3479 return (String[]) response;
3480 }
3481 // Response is an Exception of some kind,
3482 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003483 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003484 } finally {
3485 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003486 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003487 }
3488
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003489 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003490 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3492 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003493
Malcolm Chend965c8b2018-02-28 15:00:40 -08003494 final long identity = Binder.clearCallingIdentity();
3495 try {
3496 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3497 if (response.payload == null) {
3498 return "";
3499 }
Evan Charltonc66da362014-05-16 14:06:40 -07003500
Malcolm Chend965c8b2018-02-28 15:00:40 -08003501 // Append the returned status code to the end of the response payload.
3502 String s = Integer.toHexString(
3503 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3504 s = IccUtils.bytesToHexString(response.payload) + s;
3505 return s;
3506 } finally {
3507 Binder.restoreCallingIdentity(identity);
3508 }
Evan Charltonc66da362014-05-16 14:06:40 -07003509 }
3510
Jake Hambye994d462014-02-03 13:10:13 -08003511 /**
3512 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3513 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3514 *
3515 * @param itemID the ID of the item to read
3516 * @return the NV item as a String, or null on error.
3517 */
3518 @Override
3519 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003520 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3522 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003523
3524 final long identity = Binder.clearCallingIdentity();
3525 try {
3526 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003527 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003528 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3529 return value;
3530 } finally {
3531 Binder.restoreCallingIdentity(identity);
3532 }
Jake Hambye994d462014-02-03 13:10:13 -08003533 }
3534
3535 /**
3536 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3537 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3538 *
3539 * @param itemID the ID of the item to read
3540 * @param itemValue the value to write, as a String
3541 * @return true on success; false on any failure
3542 */
3543 @Override
3544 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003545 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3547 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003548
3549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3552 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003553 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003554 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3555 return success;
3556 } finally {
3557 Binder.restoreCallingIdentity(identity);
3558 }
Jake Hambye994d462014-02-03 13:10:13 -08003559 }
3560
3561 /**
3562 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3563 * Used for device configuration by some CDMA operators.
3564 *
3565 * @param preferredRoamingList byte array containing the new PRL
3566 * @return true on success; false on any failure
3567 */
3568 @Override
3569 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3571 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003572
3573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3576 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3577 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3578 return success;
3579 } finally {
3580 Binder.restoreCallingIdentity(identity);
3581 }
Jake Hambye994d462014-02-03 13:10:13 -08003582 }
3583
3584 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003585 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003586 * Used for device configuration by some CDMA operators.
3587 *
chen xu1cc0abe2018-10-26 17:39:23 -07003588 * @param slotIndex - device slot.
3589 *
Jake Hambye994d462014-02-03 13:10:13 -08003590 * @return true on success; false on any failure
3591 */
3592 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003593 public boolean resetModemConfig(int slotIndex) {
3594 Phone phone = PhoneFactory.getPhone(slotIndex);
3595 if (phone != null) {
3596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3597 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003598
chen xu1cc0abe2018-10-26 17:39:23 -07003599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3602 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3603 return success;
3604 } finally {
3605 Binder.restoreCallingIdentity(identity);
3606 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003607 }
chen xu1cc0abe2018-10-26 17:39:23 -07003608 return false;
3609 }
3610
3611 /**
3612 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3613 *
3614 * @param slotIndex - device slot.
3615 *
3616 * @return true on success; false on any failure
3617 */
3618 @Override
3619 public boolean rebootModem(int slotIndex) {
3620 Phone phone = PhoneFactory.getPhone(slotIndex);
3621 if (phone != null) {
3622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3623 mApp, phone.getSubId(), "rebootModem");
3624
3625 final long identity = Binder.clearCallingIdentity();
3626 try {
3627 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3628 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3629 return success;
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
3632 }
3633 }
3634 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003635 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003636
Svet Ganovb320e182015-04-16 12:30:10 -07003637 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003638 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003639 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003640 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003641 return new String[0];
3642 }
3643
Malcolm Chend965c8b2018-02-28 15:00:40 -08003644 final long identity = Binder.clearCallingIdentity();
3645 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003646 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003647 } finally {
3648 Binder.restoreCallingIdentity(identity);
3649 }
Wink Saville36469e72014-06-11 15:17:00 -07003650 }
3651
Brad Ebinger51f743a2017-01-23 13:50:20 -08003652 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003653 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3654 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003655 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003656 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003657 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003658
3659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 PhoneFactory.getImsResolver().enableIms(slotId);
3662 } finally {
3663 Binder.restoreCallingIdentity(identity);
3664 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003665 }
3666
3667 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003668 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3669 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003670 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003671 public void disableIms(int slotId) {
3672 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003673
3674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 PhoneFactory.getImsResolver().disableIms(slotId);
3677 } finally {
3678 Binder.restoreCallingIdentity(identity);
3679 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003680 }
3681
3682 /**
3683 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3684 * feature or {@link null} if the service is not available. If the feature is available, the
3685 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3686 */
3687 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003688 IImsServiceFeatureCallback callback) {
3689 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003690
3691 final long identity = Binder.clearCallingIdentity();
3692 try {
3693 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3694 } finally {
3695 Binder.restoreCallingIdentity(identity);
3696 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003697 }
3698
3699 /**
3700 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3701 * feature during emergency calling or {@link null} if the service is not available. If the
3702 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3703 * listener for feature updates.
3704 */
3705 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3706 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003707
3708 final long identity = Binder.clearCallingIdentity();
3709 try {
3710 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003714 }
3715
Brad Ebinger5f64b052017-12-14 14:26:15 -08003716 /**
3717 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3718 * specified.
3719 */
3720 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3721 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003722
3723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003729 }
3730
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003731 /**
3732 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3733 * specified.
3734 */
3735 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3736 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003737
3738 final long identity = Binder.clearCallingIdentity();
3739 try {
3740 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3741 } finally {
3742 Binder.restoreCallingIdentity(identity);
3743 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003744 }
3745
Brad Ebinger884c07b2018-02-15 16:17:40 -08003746 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003747 * Sets the ImsService Package Name that Telephony will bind to.
3748 *
3749 * @param slotId the slot ID that the ImsService should bind for.
3750 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3751 * ImsService is the device default ImsService.
3752 * @param packageName The package name of the application that contains the ImsService to bind
3753 * to.
3754 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3755 * @hide
3756 */
3757 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003758 int[] subIds = SubscriptionManager.getSubId(slotId);
3759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3760 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3761 "setImsService");
3762
Malcolm Chend965c8b2018-02-28 15:00:40 -08003763 final long identity = Binder.clearCallingIdentity();
3764 try {
3765 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3766 isCarrierImsService, packageName);
3767 } finally {
3768 Binder.restoreCallingIdentity(identity);
3769 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003770 }
3771
3772 /**
3773 * Return the ImsService configuration.
3774 *
3775 * @param slotId The slot that the ImsService is associated with.
3776 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3777 * the device default.
3778 * @return the package name of the ImsService configuration.
3779 */
3780 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003781 int[] subIds = SubscriptionManager.getSubId(slotId);
3782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3783 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3784 "getImsService");
3785
Malcolm Chend965c8b2018-02-28 15:00:40 -08003786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3789 isCarrierImsService);
3790 } finally {
3791 Binder.restoreCallingIdentity(identity);
3792 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003793 }
3794
Wink Saville36469e72014-06-11 15:17:00 -07003795 public void setImsRegistrationState(boolean registered) {
3796 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003797
3798 final long identity = Binder.clearCallingIdentity();
3799 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003800 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003801 } finally {
3802 Binder.restoreCallingIdentity(identity);
3803 }
Wink Saville36469e72014-06-11 15:17:00 -07003804 }
3805
3806 /**
Stuart Scott54788802015-03-30 13:18:01 -07003807 * Set the network selection mode to automatic.
3808 *
3809 */
3810 @Override
3811 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3813 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003814
Pengquan Meng466e2482018-09-21 15:54:48 -07003815 if (!isActiveSubscription(subId)) {
3816 return;
3817 }
3818
Malcolm Chend965c8b2018-02-28 15:00:40 -08003819 final long identity = Binder.clearCallingIdentity();
3820 try {
3821 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3822 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3823 } finally {
3824 Binder.restoreCallingIdentity(identity);
3825 }
Stuart Scott54788802015-03-30 13:18:01 -07003826 }
3827
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003828 /**
3829 * Ask the radio to connect to the input network and change selection mode to manual.
3830 *
3831 * @param subId the id of the subscription.
3832 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3833 * the operator to attach to.
3834 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3835 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3836 * normal network selection next time.
3837 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003838 */
3839 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003840 public boolean setNetworkSelectionModeManual(
3841 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3843 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003844
3845 if (!isActiveSubscription(subId)) {
3846 return false;
3847 }
3848
Malcolm Chend965c8b2018-02-28 15:00:40 -08003849 final long identity = Binder.clearCallingIdentity();
3850 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003851 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003852 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003853 if (DBG) {
3854 log("setNetworkSelectionModeManual: subId: " + subId
3855 + " operator: " + operatorInfo);
3856 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003857 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3858 } finally {
3859 Binder.restoreCallingIdentity(identity);
3860 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003861 }
3862
3863 /**
3864 * Scans for available networks.
3865 */
3866 @Override
3867 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3869 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003870
Pengquan Meng0c05b502018-09-06 09:59:22 -07003871 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003872 try {
3873 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003874 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003875 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003876 } finally {
3877 Binder.restoreCallingIdentity(identity);
3878 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003879 }
3880
3881 /**
yinxub1bed742017-04-17 11:45:04 -07003882 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003883 *
yinxub1bed742017-04-17 11:45:04 -07003884 * @param subId id of the subscription
3885 * @param request contains the radio access networks with bands/channels to scan
3886 * @param messenger callback messenger for scan results or errors
3887 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003888 * @return the id of the requested scan which can be used to stop the scan.
3889 */
3890 @Override
3891 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3892 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3894 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003895
3896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 return mNetworkScanRequestTracker.startNetworkScan(
3899 request, messenger, binder, getPhone(subId));
3900 } finally {
3901 Binder.restoreCallingIdentity(identity);
3902 }
yinxu504e1392017-04-12 16:03:22 -07003903 }
3904
3905 /**
3906 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003907 *
3908 * @param subId id of the subscription
3909 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003910 */
3911 @Override
3912 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3914 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003915
3916 final long identity = Binder.clearCallingIdentity();
3917 try {
3918 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3919 } finally {
3920 Binder.restoreCallingIdentity(identity);
3921 }
yinxu504e1392017-04-12 16:03:22 -07003922 }
3923
3924 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003925 * Get the calculated preferred network type.
3926 * Used for debugging incorrect network type.
3927 *
3928 * @return the preferred network type, defined in RILConstants.java.
3929 */
3930 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003931 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003932 final Phone defaultPhone = getDefaultPhone();
3933 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
3934 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003935 return RILConstants.PREFERRED_NETWORK_MODE;
3936 }
3937
Malcolm Chend965c8b2018-02-28 15:00:40 -08003938 final long identity = Binder.clearCallingIdentity();
3939 try {
3940 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003941 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003942 } finally {
3943 Binder.restoreCallingIdentity(identity);
3944 }
Junda Liu84d15a22014-07-02 11:21:04 -07003945 }
3946
3947 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003948 * Get the preferred network type.
3949 * Used for device configuration by some CDMA operators.
3950 *
3951 * @return the preferred network type, defined in RILConstants.java.
3952 */
3953 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003954 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3956 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003957
3958 final long identity = Binder.clearCallingIdentity();
3959 try {
3960 if (DBG) log("getPreferredNetworkType");
3961 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3962 int networkType = (result != null ? result[0] : -1);
3963 if (DBG) log("getPreferredNetworkType: " + networkType);
3964 return networkType;
3965 } finally {
3966 Binder.restoreCallingIdentity(identity);
3967 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003968 }
3969
3970 /**
3971 * Set the preferred network type.
3972 * Used for device configuration by some CDMA operators.
3973 *
3974 * @param networkType the preferred network type, defined in RILConstants.java.
3975 * @return true on success; false on any failure.
3976 */
3977 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003978 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3980 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003981
3982 final long identity = Binder.clearCallingIdentity();
3983 try {
3984 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3985 Boolean success = (Boolean) sendRequest(
3986 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3987 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3988 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003989 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003990 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3991 }
3992 return success;
3993 } finally {
3994 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003995 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003996 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003997
3998 /**
Junda Liu475951f2014-11-07 16:45:03 -08003999 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07004000 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004001 * tethering.
4002 *
4003 * @return 0: Not required. 1: required. 2: Not set.
4004 * @hide
4005 */
4006 @Override
4007 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004008 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004009
4010 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004011 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004012 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004013 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004014 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004015 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004016 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004017 dunRequired = 1;
4018 }
4019 return dunRequired;
4020 } finally {
4021 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004022 }
Junda Liu475951f2014-11-07 16:45:03 -08004023 }
4024
4025 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004026 * Set mobile data enabled
4027 * Used by the user through settings etc to turn on/off mobile data
4028 *
4029 * @param enable {@code true} turn turn data on, else {@code false}
4030 */
4031 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004032 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4034 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004035
4036 final long identity = Binder.clearCallingIdentity();
4037 try {
4038 int phoneId = mSubscriptionController.getPhoneId(subId);
4039 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4040 Phone phone = PhoneFactory.getPhone(phoneId);
4041 if (phone != null) {
4042 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004043 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004044 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004045 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004046 }
4047 } finally {
4048 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004049 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004050 }
4051
4052 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004053 * Get the user enabled state of Mobile Data.
4054 *
4055 * TODO: remove and use isUserDataEnabled.
4056 * This can't be removed now because some vendor codes
4057 * calls through ITelephony directly while they should
4058 * use TelephonyManager.
4059 *
4060 * @return true on enabled
4061 */
4062 @Override
4063 public boolean getDataEnabled(int subId) {
4064 return isUserDataEnabled(subId);
4065 }
4066
4067 /**
4068 * Get whether mobile data is enabled per user setting.
4069 *
4070 * There are other factors deciding whether mobile data is actually enabled, but they are
4071 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004072 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004073 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004074 *
4075 * @return {@code true} if data is enabled else {@code false}
4076 */
4077 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004078 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004079 try {
4080 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4081 null);
4082 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4084 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004085 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004086
4087 final long identity = Binder.clearCallingIdentity();
4088 try {
4089 int phoneId = mSubscriptionController.getPhoneId(subId);
4090 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4091 Phone phone = PhoneFactory.getPhone(phoneId);
4092 if (phone != null) {
4093 boolean retVal = phone.isUserDataEnabled();
4094 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4095 return retVal;
4096 } else {
4097 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4098 return false;
4099 }
4100 } finally {
4101 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004102 }
4103 }
4104
4105 /**
4106 * Get whether mobile data is enabled.
4107 *
4108 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4109 * whether mobile data is actually enabled.
4110 *
4111 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4112 *
4113 * @return {@code true} if data is enabled else {@code false}
4114 */
4115 @Override
4116 public boolean isDataEnabled(int subId) {
4117 try {
4118 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4119 null);
4120 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4122 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004123 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004124
4125 final long identity = Binder.clearCallingIdentity();
4126 try {
4127 int phoneId = mSubscriptionController.getPhoneId(subId);
4128 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4129 Phone phone = PhoneFactory.getPhone(phoneId);
4130 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004131 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004132 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4133 return retVal;
4134 } else {
4135 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4136 return false;
4137 }
4138 } finally {
4139 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004140 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004141 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004142
4143 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004144 public int getCarrierPrivilegeStatus(int subId) {
4145 final Phone phone = getPhone(subId);
4146 if (phone == null) {
4147 loge("getCarrierPrivilegeStatus: Invalid subId");
4148 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4149 }
4150 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004151 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004152 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004153 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4154 }
4155 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004156 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004157 }
Junda Liu29340342014-07-10 15:23:27 -07004158
4159 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004160 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4161 final Phone phone = getPhone(subId);
4162 if (phone == null) {
4163 loge("getCarrierPrivilegeStatus: Invalid subId");
4164 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4165 }
4166 UiccProfile profile =
4167 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4168 if (profile == null) {
4169 loge("getCarrierPrivilegeStatus: No UICC");
4170 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4171 }
4172 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4173 }
4174
4175 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004176 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004177 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004178 if (TextUtils.isEmpty(pkgName))
4179 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004180 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004181 if (card == null) {
4182 loge("checkCarrierPrivilegesForPackage: No UICC");
4183 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4184 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004185 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4186 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004187 }
4188
4189 @Override
4190 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004191 if (TextUtils.isEmpty(pkgName))
4192 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004193 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4194 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4195 UiccCard card = UiccController.getInstance().getUiccCard(i);
4196 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004197 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004198 continue;
4199 }
4200
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004201 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004202 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4203 break;
4204 }
4205 }
4206
4207 return result;
Junda Liu29340342014-07-10 15:23:27 -07004208 }
Derek Tan89e89d42014-07-08 17:00:10 -07004209
4210 @Override
Junda Liue64de782015-04-16 17:19:16 -07004211 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4212 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4213 loge("phoneId " + phoneId + " is not valid.");
4214 return null;
4215 }
4216 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004217 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004218 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004219 return null ;
4220 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004221 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004222 }
4223
Amith Yamasani6e118872016-02-19 12:53:51 -08004224 @Override
4225 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004226 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004227 List<String> privilegedPackages = new ArrayList<>();
4228 List<PackageInfo> packages = null;
4229 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4230 UiccCard card = UiccController.getInstance().getUiccCard(i);
4231 if (card == null) {
4232 // No UICC in that slot.
4233 continue;
4234 }
4235 if (card.hasCarrierPrivilegeRules()) {
4236 if (packages == null) {
4237 // Only check packages in user 0 for now
4238 packages = pm.getInstalledPackagesAsUser(
4239 PackageManager.MATCH_DISABLED_COMPONENTS
4240 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4241 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4242 }
4243 for (int p = packages.size() - 1; p >= 0; p--) {
4244 PackageInfo pkgInfo = packages.get(p);
4245 if (pkgInfo != null && pkgInfo.packageName != null
4246 && card.getCarrierPrivilegeStatus(pkgInfo)
4247 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4248 privilegedPackages.add(pkgInfo.packageName);
4249 }
4250 }
4251 }
4252 }
4253 return privilegedPackages;
4254 }
4255
Wink Savilleb564aae2014-10-23 10:18:09 -07004256 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004257 final Phone phone = getPhone(subId);
4258 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004259 if (card == null) {
4260 loge("getIccId: No UICC");
4261 return null;
4262 }
4263 String iccId = card.getIccId();
4264 if (TextUtils.isEmpty(iccId)) {
4265 loge("getIccId: ICC ID is null or empty.");
4266 return null;
4267 }
4268 return iccId;
4269 }
4270
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004271 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004272 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4273 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004274 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4275 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004276
Malcolm Chend965c8b2018-02-28 15:00:40 -08004277 final long identity = Binder.clearCallingIdentity();
4278 try {
4279 final String iccId = getIccId(subId);
4280 final Phone phone = getPhone(subId);
4281 if (phone == null) {
4282 return false;
4283 }
4284 final String subscriberId = phone.getSubscriberId();
4285
4286 if (DBG_MERGE) {
4287 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4288 + subscriberId + " to " + number);
4289 }
4290
4291 if (TextUtils.isEmpty(iccId)) {
4292 return false;
4293 }
4294
4295 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4296
4297 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4298 if (alphaTag == null) {
4299 editor.remove(alphaTagPrefKey);
4300 } else {
4301 editor.putString(alphaTagPrefKey, alphaTag);
4302 }
4303
4304 // Record both the line number and IMSI for this ICCID, since we need to
4305 // track all merged IMSIs based on line number
4306 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4307 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4308 if (number == null) {
4309 editor.remove(numberPrefKey);
4310 editor.remove(subscriberPrefKey);
4311 } else {
4312 editor.putString(numberPrefKey, number);
4313 editor.putString(subscriberPrefKey, subscriberId);
4314 }
4315
4316 editor.commit();
4317 return true;
4318 } finally {
4319 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004320 }
Derek Tan7226c842014-07-02 17:42:23 -07004321 }
4322
4323 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004324 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004325 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004327 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004328 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004329 return null;
4330 }
Derek Tan97ebb422014-09-05 16:55:38 -07004331
Malcolm Chend965c8b2018-02-28 15:00:40 -08004332 final long identity = Binder.clearCallingIdentity();
4333 try {
4334 String iccId = getIccId(subId);
4335 if (iccId != null) {
4336 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4337 if (DBG_MERGE) {
4338 log("getLine1NumberForDisplay returning "
4339 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4340 }
4341 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004342 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004343 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4344 return null;
4345 } finally {
4346 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004347 }
Derek Tan7226c842014-07-02 17:42:23 -07004348 }
4349
4350 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004351 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004353 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004354 return null;
4355 }
Derek Tan97ebb422014-09-05 16:55:38 -07004356
Malcolm Chend965c8b2018-02-28 15:00:40 -08004357 final long identity = Binder.clearCallingIdentity();
4358 try {
4359 String iccId = getIccId(subId);
4360 if (iccId != null) {
4361 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4362 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4363 }
4364 return null;
4365 } finally {
4366 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004367 }
Derek Tan7226c842014-07-02 17:42:23 -07004368 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004369
4370 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004371 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004372 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4373 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004375 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4376 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004377 return null;
4378 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004379
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004380 final long identity = Binder.clearCallingIdentity();
4381 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004382 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004383 final TelephonyManager tele = TelephonyManager.from(context);
4384 final SubscriptionManager sub = SubscriptionManager.from(context);
4385
4386 // Figure out what subscribers are currently active
4387 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4388 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4389 // the process, where TelephonyManager was instantiated.
4390 // Otherwise AppOps check will fail.
4391
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004392 final int[] subIds = sub.getActiveSubscriptionIdList();
4393 for (int subId : subIds) {
4394 activeSubscriberIds.add(tele.getSubscriberId(subId));
4395 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004396
4397 // First pass, find a number override for an active subscriber
4398 String mergeNumber = null;
4399 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4400 for (String key : prefs.keySet()) {
4401 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4402 final String subscriberId = (String) prefs.get(key);
4403 if (activeSubscriberIds.contains(subscriberId)) {
4404 final String iccId = key.substring(
4405 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4406 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4407 mergeNumber = (String) prefs.get(numberKey);
4408 if (DBG_MERGE) {
4409 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4410 + " for active subscriber " + subscriberId);
4411 }
4412 if (!TextUtils.isEmpty(mergeNumber)) {
4413 break;
4414 }
4415 }
4416 }
4417 }
4418
4419 // Shortcut when no active merged subscribers
4420 if (TextUtils.isEmpty(mergeNumber)) {
4421 return null;
4422 }
4423
4424 // Second pass, find all subscribers under that line override
4425 final ArraySet<String> result = new ArraySet<>();
4426 for (String key : prefs.keySet()) {
4427 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4428 final String number = (String) prefs.get(key);
4429 if (mergeNumber.equals(number)) {
4430 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4431 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4432 final String subscriberId = (String) prefs.get(subscriberKey);
4433 if (!TextUtils.isEmpty(subscriberId)) {
4434 result.add(subscriberId);
4435 }
4436 }
4437 }
4438 }
4439
4440 final String[] resultArray = result.toArray(new String[result.size()]);
4441 Arrays.sort(resultArray);
4442 if (DBG_MERGE) {
4443 Slog.d(LOG_TAG,
4444 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4445 }
4446 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004447 } finally {
4448 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004449 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004450 }
4451
4452 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004453 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004454 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4455 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004456
4457 final long identity = Binder.clearCallingIdentity();
4458 try {
4459 final Phone phone = getPhone(subId);
4460 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4461 } finally {
4462 Binder.restoreCallingIdentity(identity);
4463 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004464 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004465
4466 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004467 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004468 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4469 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004470 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004471
4472 final long identity = Binder.clearCallingIdentity();
4473 try {
4474 final Phone phone = getPhone(subId);
4475 if (phone == null) {
4476 return false;
4477 }
4478 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4479 cdmaNonRoamingList);
4480 } finally {
4481 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004482 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004483 }
4484
4485 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004486 @Deprecated
4487 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4488 enforceModifyPermission();
4489
4490 int returnValue = 0;
4491 try {
vagdevie435a3e2018-08-15 16:01:53 -07004492 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004493 if(result.exception == null) {
4494 if (result.result != null) {
4495 byte[] responseData = (byte[])(result.result);
4496 if(responseData.length > oemResp.length) {
4497 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4498 responseData.length + "bytes. Buffer Size is " +
4499 oemResp.length + "bytes.");
4500 }
4501 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4502 returnValue = responseData.length;
4503 }
4504 } else {
4505 CommandException ex = (CommandException) result.exception;
4506 returnValue = ex.getCommandError().ordinal();
4507 if(returnValue > 0) returnValue *= -1;
4508 }
4509 } catch (RuntimeException e) {
4510 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4511 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4512 if(returnValue > 0) returnValue *= -1;
4513 }
4514
4515 return returnValue;
4516 }
4517
4518 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004519 public void setRadioCapability(RadioAccessFamily[] rafs) {
4520 try {
4521 ProxyController.getInstance().setRadioCapability(rafs);
4522 } catch (RuntimeException e) {
4523 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4524 }
4525 }
4526
4527 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004528 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004529 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004530 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004531 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004532 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004533 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004534 final long identity = Binder.clearCallingIdentity();
4535 try {
chen xufeeed752018-10-26 14:17:57 -07004536 TelephonyPermissions
4537 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4538 mApp, phone.getSubId(), "getRadioAccessFamily");
4539 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004540 } finally {
4541 Binder.restoreCallingIdentity(identity);
4542 }
chen xufeeed752018-10-26 14:17:57 -07004543 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004544 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004545
4546 @Override
4547 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004548 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004549 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004550
4551 final long identity = Binder.clearCallingIdentity();
4552 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004553 ImsManager.getInstance(defaultPhone.getContext(),
4554 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004555 } finally {
4556 Binder.restoreCallingIdentity(identity);
4557 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004558 }
4559
4560 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004561 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004562 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004563 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004564 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004565 return false;
4566 }
Svet Ganovb320e182015-04-16 12:30:10 -07004567
Malcolm Chend965c8b2018-02-28 15:00:40 -08004568 final long identity = Binder.clearCallingIdentity();
4569 try {
4570 // Check the user preference and the system-level IMS setting. Even if the user has
4571 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4572 // In the long run, we may instead need to check if there exists a connection service
4573 // which can support video calling.
4574 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004575 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004576 return imsManager.isVtEnabledByPlatform()
4577 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4578 && imsManager.isVtEnabledByUser();
4579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004582 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004583
Andrew Leea1239f22015-03-02 17:44:07 -08004584 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004585 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4587 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4588 return false;
4589 }
4590
4591 final long identity = Binder.clearCallingIdentity();
4592 try {
4593 CarrierConfigManager configManager =
4594 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004595 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004596 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
Andrew Leea1239f22015-03-02 17:44:07 -08004600 }
4601
4602 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004603 public boolean isWorldPhone(int subId, String callingPackage) {
4604 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4605 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4606 return false;
4607 }
4608
4609 final long identity = Binder.clearCallingIdentity();
4610 try {
4611 CarrierConfigManager configManager =
4612 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004613 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004614 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4615 } finally {
4616 Binder.restoreCallingIdentity(identity);
4617 }
Andrew Leea1239f22015-03-02 17:44:07 -08004618 }
4619
Andrew Lee9431b832015-03-09 18:46:45 -07004620 @Override
4621 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004622 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004623 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004624 }
4625
4626 @Override
4627 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004628 final long identity = Binder.clearCallingIdentity();
4629 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004630 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004631 } finally {
4632 Binder.restoreCallingIdentity(identity);
4633 }
Andrew Lee9431b832015-03-09 18:46:45 -07004634 }
4635
Hall Liuf6668912018-10-31 17:05:23 -07004636 /**
4637 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4638 * support for the feature and device firmware support.
4639 *
4640 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4641 */
4642 @Override
4643 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004644 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004645 final Phone phone = getPhone(subscriptionId);
4646 if (phone == null) {
4647 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4648 return false;
4649 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004650 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004651 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004652 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4653 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004654 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004655 return isCarrierSupported && isDeviceSupported;
4656 } finally {
4657 Binder.restoreCallingIdentity(identity);
4658 }
Hall Liu98187582018-01-22 19:15:32 -08004659 }
4660
Hall Liuf6668912018-10-31 17:05:23 -07004661 /**
4662 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4663 * both also support RTT.
4664 */
4665 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004666 final long identity = Binder.clearCallingIdentity();
4667 try {
Hall Liuf6668912018-10-31 17:05:23 -07004668 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004669 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004670 } finally {
4671 Binder.restoreCallingIdentity(identity);
4672 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004673 }
4674
Sanket Padawe7310cc72015-01-14 09:53:20 -08004675 /**
4676 * Returns the unique device ID of phone, for example, the IMEI for
4677 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4678 *
4679 * <p>Requires Permission:
4680 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4681 */
4682 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004683 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004684 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004685 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004686 return null;
4687 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004688 int subId = phone.getSubId();
4689 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4690 mApp, subId, callingPackage, "getDeviceId")) {
4691 return null;
4692 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004693
4694 final long identity = Binder.clearCallingIdentity();
4695 try {
4696 return phone.getDeviceId();
4697 } finally {
4698 Binder.restoreCallingIdentity(identity);
4699 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004700 }
4701
Ping Sunc67b7c22016-03-02 19:16:45 +08004702 /**
4703 * {@hide}
4704 * Returns the IMS Registration Status on a particular subid
4705 *
4706 * @param subId
4707 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004708 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004709 Phone phone = getPhone(subId);
4710 if (phone != null) {
4711 return phone.isImsRegistered();
4712 } else {
4713 return false;
4714 }
4715 }
4716
Santos Cordon7a1885b2015-02-03 11:15:19 -08004717 @Override
4718 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004719 final long identity = Binder.clearCallingIdentity();
4720 try {
4721 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4722 } finally {
4723 Binder.restoreCallingIdentity(identity);
4724 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004725 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004726
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004727 /**
4728 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004729 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004730 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004731 final long identity = Binder.clearCallingIdentity();
4732 try {
4733 Phone phone = getPhone(subId);
4734 if (phone != null) {
4735 return phone.isWifiCallingEnabled();
4736 } else {
4737 return false;
4738 }
4739 } finally {
4740 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004741 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004742 }
4743
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004744 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004745 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004746 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004747 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004748 final long identity = Binder.clearCallingIdentity();
4749 try {
4750 Phone phone = getPhone(subId);
4751 if (phone != null) {
4752 return phone.isVideoEnabled();
4753 } else {
4754 return false;
4755 }
4756 } finally {
4757 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004758 }
4759 }
4760
4761 /**
4762 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4763 * defined in {@link ImsRegistrationImplBase}.
4764 */
4765 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004766 final long identity = Binder.clearCallingIdentity();
4767 try {
4768 Phone phone = getPhone(subId);
4769 if (phone != null) {
4770 return phone.getImsRegistrationTech();
4771 } else {
4772 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4773 }
4774 } finally {
4775 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004776 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004777 }
4778
Stuart Scott8eef64f2015-04-08 15:13:54 -07004779 @Override
4780 public void factoryReset(int subId) {
4781 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004782 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4783 return;
4784 }
4785
Svet Ganovcc087f82015-05-12 20:35:54 -07004786 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004787
Svet Ganovcc087f82015-05-12 20:35:54 -07004788 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004789 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4790 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004791 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004792 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004793 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004794 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
4795 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07004796 }
4797 } finally {
4798 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004799 }
4800 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004801
4802 @Override
4803 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004804 final long identity = Binder.clearCallingIdentity();
4805 try {
4806 // We query all subscriptions instead of just the active ones, because
4807 // this might be called early on in the provisioning flow when the
4808 // subscriptions potentially aren't active yet.
4809 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4810 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004811 return null;
4812 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004813
Malcolm Chend965c8b2018-02-28 15:00:40 -08004814 // This function may be called very early, say, from the setup wizard, at
4815 // which point we won't have a default subscription set. If that's the case
4816 // we just choose the first, which will be valid in "most cases".
4817 final int defaultSubId = getDefaultSubscription();
4818 SubscriptionInfo info = null;
4819 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4820 info = slist.get(0);
4821 } else {
4822 for (SubscriptionInfo item : slist) {
4823 if (item.getSubscriptionId() == defaultSubId) {
4824 info = item;
4825 break;
4826 }
4827 }
4828
4829 if (info == null) {
4830 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004831 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004832 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004833
Malcolm Chend965c8b2018-02-28 15:00:40 -08004834 // Try and fetch the locale from the carrier properties or from the SIM language
4835 // preferences (EF-PL and EF-LI)...
4836 final int mcc = info.getMcc();
4837 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4838 String simLanguage = null;
4839 if (defaultPhone != null) {
4840 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4841 if (localeFromDefaultSim != null) {
4842 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4843 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4844 return localeFromDefaultSim.toLanguageTag();
4845 } else {
4846 simLanguage = localeFromDefaultSim.getLanguage();
4847 }
4848 }
4849 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004850
Malcolm Chend965c8b2018-02-28 15:00:40 -08004851 // The SIM language preferences only store a language (e.g. fr = French), not an
4852 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4853 // the SIM and carrier preferences does not include a country we add the country
4854 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004855 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004856 if (mccLocale != null) {
4857 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4858 return mccLocale.toLanguageTag();
4859 }
4860
4861 if (DBG) log("No locale found - returning null");
4862 return null;
4863 } finally {
4864 Binder.restoreCallingIdentity(identity);
4865 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004866 }
4867
4868 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004869 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004870 }
4871
Malcolm Chend965c8b2018-02-28 15:00:40 -08004872 /**
4873 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4874 */
4875 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004876 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004877 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004878
Chenjie Yu1ba97252018-01-11 18:16:20 -08004879 private final ModemActivityInfo mLastModemActivityInfo =
4880 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4881
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004882 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004883 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4884 * representing the state of the modem.
4885 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004886 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4887 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004888 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004889 */
4890 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004891 public void requestModemActivityInfo(ResultReceiver result) {
4892 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004893 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004894
4895 final long identity = Binder.clearCallingIdentity();
4896 try {
4897 ModemActivityInfo ret = null;
4898 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004899 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4900 CMD_GET_MODEM_ACTIVITY_INFO,
4901 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004902 if (isModemActivityInfoValid(info)) {
4903 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4904 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4905 mergedTxTimeMs[i] =
4906 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4907 }
4908 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4909 mLastModemActivityInfo.setSleepTimeMillis(
4910 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4911 mLastModemActivityInfo.setIdleTimeMillis(
4912 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4913 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4914 mLastModemActivityInfo.setRxTimeMillis(
4915 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4916 mLastModemActivityInfo.setEnergyUsed(
4917 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004918 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004919 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4920 mLastModemActivityInfo.getSleepTimeMillis(),
4921 mLastModemActivityInfo.getIdleTimeMillis(),
4922 mLastModemActivityInfo.getTxTimeMillis(),
4923 mLastModemActivityInfo.getRxTimeMillis(),
4924 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004925 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004926 Bundle bundle = new Bundle();
4927 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4928 result.send(0, bundle);
4929 } finally {
4930 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004931 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004932 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004933
Siddharth Rayf5d29552018-06-17 15:02:38 -07004934 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4935 // less than total activity duration.
4936 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4937 if (info == null) {
4938 return false;
4939 }
4940 int activityDurationMs =
4941 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4942 int totalTxTimeMs = 0;
4943 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4944 totalTxTimeMs += info.getTxTimeMillis()[i];
4945 }
4946 return (info.isValid()
4947 && (info.getSleepTimeMillis() <= activityDurationMs)
4948 && (info.getIdleTimeMillis() <= activityDurationMs)
4949 && (info.getRxTimeMillis() <= activityDurationMs)
4950 && (totalTxTimeMs <= activityDurationMs));
4951 }
4952
Jack Yu85bd38a2015-11-09 11:34:32 -08004953 /**
4954 * {@hide}
4955 * Returns the service state information on specified subscription.
4956 */
4957 @Override
4958 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004959 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004960 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004961 return null;
4962 }
4963
Malcolm Chend965c8b2018-02-28 15:00:40 -08004964 final long identity = Binder.clearCallingIdentity();
4965 try {
4966 final Phone phone = getPhone(subId);
4967 if (phone == null) {
4968 return null;
4969 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004970
Malcolm Chend965c8b2018-02-28 15:00:40 -08004971 return phone.getServiceState();
4972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004975 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004976
4977 /**
4978 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4979 *
4980 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4981 * voicemail ringtone.
4982 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4983 * PhoneAccount.
4984 */
4985 @Override
4986 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004987 final long identity = Binder.clearCallingIdentity();
4988 try {
4989 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4990 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004991 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004992 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004993
Malcolm Chend965c8b2018-02-28 15:00:40 -08004994 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4995 } finally {
4996 Binder.restoreCallingIdentity(identity);
4997 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004998 }
4999
5000 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005001 * Sets the per-account voicemail ringtone.
5002 *
5003 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5004 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5005 *
5006 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5007 * voicemail ringtone.
5008 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5009 * PhoneAccount.
5010 */
5011 @Override
5012 public void setVoicemailRingtoneUri(String callingPackage,
5013 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005014 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5016 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005017 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5019 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5020 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005021 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005022
5023 final long identity = Binder.clearCallingIdentity();
5024 try {
5025 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5026 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005027 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005028 }
5029 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5030 } finally {
5031 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005032 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005033 }
5034
5035 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005036 * Returns whether vibration is set for voicemail notification in Phone settings.
5037 *
5038 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5039 * voicemail vibration setting.
5040 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5041 */
5042 @Override
5043 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5047 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005048 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005049 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005050
Malcolm Chend965c8b2018-02-28 15:00:40 -08005051 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5052 } finally {
5053 Binder.restoreCallingIdentity(identity);
5054 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005055 }
5056
Youhan Wange64578a2016-05-02 15:32:42 -07005057 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005058 * Sets the per-account voicemail vibration.
5059 *
5060 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5061 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5062 *
5063 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5064 * voicemail vibration setting.
5065 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5066 * specific PhoneAccount.
5067 */
5068 @Override
5069 public void setVoicemailVibrationEnabled(String callingPackage,
5070 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005071 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005072 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5073 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005074 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5076 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5077 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005078 }
5079
Malcolm Chend965c8b2018-02-28 15:00:40 -08005080 final long identity = Binder.clearCallingIdentity();
5081 try {
5082 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5083 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005084 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005085 }
5086 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005089 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005090 }
5091
5092 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005093 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5094 *
5095 * @throws SecurityException if the caller does not have the required permission
5096 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005097 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005098 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005099 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005100 }
5101
5102 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005103 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5104 * permission.
5105 *
5106 * @throws SecurityException if the caller does not have the required permission
5107 */
5108 private void enforceSendSmsPermission() {
5109 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5110 }
5111
5112 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005113 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005114 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005115 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005116 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005117 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005118 final long identity = Binder.clearCallingIdentity();
5119 try {
5120 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005121 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005122 if (componentName == null) {
5123 throw new SecurityException(
5124 "Caller not current active visual voicemail package[null]");
5125 }
5126 String vvmPackage = componentName.getPackageName();
5127 if (!callingPackage.equals(vvmPackage)) {
5128 throw new SecurityException("Caller not current active visual voicemail package["
5129 + vvmPackage + "]");
5130 }
5131 } finally {
5132 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005133 }
5134 }
5135
5136 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005137 * Return the application ID for the app type.
5138 *
5139 * @param subId the subscription ID that this request applies to.
5140 * @param appType the uicc app type.
5141 * @return Application ID for specificied app type, or null if no uicc.
5142 */
5143 @Override
5144 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005145 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005146 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005147
5148 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005149 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005150 if (phone == null) {
5151 return null;
5152 }
5153 String aid = null;
5154 try {
5155 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5156 .getApplicationByType(appType).getAid();
5157 } catch (Exception e) {
5158 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5159 }
5160 return aid;
5161 } finally {
5162 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005163 }
Youhan Wange64578a2016-05-02 15:32:42 -07005164 }
5165
Youhan Wang4001d252016-05-11 10:29:41 -07005166 /**
5167 * Return the Electronic Serial Number.
5168 *
5169 * @param subId the subscription ID that this request applies to.
5170 * @return ESN or null if error.
5171 */
5172 @Override
5173 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005174 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005175 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005176
5177 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005178 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005179 if (phone == null) {
5180 return null;
5181 }
5182 String esn = null;
5183 try {
5184 esn = phone.getEsn();
5185 } catch (Exception e) {
5186 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5187 }
5188 return esn;
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005191 }
Youhan Wang4001d252016-05-11 10:29:41 -07005192 }
5193
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005194 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005195 * Return the Preferred Roaming List Version.
5196 *
5197 * @param subId the subscription ID that this request applies to.
5198 * @return PRLVersion or null if error.
5199 */
5200 @Override
5201 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005202 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005203 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005204
5205 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005206 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005207 if (phone == null) {
5208 return null;
5209 }
5210 String cdmaPrlVersion = null;
5211 try {
5212 cdmaPrlVersion = phone.getCdmaPrlVersion();
5213 } catch (Exception e) {
5214 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5215 }
5216 return cdmaPrlVersion;
5217 } finally {
5218 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005219 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005220 }
5221
5222 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005223 * Get snapshot of Telephony histograms
5224 * @return List of Telephony histograms
5225 * @hide
5226 */
5227 @Override
5228 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5230 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005231
5232 final long identity = Binder.clearCallingIdentity();
5233 try {
5234 return RIL.getTelephonyRILTimingHistograms();
5235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005238 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005239
5240 /**
5241 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005242 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005243 * Require system privileges. In the future we may add this to carrier APIs.
5244 *
5245 * @return The number of carriers set successfully, should match length of carriers
5246 */
5247 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005248 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005249 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005250 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005251
Meng Wang9b7c4e92017-02-17 11:41:27 -08005252 if (carriers == null) {
5253 throw new NullPointerException("carriers cannot be null");
5254 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005255
Malcolm Chend965c8b2018-02-28 15:00:40 -08005256 final long identity = Binder.clearCallingIdentity();
5257 try {
Michele85121de2018-12-19 15:25:20 -08005258 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5259 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdevie435a3e2018-08-15 16:01:53 -07005260 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5261 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005262 return retVal[0];
5263 } finally {
5264 Binder.restoreCallingIdentity(identity);
5265 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005266 }
5267
5268 /**
5269 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005270 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005271 * Require system privileges. In the future we may add this to carrier APIs.
5272 *
5273 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5274 * means all carriers are allowed.
5275 */
5276 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005277 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005278 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005279 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005280
5281 final long identity = Binder.clearCallingIdentity();
5282 try {
Michele85121de2018-12-19 15:25:20 -08005283 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5284 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdevie435a3e2018-08-15 16:01:53 -07005285 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5286 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005287 } finally {
5288 Binder.restoreCallingIdentity(identity);
5289 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005290 }
5291
fionaxu59545b42016-05-25 15:53:37 -07005292 /**
5293 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5294 * @param subId the subscription ID that this action applies to.
5295 * @param enabled control enable or disable metered apns.
5296 * {@hide}
5297 */
5298 @Override
5299 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5300 enforceModifyPermission();
5301 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005302
5303 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005304 if (phone == null) {
5305 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5306 return;
5307 }
5308 try {
5309 phone.carrierActionSetMeteredApnsEnabled(enabled);
5310 } catch (Exception e) {
5311 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005312 } finally {
5313 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005314 }
5315 }
5316
5317 /**
5318 * Action set from carrier signalling broadcast receivers to enable/disable radio
5319 * @param subId the subscription ID that this action applies to.
5320 * @param enabled control enable or disable radio.
5321 * {@hide}
5322 */
5323 @Override
5324 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5325 enforceModifyPermission();
5326 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005327
5328 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005329 if (phone == null) {
5330 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5331 return;
5332 }
5333 try {
5334 phone.carrierActionSetRadioEnabled(enabled);
5335 } catch (Exception e) {
5336 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005337 } finally {
5338 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005339 }
5340 }
5341
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005342 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005343 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5344 * network status based on which carrier apps could apply actions accordingly,
5345 * enable/disable default url handler for example.
5346 *
5347 * @param subId the subscription ID that this action applies to.
5348 * @param report control start/stop reporting the default network status.
5349 * {@hide}
5350 */
5351 @Override
5352 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5353 enforceModifyPermission();
5354 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005355
5356 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005357 if (phone == null) {
5358 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5359 return;
5360 }
5361 try {
5362 phone.carrierActionReportDefaultNetworkStatus(report);
5363 } catch (Exception e) {
5364 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005365 } finally {
5366 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005367 }
5368 }
5369
5370 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005371 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5372 * bug report is being generated.
5373 */
5374 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005375 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005376 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5377 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005378 writer.println("Permission Denial: can't dump Phone from pid="
5379 + Binder.getCallingPid()
5380 + ", uid=" + Binder.getCallingUid()
5381 + "without permission "
5382 + android.Manifest.permission.DUMP);
5383 return;
5384 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005385 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005386 }
Jack Yueb89b242016-06-22 13:27:47 -07005387
Brad Ebingerdac2f002018-04-03 15:17:52 -07005388 @Override
5389 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5390 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5391 throws RemoteException {
5392 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5393 }
5394
Jack Yueb89b242016-06-22 13:27:47 -07005395 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005396 * Get aggregated video call data usage since boot.
5397 *
5398 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5399 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005400 * {@hide}
5401 */
5402 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005403 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005404 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5405 null);
5406
Malcolm Chend965c8b2018-02-28 15:00:40 -08005407 final long identity = Binder.clearCallingIdentity();
5408 try {
5409 // NetworkStatsService keeps tracking the active network interface and identity. It
5410 // records the delta with the corresponding network identity.
5411 // We just return the total video call data usage snapshot since boot.
5412 Phone phone = getPhone(subId);
5413 if (phone != null) {
5414 return phone.getVtDataUsage(perUidStats);
5415 }
5416 return null;
5417 } finally {
5418 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005419 }
Jack Yueb89b242016-06-22 13:27:47 -07005420 }
Jack Yu75ab2952016-07-08 14:29:33 -07005421
5422 /**
5423 * Policy control of data connection. Usually used when data limit is passed.
5424 * @param enabled True if enabling the data, otherwise disabling.
5425 * @param subId Subscription index
5426 * {@hide}
5427 */
5428 @Override
5429 public void setPolicyDataEnabled(boolean enabled, int subId) {
5430 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005431
5432 final long identity = Binder.clearCallingIdentity();
5433 try {
5434 Phone phone = getPhone(subId);
5435 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005436 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005437 }
5438 } finally {
5439 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005440 }
5441 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005442
5443 /**
5444 * Get Client request stats
5445 * @return List of Client Request Stats
5446 * @hide
5447 */
5448 @Override
5449 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005450 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005451 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005452 return null;
5453 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005454 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005455
Malcolm Chend965c8b2018-02-28 15:00:40 -08005456 final long identity = Binder.clearCallingIdentity();
5457 try {
5458 if (phone != null) {
5459 return phone.getClientRequestStats();
5460 }
5461
5462 return null;
5463 } finally {
5464 Binder.restoreCallingIdentity(identity);
5465 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005466 }
5467
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005468 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005469 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005470 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005471 }
Jack Yueb4124c2017-02-16 15:32:43 -08005472
5473 /**
Grace Chen70990072017-03-24 17:21:30 -07005474 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005475 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005476 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005477 * @param state State of SIM (power down, power up, pass through)
5478 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5479 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5480 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005481 *
5482 **/
5483 @Override
Grace Chen70990072017-03-24 17:21:30 -07005484 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005485 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005486 Phone phone = PhoneFactory.getPhone(slotIndex);
5487
vagdevie435a3e2018-08-15 16:01:53 -07005488 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5489
Malcolm Chend965c8b2018-02-28 15:00:40 -08005490 final long identity = Binder.clearCallingIdentity();
5491 try {
5492 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005493 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005494 }
5495 } finally {
5496 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005497 }
5498 }
Shuo Qiandd210312017-04-12 22:11:33 +00005499
Tyler Gunn65d45c22017-06-05 11:22:26 -07005500 private boolean isUssdApiAllowed(int subId) {
5501 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005502 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005503 if (configManager == null) {
5504 return false;
5505 }
5506 PersistableBundle pb = configManager.getConfigForSubId(subId);
5507 if (pb == null) {
5508 return false;
5509 }
5510 return pb.getBoolean(
5511 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5512 }
5513
Shuo Qiandd210312017-04-12 22:11:33 +00005514 /**
5515 * Check if phone is in emergency callback mode
5516 * @return true if phone is in emergency callback mode
5517 * @param subId sub id
5518 */
goneil9c5f4872017-12-05 14:07:56 -08005519 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005520 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005521 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005522 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005523
5524 final long identity = Binder.clearCallingIdentity();
5525 try {
5526 if (phone != null) {
5527 return phone.isInEcm();
5528 } else {
5529 return false;
5530 }
5531 } finally {
5532 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005533 }
5534 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005535
5536 /**
5537 * Get the current signal strength information for the given subscription.
5538 * Because this information is not updated when the device is in a low power state
5539 * it should not be relied-upon to be current.
5540 * @param subId Subscription index
5541 * @return the most recent cached signal strength info from the modem
5542 */
5543 @Override
5544 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005545 final long identity = Binder.clearCallingIdentity();
5546 try {
5547 Phone p = getPhone(subId);
5548 if (p == null) {
5549 return null;
5550 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005551
Malcolm Chend965c8b2018-02-28 15:00:40 -08005552 return p.getSignalStrength();
5553 } finally {
5554 Binder.restoreCallingIdentity(identity);
5555 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005556 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005557
Pengquan Meng9140aec2018-08-22 14:49:57 -07005558 /**
chen xu907e5a22018-10-11 13:21:04 -07005559 * Get the current modem radio state for the given slot.
5560 * @param slotIndex slot index.
5561 * @param callingPackage the name of the package making the call.
5562 * @return the current radio power state from the modem
5563 */
5564 @Override
5565 public int getRadioPowerState(int slotIndex, String callingPackage) {
5566 Phone phone = PhoneFactory.getPhone(slotIndex);
5567 if (phone != null) {
5568 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5569 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5570 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5571 }
5572
5573 final long identity = Binder.clearCallingIdentity();
5574 try {
5575 return phone.getRadioPowerState();
5576 } finally {
5577 Binder.restoreCallingIdentity(identity);
5578 }
5579 }
5580 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5581 }
5582
5583 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005584 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5585 *
5586 * <p>Requires one of the following permissions:
5587 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5588 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5589 * privileges.
5590 *
5591 * @param subId subscription id
5592 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5593 * {@code false}.
5594 */
5595 @Override
5596 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005597 boolean isEnabled = false;
5598 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005599 try {
5600 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005601 null /* message */);
5602 Phone phone = getPhone(subId);
5603 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005604 } catch (Exception e) {
5605 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5606 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005607 } finally {
5608 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005609 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005610 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005611 }
5612
5613
5614 /**
5615 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5616 *
5617 * <p> Requires permission:
5618 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5619 * privileges.
5620 *
5621 * @param subId subscription id
5622 * @param isEnabled {@code true} means enable, {@code false} means disable.
5623 */
5624 @Override
5625 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005626 final long identity = Binder.clearCallingIdentity();
5627 try {
5628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5629 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005630
Pengquan Meng0c05b502018-09-06 09:59:22 -07005631 Phone phone = getPhone(subId);
5632 if (phone != null) {
5633 phone.setDataRoamingEnabled(isEnabled);
5634 }
5635 } finally {
5636 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005637 }
5638 }
5639
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005640 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005641 public boolean isManualNetworkSelectionAllowed(int subId) {
5642 boolean isAllowed = true;
5643 final long identity = Binder.clearCallingIdentity();
5644 try {
5645 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5646 mApp, subId, "isManualNetworkSelectionAllowed");
5647 Phone phone = getPhone(subId);
5648 if (phone != null) {
5649 isAllowed = phone.isCspPlmnEnabled();
5650 }
5651 } finally {
5652 Binder.restoreCallingIdentity(identity);
5653 }
5654 return isAllowed;
5655 }
5656
5657 @Override
Jordan Liu5aa07002018-12-18 15:44:48 -08005658 public UiccCardInfo[] getUiccCardsInfo() {
5659 enforceReadPrivilegedPermission("getUiccCardsInfo");
5660
5661 final long identity = Binder.clearCallingIdentity();
5662 try {
5663 ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos();
5664 return cards.toArray(new UiccCardInfo[cards.size()]);
5665 } finally {
5666 Binder.restoreCallingIdentity(identity);
5667 }
5668 }
5669
5670 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005671 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005672 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005673
Malcolm Chend965c8b2018-02-28 15:00:40 -08005674 final long identity = Binder.clearCallingIdentity();
5675 try {
5676 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5677 if (slots == null) {
5678 Rlog.i(LOG_TAG, "slots is null.");
5679 return null;
5680 }
5681
5682 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5683 for (int i = 0; i < slots.length; i++) {
5684 UiccSlot slot = slots[i];
5685 if (slot == null) {
5686 continue;
5687 }
5688
5689 String cardId;
5690 UiccCard card = slot.getUiccCard();
5691 if (card != null) {
5692 cardId = card.getCardId();
5693 } else {
5694 cardId = slot.getIccId();
5695 }
5696
5697 int cardState = 0;
5698 switch (slot.getCardState()) {
5699 case CARDSTATE_ABSENT:
5700 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5701 break;
5702 case CARDSTATE_PRESENT:
5703 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5704 break;
5705 case CARDSTATE_ERROR:
5706 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5707 break;
5708 case CARDSTATE_RESTRICTED:
5709 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5710 break;
5711 default:
5712 break;
5713
5714 }
5715
5716 infos[i] = new UiccSlotInfo(
5717 slot.isActive(),
5718 slot.isEuicc(),
5719 cardId,
5720 cardState,
5721 slot.getPhoneId(),
5722 slot.isExtendedApduSupported());
5723 }
5724 return infos;
5725 } finally {
5726 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005727 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005728 }
5729
5730 @Override
5731 public boolean switchSlots(int[] physicalSlots) {
5732 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005733
5734 final long identity = Binder.clearCallingIdentity();
5735 try {
5736 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005740 }
Jack Yu4c988042018-02-27 15:30:01 -08005741
5742 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08005743 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
5744 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5745 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
5746 return TelephonyManager.INVALID_CARD_ID;
5747 }
5748
5749 final long identity = Binder.clearCallingIdentity();
5750 try {
5751 return UiccController.getInstance().getCardIdForDefaultEuicc();
5752 } finally {
5753 Binder.restoreCallingIdentity(identity);
5754 }
5755 }
5756
5757 @Override
Jack Yu4c988042018-02-27 15:30:01 -08005758 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5759 enforceModifyPermission();
5760 final Phone phone = getPhone(subId);
5761 if (phone == null) {
5762 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5763 return;
5764 }
5765
Malcolm Chend965c8b2018-02-28 15:00:40 -08005766 final long identity = Binder.clearCallingIdentity();
5767 try {
5768 phone.setRadioIndicationUpdateMode(filters, mode);
5769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
Jack Yu4c988042018-02-27 15:30:01 -08005772 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005773
5774 /**
goneil47ffb6e2018-04-06 15:40:58 -07005775 * A test API to reload the UICC profile.
5776 *
5777 * <p>Requires that the calling app has permission
5778 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5779 * @hide
5780 */
5781 @Override
5782 public void refreshUiccProfile(int subId) {
5783 enforceModifyPermission();
5784
5785 final long identity = Binder.clearCallingIdentity();
5786 try {
5787 Phone phone = getPhone(subId);
5788 if (phone == null) {
5789 return;
5790 }
5791 UiccCard uiccCard = phone.getUiccCard();
5792 if (uiccCard == null) {
5793 return;
5794 }
5795 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5796 if (uiccProfile == null) {
5797 return;
5798 }
5799 uiccProfile.refresh();
5800 } finally {
5801 Binder.restoreCallingIdentity(identity);
5802 }
5803 }
5804
5805 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005806 * Returns false if the mobile data is disabled by default, otherwise return true.
5807 */
5808 private boolean getDefaultDataEnabled() {
5809 return "true".equalsIgnoreCase(
5810 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5811 }
5812
5813 /**
5814 * Returns true if the data roaming is enabled by default, i.e the system property
5815 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5816 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5817 */
5818 private boolean getDefaultDataRoamingEnabled(int subId) {
5819 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005820 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005821 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5822 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5823 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5824 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5825 return isDataRoamingEnabled;
5826 }
5827
5828 /**
5829 * Returns the default network type for the given {@code subId}, if the default network type is
5830 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5831 */
5832 private int getDefaultNetworkType(int subId) {
5833 return Integer.parseInt(
5834 TelephonyManager.getTelephonyProperty(
5835 mSubscriptionController.getPhoneId(subId),
5836 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5837 String.valueOf(Phone.PREFERRED_NT_MODE)));
5838 }
fionaxua13278b2018-03-21 00:08:13 -07005839
5840 @Override
5841 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5842 gid1, String gid2, String plmn, String spn) {
5843 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005844
5845 final long identity = Binder.clearCallingIdentity();
5846 try {
5847 final Phone phone = getPhone(subId);
5848 if (phone == null) {
5849 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5850 return;
5851 }
5852 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5853 } finally {
5854 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005855 }
fionaxua13278b2018-03-21 00:08:13 -07005856 }
5857
5858 @Override
5859 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005860 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005861
5862 final long identity = Binder.clearCallingIdentity();
5863 try {
5864 final Phone phone = getPhone(subId);
5865 if (phone == null) {
5866 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5867 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5868 }
5869 return phone.getCarrierIdListVersion();
5870 } finally {
5871 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005872 }
fionaxua13278b2018-03-21 00:08:13 -07005873 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005874
5875 @Override
5876 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5877 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5878 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5879 return -1;
5880 }
5881
5882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5885 } finally {
5886 Binder.restoreCallingIdentity(identity);
5887 }
5888 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005889
5890 @Override
5891 public int getCdmaRoamingMode(int subId) {
5892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5893 mApp, subId, "getCdmaRoamingMode");
5894
5895 final long identity = Binder.clearCallingIdentity();
5896 try {
5897 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5898 } finally {
5899 Binder.restoreCallingIdentity(identity);
5900 }
5901 }
5902
5903 @Override
5904 public boolean setCdmaRoamingMode(int subId, int mode) {
5905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5906 mApp, subId, "setCdmaRoamingMode");
5907
5908 final long identity = Binder.clearCallingIdentity();
5909 try {
5910 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5911 } finally {
5912 Binder.restoreCallingIdentity(identity);
5913 }
5914 }
5915
5916 @Override
5917 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5919 mApp, subId, "setCdmaSubscriptionMode");
5920
5921 final long identity = Binder.clearCallingIdentity();
5922 try {
5923 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5924 } finally {
5925 Binder.restoreCallingIdentity(identity);
5926 }
5927 }
chen xu7ee67862018-10-30 22:27:10 -07005928
sqian2fff4a32018-11-05 14:18:37 -08005929 private void ensureUserRunning(int userId) {
5930 if (!mUserManager.isUserRunning(userId)) {
5931 throw new IllegalStateException("User " + userId + " does not exist or not running");
5932 }
5933 }
5934
5935 /**
5936 * Returns a list of SMS apps on a given user.
5937 *
5938 * Only the shell user (UID 2000 or 0) can call it.
5939 * Target user must be running.
5940 */
5941 @Override
5942 public String[] getSmsApps(int userId) {
5943 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5944 ensureUserRunning(userId);
5945
5946 final Collection<SmsApplicationData> apps =
5947 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5948
5949 String[] ret = new String[apps.size()];
5950 int i = 0;
5951 for (SmsApplicationData app : apps) {
5952 ret[i++] = app.mPackageName;
5953 }
5954 return ret;
5955 }
5956
5957 /**
5958 * Returns the default SMS app package name on a given user.
5959 *
5960 * Only the shell user (UID 2000 or 0) can call it.
5961 * Target user must be running.
5962 */
5963 @Override
5964 public String getDefaultSmsApp(int userId) {
5965 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5966 ensureUserRunning(userId);
5967
5968 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5969 /* updateIfNeeded= */ true, userId);
5970 return cn == null ? null : cn.getPackageName();
5971 }
5972
5973 /**
5974 * Set a package as the default SMS app on a given user.
5975 *
5976 * Only the shell user (UID 2000 or 0) can call it.
5977 * Target user must be running.
5978 */
5979 @Override
5980 public void setDefaultSmsApp(int userId, String packageName) {
5981 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5982 ensureUserRunning(userId);
5983
5984 boolean found = false;
5985 for (String pkg : getSmsApps(userId)) {
5986 if (TextUtils.equals(packageName, pkg)) {
5987 found = true;
5988 break;
5989 }
5990 }
5991 if (!found) {
5992 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5993 }
5994
5995 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5996 }
5997
chen xu7ee67862018-10-30 22:27:10 -07005998 @Override
sqian04b86072018-11-07 14:02:21 -08005999 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6000 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006001 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6002 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6003 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6004 }
6005 final long identity = Binder.clearCallingIdentity();
6006 try {
6007 Map<Integer, List<EmergencyNumber>> results = getEmergencyNumberListInternal();
6008 // Use ecclist to construct Emergency number list for backward compatibality
6009 if (results.isEmpty()) {
6010 results = getEmergencyNumberListFromEccList();
6011 }
6012 return results;
6013 } finally {
6014 Binder.restoreCallingIdentity(identity);
6015 }
sqian04b86072018-11-07 14:02:21 -08006016 }
6017
6018 @Override
sqian03bca152018-12-05 18:48:28 -08006019 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6020 final Phone defaultPhone = getDefaultPhone();
6021 if (!exactMatch) {
6022 TelephonyPermissions
6023 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6024 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6025 }
6026 final long identity = Binder.clearCallingIdentity();
6027 try {
6028 Map<Integer, List<EmergencyNumber>> emergencyNumberLists =
6029 getEmergencyNumberListInternal();
6030
6031 String defaultCountryIso = getNetworkCountryIsoForPhone(defaultPhone.getPhoneId());
6032
6033 if (!emergencyNumberLists.isEmpty()) {
6034 for (List<EmergencyNumber> emergencyNumberList : emergencyNumberLists.values()) {
6035 if (emergencyNumberList != null) {
6036 for (EmergencyNumber num : emergencyNumberList) {
6037 // According to com.android.i18n.phonenumbers.ShortNumberInfo, in
6038 // these countries, if extra digits are added to an emergency number,
6039 // it no longer connects to the emergency service.
6040 Set<String> countriesRequiredForExactMatch = new HashSet<>();
6041 countriesRequiredForExactMatch.add("br");
6042 countriesRequiredForExactMatch.add("cl");
6043 countriesRequiredForExactMatch.add("ni");
6044 if (exactMatch || countriesRequiredForExactMatch.contains(
6045 defaultCountryIso)) {
6046 if (num.getNumber().equals(number)) {
6047 return true;
6048 }
6049 } else {
6050 if (number.startsWith(num.getNumber())) {
6051 return true;
6052 }
6053 }
6054
6055 }
6056 }
6057 }
6058 } else {
6059 // For backward compatibility for devices launched before Q
6060 return PhoneNumberUtils.isEmergencyNumberInternal(number, exactMatch,
6061 defaultCountryIso);
6062 }
6063 return false;
6064 } finally {
6065 Binder.restoreCallingIdentity(identity);
6066 }
6067 }
6068
6069 private Map<Integer, List<EmergencyNumber>> getEmergencyNumberListInternal() {
6070 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6071
6072 for (Phone phone: PhoneFactory.getPhones()) {
6073 if (phone.getEmergencyNumberTracker() != null
6074 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6075 emergencyNumberListInternal.put(
6076 phone.getSubId(),
6077 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6078 }
6079 }
6080 return emergencyNumberListInternal;
6081 }
6082
6083 private List<EmergencyNumber> getEmergencyNumberListFromEccList(int subscriptionId) {
6084 SubscriptionManager sm = (SubscriptionManager) mApp.getSystemService(
6085 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6086 List<EmergencyNumber> emergencyNumberList = new ArrayList<>();
6087 int slotId = sm.getSlotIndex(subscriptionId);
6088
6089 String ecclist = (slotId <= 0) ? "ril.ecclist" : ("ril.ecclist" + slotId);
6090 String emergencyNumbers = SystemProperties.get(ecclist, "");
6091 if (TextUtils.isEmpty(emergencyNumbers)) {
6092 // then read-only ecclist property since old RIL only uses this
6093 emergencyNumbers = SystemProperties.get("ro.ril.ecclist");
6094 }
6095 if (!TextUtils.isEmpty(emergencyNumbers)) {
6096 // searches through the comma-separated list for a match,
6097 // return true if one is found.
6098 for (String emergencyNum : emergencyNumbers.split(",")) {
6099 emergencyNumberList.add(new EmergencyNumber(emergencyNum, "", "",
6100 EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED, 0));
6101 }
6102 }
6103 emergencyNumbers = ((slotId < 0) ? "112,911,000,08,110,118,119,999" : "112,911");
6104 for (String emergencyNum : emergencyNumbers.split(",")) {
6105 emergencyNumberList.add(new EmergencyNumber(emergencyNum, "", "",
6106 EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED, 0));
6107 }
6108 EmergencyNumber.mergeSameNumbersInEmergencyNumberList(emergencyNumberList);
6109 return emergencyNumberList;
6110 }
6111
6112 /**
6113 * Get Emergency number list based on EccList. This util is used for solving backward
6114 * compatibility if device does not support the 1.4 IRadioIndication HAL that reports
6115 * emergency number list.
6116 *
6117 * @return Map including the key as the active subscription ID (Note: if there is no active
6118 * subscription, the key is {@link SubscriptionManager#getDefaultSubscriptionId})
6119 * and the value as the list of {@link EmergencyNumber}.
6120 */
6121 private Map<Integer, List<EmergencyNumber>> getEmergencyNumberListFromEccList() {
6122 Map<Integer, List<EmergencyNumber>> results = new HashMap<>();
6123 SubscriptionManager sm = (SubscriptionManager) mApp.getSystemService(
6124 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6125 int[] activeSubscriptionIds = sm.getActiveSubscriptionIdList();
6126
6127 if (activeSubscriptionIds.length == 0) {
6128 int defaultSubscriptionId = getDefaultSubscription();
6129 results.put(defaultSubscriptionId,
6130 getEmergencyNumberListFromEccList(defaultSubscriptionId));
6131 } else {
6132 for (int activeSubscriptionId : activeSubscriptionIds) {
6133 results.put(activeSubscriptionId,
6134 getEmergencyNumberListFromEccList(activeSubscriptionId));
6135 }
6136 }
6137 return results;
sqian04b86072018-11-07 14:02:21 -08006138 }
6139
6140 @Override
chen xu7ee67862018-10-30 22:27:10 -07006141 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6142 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6143 Phone phone = getPhone(subId);
6144 if (phone == null) {
6145 return null;
6146 }
6147 final long identity = Binder.clearCallingIdentity();
6148 try {
6149 UiccProfile profile = UiccController.getInstance()
6150 .getUiccProfileForPhone(phone.getPhoneId());
6151 if (profile != null) {
6152 return profile.getCertsFromCarrierPrivilegeAccessRules();
6153 }
6154 } finally {
6155 Binder.restoreCallingIdentity(identity);
6156 }
6157 return null;
6158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006159}