blob: 2cd68850fa8626e633cd6c0cb294e3cfea0f0718 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
38import android.os.Bundle;
39import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Looper;
42import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070044import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080045import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070046import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070048import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070049import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070051import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070052import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070053import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080054import android.provider.Settings;
Santos Cordon7a1885b2015-02-03 11:15:19 -080055import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080056import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070057import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070058import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080059import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070061import android.telephony.CellInfoGsm;
62import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070063import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070064import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070065import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070066import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080067import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070068import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080069import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070070import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080071import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070072import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080075import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070076import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080077import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070079import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080081import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000082import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070083import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070084import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070085import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080086import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080087import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070088import android.telephony.gsm.GsmCellLocation;
Brad Ebinger4c460712018-10-01 10:40:55 -070089import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080090import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070091import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080092import android.telephony.ims.aidl.IImsMmTelFeature;
93import android.telephony.ims.aidl.IImsRcsFeature;
94import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070095import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080096import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080098import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800100import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800101import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800102
Brad Ebinger4c460712018-10-01 10:40:55 -0700103import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700104import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800105import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700106import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700107import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700108import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800109import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700110import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700111import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import com.android.internal.telephony.DefaultPhoneNotifier;
Hall Liud892bec2018-11-30 14:51:45 -0800113import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800115import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700116import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100117import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700118import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700119import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700121import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800122import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700123import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700124import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700125import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700126import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700127import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700128import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800129import com.android.internal.telephony.SmsApplication;
130import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800131import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800132import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700133import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700134import com.android.internal.telephony.uicc.IccIoResult;
135import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800136import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700137import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800138import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800140import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000141import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700142import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800143import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700144import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800145import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700146import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700147import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800148
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700149import java.io.FileDescriptor;
150import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800151import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800153import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800154import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800155import java.util.HashMap;
Jake Hambye994d462014-02-03 13:10:13 -0800156import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100157import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800158import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159
160/**
161 * Implementation of the ITelephony interface.
162 */
Santos Cordon117fee72014-05-16 17:56:12 -0700163public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164 private static final String LOG_TAG = "PhoneInterfaceManager";
165 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
166 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800167 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168
169 // Message codes used with mMainThreadHandler
170 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700171 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
172 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700173 private static final int CMD_OPEN_CHANNEL = 9;
174 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
175 private static final int CMD_CLOSE_CHANNEL = 11;
176 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800177 private static final int CMD_NV_READ_ITEM = 13;
178 private static final int EVENT_NV_READ_ITEM_DONE = 14;
179 private static final int CMD_NV_WRITE_ITEM = 15;
180 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
181 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
182 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700183 private static final int CMD_RESET_MODEM_CONFIG = 19;
184 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800185 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
186 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
187 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
188 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800189 private static final int CMD_SEND_ENVELOPE = 25;
190 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000191 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
192 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700193 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
194 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
195 private static final int CMD_EXCHANGE_SIM_IO = 31;
196 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800197 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
198 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700199 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
200 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700201 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
202 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700203 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
204 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
205 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
206 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700207 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
208 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
209 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
210 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700211 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800212 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
213 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000214 private static final int CMD_SWITCH_SLOTS = 50;
215 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700216 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
217 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
218 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
219 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
220 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
221 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
222 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
223 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700224 private static final int CMD_GET_ALL_CELL_INFO = 60;
225 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
226 private static final int CMD_GET_CELL_LOCATION = 62;
227 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700228 private static final int CMD_MODEM_REBOOT = 64;
229 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700230 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
231 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800232 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
233 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800235 // Parameters of select command.
236 private static final int SELECT_COMMAND = 0xA4;
237 private static final int SELECT_P1 = 0x04;
238 private static final int SELECT_P2 = 0;
239 private static final int SELECT_P3 = 0x10;
240
Pengquan Meng85728fb2018-03-12 16:31:21 -0700241 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
242 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
243 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
244
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245 /** The singleton instance. */
246 private static PhoneInterfaceManager sInstance;
247
Wink Saville3ab207e2014-11-20 13:07:20 -0800248 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800249 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700250 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800251 private AppOpsManager mAppOps;
252 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800253 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800254 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700255 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256
Derek Tan97ebb422014-09-05 16:55:38 -0700257 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
258 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800259 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700260
Derek Tan740e1672017-06-27 14:56:27 -0700261 // The AID of ISD-R.
262 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
263
yinxub1bed742017-04-17 11:45:04 -0700264 private NetworkScanRequestTracker mNetworkScanRequestTracker;
265
David Kelly5e06a7f2018-03-12 14:10:59 +0000266 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
267 private static final int MANUFACTURER_CODE_LENGTH = 8;
268
Derek Tan89e89d42014-07-08 17:00:10 -0700269 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700270 * A request object to use for transmitting data to an ICC.
271 */
272 private static final class IccAPDUArgument {
273 public int channel, cla, command, p1, p2, p3;
274 public String data;
275
276 public IccAPDUArgument(int channel, int cla, int command,
277 int p1, int p2, int p3, String data) {
278 this.channel = channel;
279 this.cla = cla;
280 this.command = command;
281 this.p1 = p1;
282 this.p2 = p2;
283 this.p3 = p3;
284 this.data = data;
285 }
286 }
287
288 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700289 * A request object to use for transmitting data to an ICC.
290 */
291 private static final class ManualNetworkSelectionArgument {
292 public OperatorInfo operatorInfo;
293 public boolean persistSelection;
294
295 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
296 this.operatorInfo = operatorInfo;
297 this.persistSelection = persistSelection;
298 }
299 }
300
301 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700302 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
303 * request after sending. The main thread will notify the request when it is complete.
304 */
305 private static final class MainThreadRequest {
306 /** The argument to use for the request */
307 public Object argument;
308 /** The result of the request that is run on the main thread */
309 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800310 // The subscriber id that this request applies to. Defaults to
311 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
312 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700313
Nathan Harold92bed182018-10-12 18:16:49 -0700314 // In cases where subId is unavailable, the caller needs to specify the phone.
315 public Phone phone;
316
vagdevie435a3e2018-08-15 16:01:53 -0700317 public WorkSource workSource;
318
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 public MainThreadRequest(Object argument) {
320 this.argument = argument;
321 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800322
Nathan Harold92bed182018-10-12 18:16:49 -0700323 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
324 this.argument = argument;
325 if (phone != null) {
326 this.phone = phone;
327 }
328 this.workSource = workSource;
329 }
330
vagdevie435a3e2018-08-15 16:01:53 -0700331 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800332 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800333 if (subId != null) {
334 this.subId = subId;
335 }
vagdevie435a3e2018-08-15 16:01:53 -0700336 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800337 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 }
339
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800340 private static final class IncomingThirdPartyCallArgs {
341 public final ComponentName component;
342 public final String callId;
343 public final String callerDisplayName;
344
345 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
346 String callerDisplayName) {
347 this.component = component;
348 this.callId = callId;
349 this.callerDisplayName = callerDisplayName;
350 }
351 }
352
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353 /**
354 * A handler that processes messages on the main thread in the phone process. Since many
355 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
356 * inbound binder threads to the main thread in the phone process. The Binder thread
357 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
358 * on, which will be notified when the operation completes and will contain the result of the
359 * request.
360 *
361 * <p>If a MainThreadRequest object is provided in the msg.obj field,
362 * note that request.result must be set to something non-null for the calling thread to
363 * unblock.
364 */
365 private final class MainThreadHandler extends Handler {
366 @Override
367 public void handleMessage(Message msg) {
368 MainThreadRequest request;
369 Message onCompleted;
370 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800371 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700372 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800373 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374
375 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700376 case CMD_HANDLE_USSD_REQUEST: {
377 request = (MainThreadRequest) msg.obj;
378 final Phone phone = getPhoneFromRequest(request);
379 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
380 String ussdRequest = ussdObject.first;
381 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700382
Pengquan Meng0c05b502018-09-06 09:59:22 -0700383 if (!isUssdApiAllowed(request.subId)) {
384 // Carrier does not support use of this API, return failure.
385 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
386 UssdResponse response = new UssdResponse(ussdRequest, null);
387 Bundle returnData = new Bundle();
388 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
389 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700390
Pengquan Meng0c05b502018-09-06 09:59:22 -0700391 request.result = true;
392 notifyRequester(request);
393 return;
394 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700395
Pengquan Meng0c05b502018-09-06 09:59:22 -0700396 try {
397 request.result = phone != null
398 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
399 } catch (CallStateException cse) {
400 request.result = false;
401 }
402 // Wake up the requesting thread
403 notifyRequester(request);
404 break;
pkanwar32d516d2016-10-14 19:37:38 -0700405 }
406
Yorke Lee716f67e2015-06-17 15:39:16 -0700407 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700409 final Phone phone = getPhoneFromRequest(request);
410 request.result = phone != null ?
411 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
412 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700414 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700418 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700419 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700420 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800421 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700422 if (uiccCard == null) {
423 loge("iccTransmitApduLogicalChannel: No UICC");
424 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700425 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700426 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
428 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700429 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700430 iccArgument.channel, iccArgument.cla, iccArgument.command,
431 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700433 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700434 break;
435
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700436 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 ar = (AsyncResult) msg.obj;
438 request = (MainThreadRequest) ar.userObj;
439 if (ar.exception == null && ar.result != null) {
440 request.result = ar.result;
441 } else {
442 request.result = new IccIoResult(0x6F, 0, (byte[])null);
443 if (ar.result == null) {
444 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800445 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800447 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700448 } else {
449 loge("iccTransmitApduLogicalChannel: Unknown exception");
450 }
451 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700452 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700453 break;
454
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
456 request = (MainThreadRequest) msg.obj;
457 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800458 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 if (uiccCard == null) {
460 loge("iccTransmitApduBasicChannel: No UICC");
461 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700462 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 } else {
464 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
465 request);
466 uiccCard.iccTransmitApduBasicChannel(
467 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
468 iccArgument.p3, iccArgument.data, onCompleted);
469 }
470 break;
471
472 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
473 ar = (AsyncResult) msg.obj;
474 request = (MainThreadRequest) ar.userObj;
475 if (ar.exception == null && ar.result != null) {
476 request.result = ar.result;
477 } else {
478 request.result = new IccIoResult(0x6F, 0, (byte[])null);
479 if (ar.result == null) {
480 loge("iccTransmitApduBasicChannel: Empty response");
481 } else if (ar.exception instanceof CommandException) {
482 loge("iccTransmitApduBasicChannel: CommandException: " +
483 ar.exception);
484 } else {
485 loge("iccTransmitApduBasicChannel: Unknown exception");
486 }
487 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700488 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 break;
490
491 case CMD_EXCHANGE_SIM_IO:
492 request = (MainThreadRequest) msg.obj;
493 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800494 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 if (uiccCard == null) {
496 loge("iccExchangeSimIO: No UICC");
497 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700498 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 } else {
500 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
501 request);
502 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
503 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
504 iccArgument.data, onCompleted);
505 }
506 break;
507
508 case EVENT_EXCHANGE_SIM_IO_DONE:
509 ar = (AsyncResult) msg.obj;
510 request = (MainThreadRequest) ar.userObj;
511 if (ar.exception == null && ar.result != null) {
512 request.result = ar.result;
513 } else {
514 request.result = new IccIoResult(0x6f, 0, (byte[])null);
515 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700516 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700517 break;
518
Derek Tan4d5e5c12014-02-04 11:54:58 -0800519 case CMD_SEND_ENVELOPE:
520 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800521 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700522 if (uiccCard == null) {
523 loge("sendEnvelopeWithStatus: No UICC");
524 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700525 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700526 } else {
527 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
528 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
529 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800530 break;
531
532 case EVENT_SEND_ENVELOPE_DONE:
533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700535 if (ar.exception == null && ar.result != null) {
536 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800537 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
539 if (ar.result == null) {
540 loge("sendEnvelopeWithStatus: Empty response");
541 } else if (ar.exception instanceof CommandException) {
542 loge("sendEnvelopeWithStatus: CommandException: " +
543 ar.exception);
544 } else {
545 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
546 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700548 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800549 break;
550
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 case CMD_OPEN_CHANNEL:
552 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800553 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800554 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 if (uiccCard == null) {
556 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800557 request.result = new IccOpenLogicalChannelResponse(-1,
558 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 } else {
561 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800562 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
563 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 break;
566
567 case EVENT_OPEN_CHANNEL_DONE:
568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 int[] result = (int[]) ar.result;
573 int channelId = result[0];
574 byte[] selectResponse = null;
575 if (result.length > 1) {
576 selectResponse = new byte[result.length - 1];
577 for (int i = 1; i < result.length; ++i) {
578 selectResponse[i - 1] = (byte) result[i];
579 }
580 }
581 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700582 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 if (ar.result == null) {
585 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 if (ar.exception != null) {
588 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
589 }
590
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700591 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700592 if (ar.exception instanceof CommandException) {
593 CommandException.Error error =
594 ((CommandException) (ar.exception)).getCommandError();
595 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700597 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700598 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 }
600 }
601 openChannelResp = new IccOpenLogicalChannelResponse(
602 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700604 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700605 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 break;
607
608 case CMD_CLOSE_CHANNEL:
609 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800610 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700611 if (uiccCard == null) {
612 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900613 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700614 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 } else {
616 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
617 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
618 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 break;
620
621 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800622 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
623 break;
624
625 case CMD_NV_READ_ITEM:
626 request = (MainThreadRequest) msg.obj;
627 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800628 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
629 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800630 break;
631
632 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 ar = (AsyncResult) msg.obj;
634 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800635 if (ar.exception == null && ar.result != null) {
636 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800638 request.result = "";
639 if (ar.result == null) {
640 loge("nvReadItem: Empty response");
641 } else if (ar.exception instanceof CommandException) {
642 loge("nvReadItem: CommandException: " +
643 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800645 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 }
647 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700648 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 break;
650
Jake Hambye994d462014-02-03 13:10:13 -0800651 case CMD_NV_WRITE_ITEM:
652 request = (MainThreadRequest) msg.obj;
653 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
654 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800655 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700656 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800657 break;
658
659 case EVENT_NV_WRITE_ITEM_DONE:
660 handleNullReturnEvent(msg, "nvWriteItem");
661 break;
662
663 case CMD_NV_WRITE_CDMA_PRL:
664 request = (MainThreadRequest) msg.obj;
665 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800666 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800667 break;
668
669 case EVENT_NV_WRITE_CDMA_PRL_DONE:
670 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
671 break;
672
chen xu1cc0abe2018-10-26 17:39:23 -0700673 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800674 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700675 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800676 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800677 break;
678
chen xu1cc0abe2018-10-26 17:39:23 -0700679 case EVENT_RESET_MODEM_CONFIG_DONE:
680 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800681 break;
682
Jake Hamby7c27be32014-03-03 13:25:59 -0800683 case CMD_GET_PREFERRED_NETWORK_TYPE:
684 request = (MainThreadRequest) msg.obj;
685 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700686 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800687 break;
688
689 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
690 ar = (AsyncResult) msg.obj;
691 request = (MainThreadRequest) ar.userObj;
692 if (ar.exception == null && ar.result != null) {
693 request.result = ar.result; // Integer
694 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800695 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800696 if (ar.result == null) {
697 loge("getPreferredNetworkType: Empty response");
698 } else if (ar.exception instanceof CommandException) {
699 loge("getPreferredNetworkType: CommandException: " +
700 ar.exception);
701 } else {
702 loge("getPreferredNetworkType: Unknown exception");
703 }
704 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700705 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800706 break;
707
708 case CMD_SET_PREFERRED_NETWORK_TYPE:
709 request = (MainThreadRequest) msg.obj;
710 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
711 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700712 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 break;
714
715 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
716 handleNullReturnEvent(msg, "setPreferredNetworkType");
717 break;
718
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000719 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
720 request = (MainThreadRequest)msg.obj;
721 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800722 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000723 break;
724
725 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
726 ar = (AsyncResult)msg.obj;
727 request = (MainThreadRequest)ar.userObj;
728 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700729 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000730 break;
731
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800732 case CMD_SET_VOICEMAIL_NUMBER:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
735 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800736 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
737 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800738 break;
739
740 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
741 handleNullReturnEvent(msg, "setVoicemailNumber");
742 break;
743
Stuart Scott54788802015-03-30 13:18:01 -0700744 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
745 request = (MainThreadRequest) msg.obj;
746 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
747 request);
748 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
749 break;
750
751 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
752 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
753 break;
754
Shishir Agrawal302c8692015-06-19 13:49:39 -0700755 case CMD_PERFORM_NETWORK_SCAN:
756 request = (MainThreadRequest) msg.obj;
757 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
758 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
759 break;
760
761 case EVENT_PERFORM_NETWORK_SCAN_DONE:
762 ar = (AsyncResult) msg.obj;
763 request = (MainThreadRequest) ar.userObj;
764 CellNetworkScanResult cellScanResult;
765 if (ar.exception == null && ar.result != null) {
766 cellScanResult = new CellNetworkScanResult(
767 CellNetworkScanResult.STATUS_SUCCESS,
768 (List<OperatorInfo>) ar.result);
769 } else {
770 if (ar.result == null) {
771 loge("getCellNetworkScanResults: Empty response");
772 }
773 if (ar.exception != null) {
774 loge("getCellNetworkScanResults: Exception: " + ar.exception);
775 }
776 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
777 if (ar.exception instanceof CommandException) {
778 CommandException.Error error =
779 ((CommandException) (ar.exception)).getCommandError();
780 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
781 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
782 } else if (error == CommandException.Error.GENERIC_FAILURE) {
783 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
784 }
785 }
786 cellScanResult = new CellNetworkScanResult(errorCode, null);
787 }
788 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700789 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700790 break;
791
792 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
793 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700794 ManualNetworkSelectionArgument selArg =
795 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700796 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
797 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700798 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
799 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700800 break;
801
802 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
805 if (ar.exception == null) {
806 request.result = true;
807 } else {
808 request.result = false;
809 loge("setNetworkSelectionModeManual " + ar.exception);
810 }
811 notifyRequester(request);
812 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700813 break;
814
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700815 case CMD_GET_MODEM_ACTIVITY_INFO:
816 request = (MainThreadRequest) msg.obj;
817 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800818 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700819 break;
820
821 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
822 ar = (AsyncResult) msg.obj;
823 request = (MainThreadRequest) ar.userObj;
824 if (ar.exception == null && ar.result != null) {
825 request.result = ar.result;
826 } else {
827 if (ar.result == null) {
828 loge("queryModemActivityInfo: Empty response");
829 } else if (ar.exception instanceof CommandException) {
830 loge("queryModemActivityInfo: CommandException: " +
831 ar.exception);
832 } else {
833 loge("queryModemActivityInfo: Unknown exception");
834 }
835 }
Amit Mahajand4766222016-01-28 15:28:28 -0800836 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
837 if (request.result == null) {
838 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
839 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700840 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700841 break;
842
Meng Wang1a7c35a2016-05-05 20:56:15 -0700843 case CMD_SET_ALLOWED_CARRIERS:
844 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800845 CarrierRestrictionRules argument =
846 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700847 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800848 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700849 break;
850
851 case EVENT_SET_ALLOWED_CARRIERS_DONE:
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null && ar.result != null) {
855 request.result = ar.result;
856 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800857 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
858 if (ar.exception instanceof CommandException) {
859 loge("setAllowedCarriers: CommandException: " + ar.exception);
860 CommandException.Error error =
861 ((CommandException) (ar.exception)).getCommandError();
862 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
863 request.result =
864 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
865 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700866 } else {
867 loge("setAllowedCarriers: Unknown exception");
868 }
869 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700870 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700871 break;
872
873 case CMD_GET_ALLOWED_CARRIERS:
874 request = (MainThreadRequest) msg.obj;
875 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800876 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700877 break;
878
879 case EVENT_GET_ALLOWED_CARRIERS_DONE:
880 ar = (AsyncResult) msg.obj;
881 request = (MainThreadRequest) ar.userObj;
882 if (ar.exception == null && ar.result != null) {
883 request.result = ar.result;
884 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800885 request.result = new IllegalStateException(
886 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700887 if (ar.result == null) {
888 loge("getAllowedCarriers: Empty response");
889 } else if (ar.exception instanceof CommandException) {
890 loge("getAllowedCarriers: CommandException: " +
891 ar.exception);
892 } else {
893 loge("getAllowedCarriers: Unknown exception");
894 }
895 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700896 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700897 break;
898
Nathan Haroldb3014052017-01-25 15:57:32 -0800899 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
900 ar = (AsyncResult) msg.obj;
901 request = (MainThreadRequest) ar.userObj;
902 if (ar.exception == null && ar.result != null) {
903 request.result = ar.result;
904 } else {
905 request.result = new IllegalArgumentException(
906 "Failed to retrieve Forbidden Plmns");
907 if (ar.result == null) {
908 loge("getForbiddenPlmns: Empty response");
909 } else {
910 loge("getForbiddenPlmns: Unknown exception");
911 }
912 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700913 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800914 break;
915
916 case CMD_GET_FORBIDDEN_PLMNS:
917 request = (MainThreadRequest) msg.obj;
918 uiccCard = getUiccCardFromRequest(request);
919 if (uiccCard == null) {
920 loge("getForbiddenPlmns() UiccCard is null");
921 request.result = new IllegalArgumentException(
922 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700923 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800924 break;
925 }
926 Integer appType = (Integer) request.argument;
927 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
928 if (uiccApp == null) {
929 loge("getForbiddenPlmns() no app with specified type -- "
930 + appType);
931 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700932 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800933 break;
934 } else {
935 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
936 + " specified type -- " + appType);
937 }
938 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
939 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
940 onCompleted);
941 break;
942
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000943 case CMD_SWITCH_SLOTS:
944 request = (MainThreadRequest) msg.obj;
945 int[] physicalSlots = (int[]) request.argument;
946 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
947 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
948 break;
949
950 case EVENT_SWITCH_SLOTS_DONE:
951 ar = (AsyncResult) msg.obj;
952 request = (MainThreadRequest) ar.userObj;
953 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700954 notifyRequester(request);
955 break;
956 case CMD_GET_NETWORK_SELECTION_MODE:
957 request = (MainThreadRequest) msg.obj;
958 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
959 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
960 break;
961
962 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 if (ar.exception != null) {
966 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
967 } else {
968 int mode = ((int[]) ar.result)[0];
969 if (mode == 0) {
970 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
971 } else {
972 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
973 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000974 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700975 notifyRequester(request);
976 break;
977 case CMD_GET_CDMA_ROAMING_MODE:
978 request = (MainThreadRequest) msg.obj;
979 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
980 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
981 break;
982 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 if (ar.exception != null) {
986 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
987 } else {
988 request.result = ((int[]) ar.result)[0];
989 }
990 notifyRequester(request);
991 break;
992 case CMD_SET_CDMA_ROAMING_MODE:
993 request = (MainThreadRequest) msg.obj;
994 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
995 int mode = (int) request.argument;
996 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
997 break;
998 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 request.result = ar.exception == null;
1002 notifyRequester(request);
1003 break;
1004 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1005 request = (MainThreadRequest) msg.obj;
1006 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1007 int subscriptionMode = (int) request.argument;
1008 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1009 break;
1010 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1011 ar = (AsyncResult) msg.obj;
1012 request = (MainThreadRequest) ar.userObj;
1013 request.result = ar.exception == null;
1014 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001015 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001016 case CMD_GET_ALL_CELL_INFO:
1017 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001018 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001019 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001020 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001021 case EVENT_GET_ALL_CELL_INFO_DONE:
1022 ar = (AsyncResult) msg.obj;
1023 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001024 // If a timeout occurs, the response will be null
1025 request.result = (ar.exception == null && ar.result != null)
1026 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001027 synchronized (request) {
1028 request.notifyAll();
1029 }
1030 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001031 case CMD_REQUEST_CELL_INFO_UPDATE:
1032 request = (MainThreadRequest) msg.obj;
1033 request.phone.requestCellInfoUpdate(request.workSource,
1034 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1035 break;
1036 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
1039 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1040 try {
1041 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001042 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001043 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1044 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001045 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001046 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001047 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001048 } else {
1049 // use the result as returned
1050 cb.onCellInfo((List<CellInfo>) ar.result);
1051 }
1052 } catch (RemoteException re) {
1053 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1054 }
1055 break;
1056 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 request = (MainThreadRequest) msg.obj;
1058 WorkSource ws = (WorkSource) request.argument;
1059 Phone phone = getPhoneFromRequest(request);
1060 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1061 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001062 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 ar = (AsyncResult) msg.obj;
1064 request = (MainThreadRequest) ar.userObj;
1065 if (ar.exception == null) {
1066 request.result = ar.result;
1067 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001068 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001069 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1070 ? new CdmaCellLocation() : new GsmCellLocation();
1071 }
1072
1073 synchronized (request) {
1074 request.notifyAll();
1075 }
1076 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001077 case CMD_MODEM_REBOOT:
1078 request = (MainThreadRequest) msg.obj;
1079 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001080 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001081 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001082 case EVENT_CMD_MODEM_REBOOT_DONE:
1083 handleNullReturnEvent(msg, "rebootModem");
1084 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001085 case CMD_REQUEST_ENABLE_MODEM:
1086 request = (MainThreadRequest) msg.obj;
1087 boolean enable = (boolean) request.argument;
1088 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
1089 PhoneConfigurationManager.getInstance()
1090 .enablePhone(request.phone, enable, onCompleted);
1091 break;
1092 case EVENT_ENABLE_MODEM_DONE:
1093 ar = (AsyncResult) msg.obj;
1094 request = (MainThreadRequest) ar.userObj;
1095 request.result = (ar.exception == null);
1096 notifyRequester(request);
1097 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001098 default:
1099 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1100 break;
1101 }
1102 }
Jake Hambye994d462014-02-03 13:10:13 -08001103
Pengquan Meng0c05b502018-09-06 09:59:22 -07001104 private void notifyRequester(MainThreadRequest request) {
1105 synchronized (request) {
1106 request.notifyAll();
1107 }
1108 }
1109
Jake Hambye994d462014-02-03 13:10:13 -08001110 private void handleNullReturnEvent(Message msg, String command) {
1111 AsyncResult ar = (AsyncResult) msg.obj;
1112 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1113 if (ar.exception == null) {
1114 request.result = true;
1115 } else {
1116 request.result = false;
1117 if (ar.exception instanceof CommandException) {
1118 loge(command + ": CommandException: " + ar.exception);
1119 } else {
1120 loge(command + ": Unknown exception");
1121 }
1122 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001123 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001124 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001125 }
1126
1127 /**
1128 * Posts the specified command to be executed on the main thread,
1129 * waits for the request to complete, and returns the result.
1130 * @see #sendRequestAsync
1131 */
1132 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001133 return sendRequest(
1134 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001135 }
1136
1137 /**
1138 * Posts the specified command to be executed on the main thread,
1139 * waits for the request to complete, and returns the result.
1140 * @see #sendRequestAsync
1141 */
1142 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1143 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001144 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -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 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001152 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001153 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001154 }
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 */
Nathan Harold92bed182018-10-12 18:16:49 -07001161 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1162 return sendRequest(command, argument, subId, null, workSource);
1163 }
1164
1165 /**
1166 * Posts the specified command to be executed on the main thread,
1167 * waits for the request to complete, and returns the result.
1168 * @see #sendRequestAsync
1169 */
1170 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1171 return sendRequest(
1172 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1173 }
1174
1175 /**
1176 * Posts the specified command to be executed on the main thread,
1177 * waits for the request to complete, and returns the result.
1178 * @see #sendRequestAsync
1179 */
1180 private Object sendRequest(
1181 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001182 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1183 throw new RuntimeException("This method will deadlock if called from the main thread.");
1184 }
1185
Nathan Harold92bed182018-10-12 18:16:49 -07001186 MainThreadRequest request = null;
1187 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1188 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1189 } else if (phone != null) {
1190 request = new MainThreadRequest(argument, phone, workSource);
1191 } else {
1192 request = new MainThreadRequest(argument, subId, workSource);
1193 }
1194
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 Message msg = mMainThreadHandler.obtainMessage(command, request);
1196 msg.sendToTarget();
1197
1198 // Wait for the request to complete
1199 synchronized (request) {
1200 while (request.result == null) {
1201 try {
1202 request.wait();
1203 } catch (InterruptedException e) {
1204 // Do nothing, go back and wait until the request is complete
1205 }
1206 }
1207 }
1208 return request.result;
1209 }
1210
1211 /**
1212 * Asynchronous ("fire and forget") version of sendRequest():
1213 * Posts the specified command to be executed on the main thread, and
1214 * returns immediately.
1215 * @see #sendRequest
1216 */
1217 private void sendRequestAsync(int command) {
1218 mMainThreadHandler.sendEmptyMessage(command);
1219 }
1220
1221 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001222 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001223 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001224 */
1225 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001226 sendRequestAsync(command, argument, null, null);
1227 }
1228
1229 /**
1230 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1231 * @see {@link #sendRequest(int,Object)}
1232 */
1233 private void sendRequestAsync(
1234 int command, Object argument, Phone phone, WorkSource workSource) {
1235 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001236 Message msg = mMainThreadHandler.obtainMessage(command, request);
1237 msg.sendToTarget();
1238 }
1239
1240 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001241 * Initialize the singleton PhoneInterfaceManager instance.
1242 * This is only done once, at startup, from PhoneApp.onCreate().
1243 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001244 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 synchronized (PhoneInterfaceManager.class) {
1246 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001247 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 } else {
1249 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1250 }
1251 return sInstance;
1252 }
1253 }
1254
1255 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001256 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001257 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001259 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1261 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001262 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001263 mTelephonySharedPreferences =
1264 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001265 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001266 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001267
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001268 publish();
1269 }
1270
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001271 private Phone getDefaultPhone() {
1272 Phone thePhone = getPhone(getDefaultSubscription());
1273 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1274 }
1275
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276 private void publish() {
1277 if (DBG) log("publish: " + this);
1278
1279 ServiceManager.addService("phone", this);
1280 }
1281
Stuart Scott584921c2015-01-15 17:10:34 -08001282 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001283 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001284 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001285 }
1286
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001287 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1288 Phone phone = getPhoneFromRequest(request);
1289 return phone == null ? null :
1290 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1291 }
1292
Wink Saville36469e72014-06-11 15:17:00 -07001293 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001294 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001295 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001297
1298 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001299 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001300 }
1301
Wink Savilleb564aae2014-10-23 10:18:09 -07001302 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303 if (DBG) log("dial: " + number);
1304 // No permission check needed here: This is just a wrapper around the
1305 // ACTION_DIAL intent, which is available to any app since it puts up
1306 // the UI before it does anything.
1307
Malcolm Chend965c8b2018-02-28 15:00:40 -08001308 final long identity = Binder.clearCallingIdentity();
1309 try {
1310 String url = createTelUrl(number);
1311 if (url == null) {
1312 return;
1313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314
Malcolm Chend965c8b2018-02-28 15:00:40 -08001315 // PENDING: should we just silently fail if phone is offhook or ringing?
1316 PhoneConstants.State state = mCM.getState(subId);
1317 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1318 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1319 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1320 mApp.startActivity(intent);
1321 }
1322 } finally {
1323 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 }
1325 }
1326
1327 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001328 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001329 }
1330
Wink Savilleb564aae2014-10-23 10:18:09 -07001331 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001332 if (DBG) log("call: " + number);
1333
1334 // This is just a wrapper around the ACTION_CALL intent, but we still
1335 // need to do a permission check since we're calling startActivity()
1336 // from the context of the phone app.
1337 enforceCallPermission();
1338
1339 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1340 != AppOpsManager.MODE_ALLOWED) {
1341 return;
1342 }
1343
Malcolm Chend965c8b2018-02-28 15:00:40 -08001344 final long identity = Binder.clearCallingIdentity();
1345 try {
1346 String url = createTelUrl(number);
1347 if (url == null) {
1348 return;
1349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001350
Malcolm Chend965c8b2018-02-28 15:00:40 -08001351 boolean isValid = false;
1352 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1353 if (slist != null) {
1354 for (SubscriptionInfo subInfoRecord : slist) {
1355 if (subInfoRecord.getSubscriptionId() == subId) {
1356 isValid = true;
1357 break;
1358 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001359 }
Wink Saville08874612014-08-31 19:19:58 -07001360 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001361 if (!isValid) {
1362 return;
1363 }
Wink Saville08874612014-08-31 19:19:58 -07001364
Malcolm Chend965c8b2018-02-28 15:00:40 -08001365 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1366 intent.putExtra(SUBSCRIPTION_KEY, subId);
1367 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1368 mApp.startActivity(intent);
1369 } finally {
1370 Binder.restoreCallingIdentity(identity);
1371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372 }
1373
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001376 }
1377
Wink Savilleb564aae2014-10-23 10:18:09 -07001378 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001379 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001380 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1381 }
1382
1383 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001384 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001385 }
1386
Wink Savilleb564aae2014-10-23 10:18:09 -07001387 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001388 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001389 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1390 }
1391
1392 /** {@hide} */
1393 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001394 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001395 }
1396
Wink Savilleb564aae2014-10-23 10:18:09 -07001397 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001398 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001399
1400 final long identity = Binder.clearCallingIdentity();
1401 try {
1402 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1403 checkSimPin.start();
1404 return checkSimPin.unlockSim(null, pin);
1405 } finally {
1406 Binder.restoreCallingIdentity(identity);
1407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001408 }
1409
Wink Saville9de0f752013-10-22 19:04:03 -07001410 /** {@hide} */
1411 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001412 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001413 }
1414
Wink Savilleb564aae2014-10-23 10:18:09 -07001415 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001416 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001417
1418 final long identity = Binder.clearCallingIdentity();
1419 try {
1420 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1421 checkSimPuk.start();
1422 return checkSimPuk.unlockSim(puk, pin);
1423 } finally {
1424 Binder.restoreCallingIdentity(identity);
1425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426 }
1427
1428 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001429 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001430 * a synchronous one.
1431 */
1432 private static class UnlockSim extends Thread {
1433
1434 private final IccCard mSimCard;
1435
1436 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001437 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1438 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001439
1440 // For replies from SimCard interface
1441 private Handler mHandler;
1442
1443 // For async handler to identify request type
1444 private static final int SUPPLY_PIN_COMPLETE = 100;
1445
1446 public UnlockSim(IccCard simCard) {
1447 mSimCard = simCard;
1448 }
1449
1450 @Override
1451 public void run() {
1452 Looper.prepare();
1453 synchronized (UnlockSim.this) {
1454 mHandler = new Handler() {
1455 @Override
1456 public void handleMessage(Message msg) {
1457 AsyncResult ar = (AsyncResult) msg.obj;
1458 switch (msg.what) {
1459 case SUPPLY_PIN_COMPLETE:
1460 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1461 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001462 mRetryCount = msg.arg1;
1463 if (ar.exception != null) {
1464 if (ar.exception instanceof CommandException &&
1465 ((CommandException)(ar.exception)).getCommandError()
1466 == CommandException.Error.PASSWORD_INCORRECT) {
1467 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1468 } else {
1469 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1470 }
1471 } else {
1472 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474 mDone = true;
1475 UnlockSim.this.notifyAll();
1476 }
1477 break;
1478 }
1479 }
1480 };
1481 UnlockSim.this.notifyAll();
1482 }
1483 Looper.loop();
1484 }
1485
1486 /*
1487 * Use PIN or PUK to unlock SIM card
1488 *
1489 * If PUK is null, unlock SIM card with PIN
1490 *
1491 * If PUK is not null, unlock SIM card with PUK and set PIN code
1492 */
Wink Saville9de0f752013-10-22 19:04:03 -07001493 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001494
1495 while (mHandler == null) {
1496 try {
1497 wait();
1498 } catch (InterruptedException e) {
1499 Thread.currentThread().interrupt();
1500 }
1501 }
1502 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1503
1504 if (puk == null) {
1505 mSimCard.supplyPin(pin, callback);
1506 } else {
1507 mSimCard.supplyPuk(puk, pin, callback);
1508 }
1509
1510 while (!mDone) {
1511 try {
1512 Log.d(LOG_TAG, "wait for done");
1513 wait();
1514 } catch (InterruptedException e) {
1515 // Restore the interrupted status
1516 Thread.currentThread().interrupt();
1517 }
1518 }
1519 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001520 int[] resultArray = new int[2];
1521 resultArray[0] = mResult;
1522 resultArray[1] = mRetryCount;
1523 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 }
1525 }
1526
1527 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001528 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001529
1530 }
1531
Wink Savilleb564aae2014-10-23 10:18:09 -07001532 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 // No permission check needed here: this call is harmless, and it's
1534 // needed for the ServiceState.requestStateUpdate() call (which is
1535 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001536 final long identity = Binder.clearCallingIdentity();
1537 try {
1538 final Phone phone = getPhone(subId);
1539 if (phone != null) {
1540 phone.updateServiceLocation();
1541 }
1542 } finally {
1543 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001545 }
1546
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001547 @Override
1548 public boolean isRadioOn(String callingPackage) {
1549 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001550 }
1551
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001552 @Override
1553 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001554 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001555 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001556 return false;
1557 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001558
1559 final long identity = Binder.clearCallingIdentity();
1560 try {
1561 return isRadioOnForSubscriber(subId);
1562 } finally {
1563 Binder.restoreCallingIdentity(identity);
1564 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001565 }
1566
1567 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001568 final long identity = Binder.clearCallingIdentity();
1569 try {
1570 final Phone phone = getPhone(subId);
1571 if (phone != null) {
1572 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1573 } else {
1574 return false;
1575 }
1576 } finally {
1577 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001578 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 }
1580
1581 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001582 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
Wink Saville36469e72014-06-11 15:17:00 -07001584
Wink Savilleb564aae2014-10-23 10:18:09 -07001585 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001587
1588 final long identity = Binder.clearCallingIdentity();
1589 try {
1590 final Phone phone = getPhone(subId);
1591 if (phone != null) {
1592 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1593 }
1594 } finally {
1595 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001596 }
Wink Saville36469e72014-06-11 15:17:00 -07001597 }
1598
1599 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001600 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001601 }
1602
Wink Savilleb564aae2014-10-23 10:18:09 -07001603 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001604 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001605
1606 final long identity = Binder.clearCallingIdentity();
1607 try {
1608 final Phone phone = getPhone(subId);
1609 if (phone == null) {
1610 return false;
1611 }
1612 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1613 toggleRadioOnOffForSubscriber(subId);
1614 }
1615 return true;
1616 } finally {
1617 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001619 }
Wink Saville36469e72014-06-11 15:17:00 -07001620
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001621 public boolean needMobileRadioShutdown() {
1622 /*
1623 * If any of the Radios are available, it will need to be
1624 * shutdown. So return true if any Radio is available.
1625 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001626 final long identity = Binder.clearCallingIdentity();
1627 try {
1628 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1629 Phone phone = PhoneFactory.getPhone(i);
1630 if (phone != null && phone.isRadioAvailable()) return true;
1631 }
1632 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1633 return false;
1634 } finally {
1635 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001636 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001637 }
1638
Malcolm Chend965c8b2018-02-28 15:00:40 -08001639 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001640 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001641 enforceModifyPermission();
1642
1643 final long identity = Binder.clearCallingIdentity();
1644 try {
1645 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1646 logv("Shutting down Phone " + i);
1647 shutdownRadioUsingPhoneId(i);
1648 }
1649 } finally {
1650 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001651 }
1652 }
1653
1654 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001655 Phone phone = PhoneFactory.getPhone(phoneId);
1656 if (phone != null && phone.isRadioAvailable()) {
1657 phone.shutdownRadio();
1658 }
1659 }
1660
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001662 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001663
1664 final long identity = Binder.clearCallingIdentity();
1665 try {
1666 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1667 if (defaultPhone != null) {
1668 defaultPhone.setRadioPower(turnOn);
1669 return true;
1670 } else {
1671 loge("There's no default phone.");
1672 return false;
1673 }
1674 } finally {
1675 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001676 }
Wink Saville36469e72014-06-11 15:17:00 -07001677 }
1678
Wink Savilleb564aae2014-10-23 10:18:09 -07001679 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001680 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001681
1682 final long identity = Binder.clearCallingIdentity();
1683 try {
1684 final Phone phone = getPhone(subId);
1685 if (phone != null) {
1686 phone.setRadioPower(turnOn);
1687 return true;
1688 } else {
1689 return false;
1690 }
1691 } finally {
1692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 }
1695
Wink Saville36469e72014-06-11 15:17:00 -07001696 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001697 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 public boolean enableDataConnectivity() {
1699 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001700
1701 final long identity = Binder.clearCallingIdentity();
1702 try {
1703 int subId = mSubscriptionController.getDefaultDataSubId();
1704 final Phone phone = getPhone(subId);
1705 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001706 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001707 return true;
1708 } else {
1709 return false;
1710 }
1711 } finally {
1712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 }
1715
Wink Saville36469e72014-06-11 15:17:00 -07001716 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001717 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 public boolean disableDataConnectivity() {
1719 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001720
1721 final long identity = Binder.clearCallingIdentity();
1722 try {
1723 int subId = mSubscriptionController.getDefaultDataSubId();
1724 final Phone phone = getPhone(subId);
1725 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001726 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001727 return true;
1728 } else {
1729 return false;
1730 }
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 }
1735
Sanket Padawe356d7632015-06-22 14:03:32 -07001736 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001737 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001738 final long identity = Binder.clearCallingIdentity();
1739 try {
1740 final Phone phone = getPhone(subId);
1741 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001742 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001743 } else {
1744 return false;
1745 }
1746 } finally {
1747 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 }
1750
1751 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001752 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001753 }
1754
pkanwarae03a6b2016-11-06 20:37:09 -08001755 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001756 enforceCallPermission();
1757
1758 final long identity = Binder.clearCallingIdentity();
1759 try {
1760 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1761 return;
1762 }
1763 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1764 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1765 } finally {
1766 Binder.restoreCallingIdentity(identity);
1767 }
pkanwar32d516d2016-10-14 19:37:38 -07001768 };
1769
Wink Savilleb564aae2014-10-23 10:18:09 -07001770 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001772
1773 final long identity = Binder.clearCallingIdentity();
1774 try {
1775 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1776 return false;
1777 }
1778 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1779 } finally {
1780 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001781 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001782 }
1783
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001785 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001786 }
1787
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001788 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001789 final long identity = Binder.clearCallingIdentity();
1790 try {
1791 Phone phone = PhoneFactory.getPhone(slotIndex);
1792 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1793 PhoneConstantConversions.convertCallState(phone.getState());
1794 } finally {
1795 Binder.restoreCallingIdentity(identity);
1796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 }
1798
Sanket Padawe356d7632015-06-22 14:03:32 -07001799 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001800 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001801 final long identity = Binder.clearCallingIdentity();
1802 try {
1803 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1804 if (phone != null) {
1805 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1806 } else {
1807 return PhoneConstantConversions.convertDataState(
1808 PhoneConstants.DataState.DISCONNECTED);
1809 }
1810 } finally {
1811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 }
1814
Sanket Padawe356d7632015-06-22 14:03:32 -07001815 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001817 final long identity = Binder.clearCallingIdentity();
1818 try {
1819 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1820 if (phone != null) {
1821 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1822 } else {
1823 return TelephonyManager.DATA_ACTIVITY_NONE;
1824 }
1825 } finally {
1826 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 }
1829
1830 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001831 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001832 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001833 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001834 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1835 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001836 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001837 }
1838
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001839 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001840 final long identity = Binder.clearCallingIdentity();
1841 try {
1842 if (DBG_LOC) log("getCellLocation: is active user");
1843 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001844 int subId = mSubscriptionController.getDefaultDataSubId();
1845 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1846 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001847 return data;
1848 } finally {
1849 Binder.restoreCallingIdentity(identity);
1850 }
Svetoslav64fad262015-04-14 14:35:21 -07001851 }
1852
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001854 public String getNetworkCountryIsoForPhone(int phoneId) {
1855 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1856 // registered cell info, so return a NULL country instead.
1857 final long identity = Binder.clearCallingIdentity();
1858 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001859 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1860 // Get default phone in this case.
1861 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1862 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001863 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001864 // Todo: fix this when we can get the actual cellular network info when the device
1865 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001866 if (TelephonyManager.NETWORK_TYPE_IWLAN
1867 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1868 return "";
1869 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001870 Phone phone = PhoneFactory.getPhone(phoneId);
1871 if (phone != null) {
1872 ServiceStateTracker sst = phone.getServiceStateTracker();
1873 if (sst != null) {
1874 LocaleTracker lt = sst.getLocaleTracker();
1875 if (lt != null) {
1876 return lt.getCurrentCountry();
1877 }
1878 }
1879 }
1880 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001881 } finally {
1882 Binder.restoreCallingIdentity(identity);
1883 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001884 }
1885
1886 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001888 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001889 }
1890
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001892 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 mApp.enforceCallingOrSelfPermission(
1894 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001895
1896 final long identity = Binder.clearCallingIdentity();
1897 try {
1898 final Phone phone = getPhone(subId);
1899 if (phone != null) {
1900 phone.enableLocationUpdates();
1901 }
1902 } finally {
1903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
1907 @Override
1908 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001909 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001910 }
1911
Sanket Padawe356d7632015-06-22 14:03:32 -07001912 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001913 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 mApp.enforceCallingOrSelfPermission(
1915 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001916
1917 final long identity = Binder.clearCallingIdentity();
1918 try {
1919 final Phone phone = getPhone(subId);
1920 if (phone != null) {
1921 phone.disableLocationUpdates();
1922 }
1923 } finally {
1924 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001925 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 }
1927
Nathan Harold31d7ff32018-10-15 20:20:30 -07001928 /**
1929 * Returns the target SDK version number for a given package name.
1930 *
1931 * @return target SDK if the package is found or INT_MAX.
1932 */
1933 private int getTargetSdk(String packageName) {
1934 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001935 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1936 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001937 if (ai != null) return ai.targetSdkVersion;
1938 } catch (PackageManager.NameNotFoundException unexpected) {
1939 }
1940 return Integer.MAX_VALUE;
1941 }
1942
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 @Override
1944 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001945 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1946 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001947 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1948 throw new SecurityException(
1949 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1950 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001951
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1953 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1954 return null;
1955 }
Svetoslav64fad262015-04-14 14:35:21 -07001956
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001957 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958
Nathan Haroldf180aac2018-06-01 18:43:55 -07001959 List<CellInfo> info = getAllCellInfo(callingPackage);
1960 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961
Nathan Haroldf180aac2018-06-01 18:43:55 -07001962 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1963 for (CellInfo ci : info) {
1964 if (ci instanceof CellInfoGsm) {
1965 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1966 } else if (ci instanceof CellInfoWcdma) {
1967 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1968 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001970 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971 }
1972
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001973 private List<CellInfo> getCachedCellInfo() {
1974 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1975 for (Phone phone : PhoneFactory.getPhones()) {
1976 List<CellInfo> info = phone.getAllCellInfo();
1977 if (info != null) cellInfos.addAll(info);
1978 }
1979 return cellInfos;
1980 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981
1982 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001983 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001984 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001985 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001986 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001987 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001988 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001991 final int targetSdk = getTargetSdk(callingPackage);
1992 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1993 return getCachedCellInfo();
1994 }
1995
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001996 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001997 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001998 final long identity = Binder.clearCallingIdentity();
1999 try {
2000 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2001 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002002 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002003 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002004 if (info != null) cellInfos.addAll(info);
2005 }
2006 return cellInfos;
2007 } finally {
2008 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010 }
2011
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002012 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002013 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2014 requestCellInfoUpdateInternal(
2015 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2016 }
2017
2018 @Override
2019 public void requestCellInfoUpdateWithWorkSource(
2020 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2021 enforceModifyPermission();
2022 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2023 }
2024
2025 private void requestCellInfoUpdateInternal(
2026 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002027 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002028 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002029 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2030 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002031 return;
2032 }
2033
2034 final Phone phone = getPhone(subId);
2035 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2036
2037 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2038 }
2039
2040 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002042 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002043 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002044
2045 final long identity = Binder.clearCallingIdentity();
2046 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002047 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002048 } finally {
2049 Binder.restoreCallingIdentity(identity);
2050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 }
2052
Shishir Agrawala9f32182016-04-12 12:00:16 -07002053 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002054 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002055 Phone phone = PhoneFactory.getPhone(slotIndex);
2056 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002057 return null;
2058 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002059 int subId = phone.getSubId();
2060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2061 mApp, subId, callingPackage, "getImeiForSlot")) {
2062 return null;
2063 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002064
2065 final long identity = Binder.clearCallingIdentity();
2066 try {
2067 return phone.getImei();
2068 } finally {
2069 Binder.restoreCallingIdentity(identity);
2070 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002071 }
2072
2073 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002074 public String getTypeAllocationCodeForSlot(int slotIndex) {
2075 Phone phone = PhoneFactory.getPhone(slotIndex);
2076 String tac = null;
2077 if (phone != null) {
2078 String imei = phone.getImei();
2079 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2080 }
2081 return tac;
2082 }
2083
2084 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002085 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002086 Phone phone = PhoneFactory.getPhone(slotIndex);
2087 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002088 return null;
2089 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002090
Jeff Davidson913390f2018-02-23 17:11:49 -08002091 int subId = phone.getSubId();
2092 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2093 mApp, subId, callingPackage, "getMeidForSlot")) {
2094 return null;
2095 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002096
2097 final long identity = Binder.clearCallingIdentity();
2098 try {
2099 return phone.getMeid();
2100 } finally {
2101 Binder.restoreCallingIdentity(identity);
2102 }
Jack Yu2af8d712017-03-15 17:14:14 -07002103 }
2104
2105 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002106 public String getManufacturerCodeForSlot(int slotIndex) {
2107 Phone phone = PhoneFactory.getPhone(slotIndex);
2108 String manufacturerCode = null;
2109 if (phone != null) {
2110 String meid = phone.getMeid();
2111 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2112 }
2113 return manufacturerCode;
2114 }
2115
2116 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002117 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002118 Phone phone = PhoneFactory.getPhone(slotIndex);
2119 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002120 return null;
2121 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002122 int subId = phone.getSubId();
2123 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2124 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2125 return null;
2126 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002127
2128 final long identity = Binder.clearCallingIdentity();
2129 try {
2130 return phone.getDeviceSvn();
2131 } finally {
2132 Binder.restoreCallingIdentity(identity);
2133 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002134 }
2135
fionaxu43304da2017-11-27 22:51:16 -08002136 @Override
2137 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002138 final long identity = Binder.clearCallingIdentity();
2139 try {
2140 final Phone phone = getPhone(subId);
2141 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2142 } finally {
2143 Binder.restoreCallingIdentity(identity);
2144 }
fionaxu43304da2017-11-27 22:51:16 -08002145 }
2146
2147 @Override
2148 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002149 final long identity = Binder.clearCallingIdentity();
2150 try {
2151 final Phone phone = getPhone(subId);
2152 return phone == null ? null : phone.getCarrierName();
2153 } finally {
2154 Binder.restoreCallingIdentity(identity);
2155 }
fionaxu43304da2017-11-27 22:51:16 -08002156 }
2157
calvinpaneed9ae82018-11-01 19:43:06 +08002158 @Override
chen xuc93cc282018-11-04 17:17:00 -08002159 public int getSubscriptionPreciseCarrierId(int subId) {
2160 final long identity = Binder.clearCallingIdentity();
2161 try {
2162 final Phone phone = getPhone(subId);
2163 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2164 : phone.getPreciseCarrierId();
2165 } finally {
2166 Binder.restoreCallingIdentity(identity);
2167 }
2168 }
2169
2170 @Override
2171 public String getSubscriptionPreciseCarrierName(int subId) {
2172 final long identity = Binder.clearCallingIdentity();
2173 try {
2174 final Phone phone = getPhone(subId);
2175 return phone == null ? null : phone.getPreciseCarrierName();
2176 } finally {
2177 Binder.restoreCallingIdentity(identity);
2178 }
2179 }
2180
chen xu02581692018-11-11 19:03:44 -08002181 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002182 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2183 if (!isSubscriptionMccMnc) {
2184 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2185 }
chen xu02581692018-11-11 19:03:44 -08002186 final Phone phone = PhoneFactory.getPhone(slotIndex);
2187 if (phone == null) {
2188 return TelephonyManager.UNKNOWN_CARRIER_ID;
2189 }
2190 final long identity = Binder.clearCallingIdentity();
2191 try {
2192 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2193 } finally {
2194 Binder.restoreCallingIdentity(identity);
2195 }
2196 }
2197
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 //
2199 // Internal helper methods.
2200 //
2201
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002202 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2204 *
2205 * @throws SecurityException if the caller does not have the required permission
2206 */
2207 private void enforceModifyPermission() {
2208 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2209 }
2210
2211 /**
2212 * Make sure the caller has the CALL_PHONE permission.
2213 *
2214 * @throws SecurityException if the caller does not have the required permission
2215 */
2216 private void enforceCallPermission() {
2217 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2218 }
2219
Stuart Scott8eef64f2015-04-08 15:13:54 -07002220 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002221 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002222 "ConnectivityService");
2223 }
2224
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 private String createTelUrl(String number) {
2226 if (TextUtils.isEmpty(number)) {
2227 return null;
2228 }
2229
Jake Hambye994d462014-02-03 13:10:13 -08002230 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 }
2232
Ihab Awadf9e92732013-12-05 18:02:52 -08002233 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2235 }
2236
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002237 private static void logv(String msg) {
2238 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2239 }
2240
Ihab Awadf9e92732013-12-05 18:02:52 -08002241 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2243 }
2244
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002245 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002247 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002248 }
2249
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002251 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002252 final long identity = Binder.clearCallingIdentity();
2253 try {
2254 final Phone phone = PhoneFactory.getPhone(slotIndex);
2255 if (phone == null) {
2256 return PhoneConstants.PHONE_TYPE_NONE;
2257 } else {
2258 return phone.getPhoneType();
2259 }
2260 } finally {
2261 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 }
2264
2265 /**
2266 * Returns the CDMA ERI icon index to display
2267 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002268 @Override
2269 public int getCdmaEriIconIndex(String callingPackage) {
2270 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002271 }
2272
Sanket Padawe356d7632015-06-22 14:03:32 -07002273 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002274 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002276 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002277 return -1;
2278 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002279
2280 final long identity = Binder.clearCallingIdentity();
2281 try {
2282 final Phone phone = getPhone(subId);
2283 if (phone != null) {
2284 return phone.getCdmaEriIconIndex();
2285 } else {
2286 return -1;
2287 }
2288 } finally {
2289 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 }
2292
2293 /**
2294 * Returns the CDMA ERI icon mode,
2295 * 0 - ON
2296 * 1 - FLASHING
2297 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002298 @Override
2299 public int getCdmaEriIconMode(String callingPackage) {
2300 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002301 }
2302
Sanket Padawe356d7632015-06-22 14:03:32 -07002303 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002304 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002306 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002307 return -1;
2308 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002309
2310 final long identity = Binder.clearCallingIdentity();
2311 try {
2312 final Phone phone = getPhone(subId);
2313 if (phone != null) {
2314 return phone.getCdmaEriIconMode();
2315 } else {
2316 return -1;
2317 }
2318 } finally {
2319 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321 }
2322
2323 /**
2324 * Returns the CDMA ERI text,
2325 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002326 @Override
2327 public String getCdmaEriText(String callingPackage) {
2328 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002329 }
2330
Sanket Padawe356d7632015-06-22 14:03:32 -07002331 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002332 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002333 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002334 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002335 return null;
2336 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002337
2338 final long identity = Binder.clearCallingIdentity();
2339 try {
2340 final Phone phone = getPhone(subId);
2341 if (phone != null) {
2342 return phone.getCdmaEriText();
2343 } else {
2344 return null;
2345 }
2346 } finally {
2347 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 }
2350
2351 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002352 * Returns the CDMA MDN.
2353 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002354 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002355 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2357 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002358
2359 final long identity = Binder.clearCallingIdentity();
2360 try {
2361 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002362 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002363 return phone.getLine1Number();
2364 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002365 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002366 return null;
2367 }
2368 } finally {
2369 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002370 }
2371 }
2372
2373 /**
2374 * Returns the CDMA MIN.
2375 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002376 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002377 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2379 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002380
2381 final long identity = Binder.clearCallingIdentity();
2382 try {
2383 final Phone phone = getPhone(subId);
2384 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2385 return phone.getCdmaMin();
2386 } else {
2387 return null;
2388 }
2389 } finally {
2390 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002391 }
2392 }
2393
Hall Liud892bec2018-11-30 14:51:45 -08002394 @Override
2395 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2396 INumberVerificationCallback callback, String callingPackage) {
2397 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2398 != PERMISSION_GRANTED) {
2399 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2400 }
2401 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2402
2403 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2404 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2405 throw new SecurityException("Calling package must be configured in the device config");
2406 }
2407
2408 if (range == null) {
2409 throw new NullPointerException("Range must be non-null");
2410 }
2411
2412 timeoutMillis = Math.min(timeoutMillis,
2413 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2414
2415 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2416 }
2417
Junda Liuca05d5d2014-08-14 22:36:34 -07002418 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 * Returns true if CDMA provisioning needs to run.
2420 */
2421 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002422 final long identity = Binder.clearCallingIdentity();
2423 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002424 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002425 } finally {
2426 Binder.restoreCallingIdentity(identity);
2427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 }
2429
2430 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002431 * Sets the voice mail number of a given subId.
2432 */
2433 @Override
2434 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002435 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002436
2437 final long identity = Binder.clearCallingIdentity();
2438 try {
2439 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2440 new Pair<String, String>(alphaTag, number), new Integer(subId));
2441 return success;
2442 } finally {
2443 Binder.restoreCallingIdentity(identity);
2444 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002445 }
2446
Ta-wei Yen87c49842016-05-13 21:19:52 -07002447 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002448 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2449 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002450 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002451 if (!TextUtils.equals(callingPackage, systemDialer)) {
2452 throw new SecurityException("caller must be system dialer");
2453 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002454
2455 final long identity = Binder.clearCallingIdentity();
2456 try {
2457 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2458 if (phoneAccountHandle == null) {
2459 return null;
2460 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002461 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002462 } finally {
2463 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002464 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002465 }
2466
2467 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002468 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002469 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002471 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002472 return null;
2473 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002474
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002475 final long identity = Binder.clearCallingIdentity();
2476 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002477 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002478 } finally {
2479 Binder.restoreCallingIdentity(identity);
2480 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002481 }
2482
2483 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002484 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2485 VisualVoicemailSmsFilterSettings settings) {
2486 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002487
2488 final long identity = Binder.clearCallingIdentity();
2489 try {
2490 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002491 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002492 } finally {
2493 Binder.restoreCallingIdentity(identity);
2494 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002495 }
2496
2497 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002498 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2499 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002500
2501 final long identity = Binder.clearCallingIdentity();
2502 try {
2503 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002504 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002505 } finally {
2506 Binder.restoreCallingIdentity(identity);
2507 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002508 }
2509
2510 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002511 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2512 String callingPackage, int subId) {
2513 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002514
2515 final long identity = Binder.clearCallingIdentity();
2516 try {
2517 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002518 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002519 } finally {
2520 Binder.restoreCallingIdentity(identity);
2521 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002522 }
2523
2524 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002525 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002526 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002527
2528 final long identity = Binder.clearCallingIdentity();
2529 try {
2530 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002531 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002532 } finally {
2533 Binder.restoreCallingIdentity(identity);
2534 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002535 }
2536
2537 @Override
2538 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2539 String number, int port, String text, PendingIntent sentIntent) {
2540 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002541 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002542 enforceSendSmsPermission();
2543 // Make the calls as the phone process.
2544 final long identity = Binder.clearCallingIdentity();
2545 try {
2546 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2547 if (port == 0) {
2548 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2549 sentIntent, null, false);
2550 } else {
2551 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2552 smsManager.sendDataMessageWithSelfPermissions(number, null,
2553 (short) port, data, sentIntent, null);
2554 }
2555 } finally {
2556 Binder.restoreCallingIdentity(identity);
2557 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002558 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002559 /**
fionaxu0152e512016-11-14 13:36:14 -08002560 * Sets the voice activation state of a given subId.
2561 */
2562 @Override
2563 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2565 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002566
2567 final long identity = Binder.clearCallingIdentity();
2568 try {
2569 final Phone phone = getPhone(subId);
2570 if (phone != null) {
2571 phone.setVoiceActivationState(activationState);
2572 } else {
2573 loge("setVoiceActivationState fails with invalid subId: " + subId);
2574 }
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002577 }
2578 }
2579
2580 /**
2581 * Sets the data activation state of a given subId.
2582 */
2583 @Override
2584 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2586 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002587
2588 final long identity = Binder.clearCallingIdentity();
2589 try {
2590 final Phone phone = getPhone(subId);
2591 if (phone != null) {
2592 phone.setDataActivationState(activationState);
2593 } else {
2594 loge("setVoiceActivationState fails with invalid subId: " + subId);
2595 }
2596 } finally {
2597 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002598 }
2599 }
2600
2601 /**
2602 * Returns the voice activation state of a given subId.
2603 */
2604 @Override
2605 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002606 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002607
fionaxu0152e512016-11-14 13:36:14 -08002608 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002609 final long identity = Binder.clearCallingIdentity();
2610 try {
2611 if (phone != null) {
2612 return phone.getVoiceActivationState();
2613 } else {
2614 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2615 }
2616 } finally {
2617 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002618 }
2619 }
2620
2621 /**
2622 * Returns the data activation state of a given subId.
2623 */
2624 @Override
2625 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002626 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002627
fionaxu0152e512016-11-14 13:36:14 -08002628 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002629 final long identity = Binder.clearCallingIdentity();
2630 try {
2631 if (phone != null) {
2632 return phone.getDataActivationState();
2633 } else {
2634 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2635 }
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002638 }
2639 }
2640
2641 /**
Wink Saville36469e72014-06-11 15:17:00 -07002642 * Returns the unread count of voicemails for a subId
2643 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002644 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002645 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2646 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2647 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2648 return 0;
2649 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002650 final long identity = Binder.clearCallingIdentity();
2651 try {
2652 final Phone phone = getPhone(subId);
2653 if (phone != null) {
2654 return phone.getVoiceMessageCount();
2655 } else {
2656 return 0;
2657 }
2658 } finally {
2659 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002660 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 }
2662
2663 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002664 * returns true, if the device is in a state where both voice and data
2665 * are supported simultaneously. This can change based on location or network condition.
2666 */
2667 @Override
2668 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002669 final long identity = Binder.clearCallingIdentity();
2670 try {
2671 final Phone phone = getPhone(subId);
2672 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
2675 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002676 }
2677
2678 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002679 * Send the dialer code if called from the current default dialer or the caller has
2680 * carrier privilege.
2681 * @param inputCode The dialer code to send
2682 */
2683 @Override
2684 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002685 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002686 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002687 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2688 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002689 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002690 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2691 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002692 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002693
2694 final long identity = Binder.clearCallingIdentity();
2695 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002696 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002697 } finally {
2698 Binder.restoreCallingIdentity(identity);
2699 }
fionaxu235cc5e2017-03-06 22:25:57 -08002700 }
2701
2702 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002703 * Returns the data network type.
2704 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 *
2706 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2707 */
2708 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002709 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002710 final long identity = Binder.clearCallingIdentity();
2711 try {
2712 final Phone phone = getPhone(getDefaultSubscription());
2713 if (phone != null) {
2714 return phone.getServiceState().getDataNetworkType();
2715 } else {
2716 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2717 }
2718 } finally {
2719 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002720 }
Wink Saville36469e72014-06-11 15:17:00 -07002721 }
2722
Pengquan Meng0c05b502018-09-06 09:59:22 -07002723 @Override
2724 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002725 if (!isActiveSubscription(subId)) {
2726 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2727 }
2728
Pengquan Meng0c05b502018-09-06 09:59:22 -07002729 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2730 }
2731
Brad Ebinger4c460712018-10-01 10:40:55 -07002732 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002733 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2734 throws RemoteException {
2735 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002736 final long token = Binder.clearCallingIdentity();
2737 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002738 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002739 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002740 .addRegistrationCallbackForSubscription(c, subId);
2741 } finally {
2742 Binder.restoreCallingIdentity(token);
2743 }
2744 }
2745
2746 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002747 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2748 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002749 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2750 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2751 }
2752 Binder.withCleanCallingIdentity(() -> {
2753 try {
2754 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002755 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002756 .removeRegistrationCallbackForSubscription(c, subId);
2757 } catch (IllegalArgumentException e) {
2758 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2759 + "is inactive, ignoring unregister.");
2760 // If the subscription is no longer active, just return, since the callback
2761 // will already have been removed internally.
2762 }
2763 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002764 }
2765
2766 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002767 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2768 throws RemoteException {
2769 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002770 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2771 final long token = Binder.clearCallingIdentity();
2772 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002773 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002774 .addCapabilitiesCallbackForSubscription(c, subId);
2775 } finally {
2776 Binder.restoreCallingIdentity(token);
2777 }
2778 }
2779
2780 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002781 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2782 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002783
2784 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2785 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2786 }
2787 Binder.withCleanCallingIdentity(() -> {
2788 try {
2789 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002790 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002791 .removeCapabilitiesCallbackForSubscription(c, subId);
2792 } catch (IllegalArgumentException e) {
2793 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2794 + "is inactive, ignoring unregister.");
2795 // If the subscription is no longer active, just return, since the callback
2796 // will already have been removed internally.
2797 }
2798 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002799 }
2800
2801 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002802 public boolean isCapable(int subId, int capability, int regTech) {
2803 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002804 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2805 final long token = Binder.clearCallingIdentity();
2806 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002807 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002808 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2809 } catch (ImsException e) {
2810 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2811 return false;
2812 } finally {
2813 Binder.restoreCallingIdentity(token);
2814 }
2815 }
2816
2817 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002818 public boolean isAvailable(int subId, int capability, int regTech) {
2819 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002820 final long token = Binder.clearCallingIdentity();
2821 try {
2822 Phone phone = getPhone(subId);
2823 if (phone == null) return false;
2824 return phone.isImsCapabilityAvailable(capability, regTech);
2825 } finally {
2826 Binder.restoreCallingIdentity(token);
2827 }
2828 }
2829
2830 @Override
2831 public boolean isAdvancedCallingSettingEnabled(int subId) {
2832 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2833 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2834 final long token = Binder.clearCallingIdentity();
2835 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002836 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002837 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2838 } finally {
2839 Binder.restoreCallingIdentity(token);
2840 }
2841 }
2842
2843 @Override
2844 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2846 "setAdvancedCallingSetting");
2847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002850 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002851 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
2854 }
2855 }
2856
2857 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002858 public boolean isVtSettingEnabled(int subId) {
2859 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002863 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002864 getSlotIndexOrException(subId)).isVtEnabledByUser();
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
2867 }
2868 }
2869
2870 @Override
2871 public void setVtSetting(int subId, boolean isEnabled) {
2872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2873 "setVtSetting");
2874 final long identity = Binder.clearCallingIdentity();
2875 try {
2876 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002877 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002878 } finally {
2879 Binder.restoreCallingIdentity(identity);
2880 }
2881 }
2882
2883 @Override
2884 public boolean isVoWiFiSettingEnabled(int subId) {
2885 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2886 final long identity = Binder.clearCallingIdentity();
2887 try {
2888 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002889 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002890 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2891 } finally {
2892 Binder.restoreCallingIdentity(identity);
2893 }
2894 }
2895
2896 @Override
2897 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2899 "setVoWiFiSetting");
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002903 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002904 } finally {
2905 Binder.restoreCallingIdentity(identity);
2906 }
2907 }
2908
2909 @Override
2910 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2911 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2912 final long identity = Binder.clearCallingIdentity();
2913 try {
2914 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002915 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002916 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
2919 }
2920 }
2921
2922 @Override
2923 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2924 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2925 "setVoWiFiRoamingSetting");
2926 final long identity = Binder.clearCallingIdentity();
2927 try {
2928 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002929 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002930 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2931 } finally {
2932 Binder.restoreCallingIdentity(identity);
2933 }
2934 }
2935
2936 @Override
2937 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2939 "setVoWiFiNonPersistent");
2940 final long identity = Binder.clearCallingIdentity();
2941 try {
2942 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002943 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002944 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
2947 }
2948 }
2949
2950 @Override
2951 public int getVoWiFiModeSetting(int subId) {
2952 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002956 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002957 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2958 } finally {
2959 Binder.restoreCallingIdentity(identity);
2960 }
2961 }
2962
2963 @Override
2964 public void setVoWiFiModeSetting(int subId, int mode) {
2965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2966 "setVoWiFiModeSetting");
2967 final long identity = Binder.clearCallingIdentity();
2968 try {
2969 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002970 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002971 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
2974 }
2975 }
2976
2977 @Override
2978 public int getVoWiFiRoamingModeSetting(int subId) {
2979 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002983 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002984 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
2988 }
2989
2990 @Override
2991 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2993 "setVoWiFiRoamingModeSetting");
2994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002997 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002998 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2999 } finally {
3000 Binder.restoreCallingIdentity(identity);
3001 }
3002 }
3003
3004 @Override
3005 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3007 "setRttCapabilityEnabled");
3008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003011 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003012 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3013 } finally {
3014 Binder.restoreCallingIdentity(identity);
3015 }
3016 }
3017
3018 @Override
3019 public boolean isTtyOverVolteEnabled(int subId) {
3020 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3021 final long identity = Binder.clearCallingIdentity();
3022 try {
3023 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003024 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003025 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3026 } finally {
3027 Binder.restoreCallingIdentity(identity);
3028 }
3029 }
3030
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003031 @Override
3032 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3033 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003037 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003038 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003039 } finally {
3040 Binder.restoreCallingIdentity(identity);
3041 }
3042 }
3043
3044 @Override
3045 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3046 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3047 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003048 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3049 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3050 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003051 try {
3052 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003053 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003054 .removeProvisioningCallbackForSubscription(callback, subId);
3055 } catch (IllegalArgumentException e) {
3056 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3057 + "is inactive, ignoring unregister.");
3058 // If the subscription is no longer active, just return, since the callback will already
3059 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003060 } finally {
3061 Binder.restoreCallingIdentity(identity);
3062 }
3063 }
3064
3065 @Override
3066 public int getImsProvisioningInt(int subId, int key) {
3067 enforceReadPrivilegedPermission("getImsProvisioningInt");
3068 final long identity = Binder.clearCallingIdentity();
3069 try {
3070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003071 return ImsManager.getInstance(mApp,
3072 getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003073 } catch (ImsException e) {
3074 throw new IllegalArgumentException(e.getMessage());
3075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
3078 }
3079
3080 @Override
3081 public String getImsProvisioningString(int subId, int key) {
3082 enforceReadPrivilegedPermission("getImsProvisioningString");
3083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003086 return ImsManager.getInstance(mApp,
3087 getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003088 } catch (ImsException e) {
3089 throw new IllegalArgumentException(e.getMessage());
3090 } finally {
3091 Binder.restoreCallingIdentity(identity);
3092 }
3093 }
3094
3095 @Override
3096 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3098 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003099 final long identity = Binder.clearCallingIdentity();
3100 try {
3101 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003102 return ImsManager.getInstance(mApp,
3103 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003104 } catch (ImsException e) {
3105 throw new IllegalArgumentException(e.getMessage());
3106 } finally {
3107 Binder.restoreCallingIdentity(identity);
3108 }
3109 }
3110
3111 @Override
3112 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3114 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003118 return ImsManager.getInstance(mApp,
3119 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003120 } catch (ImsException e) {
3121 throw new IllegalArgumentException(e.getMessage());
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
3125 }
3126
Brad Ebinger4c460712018-10-01 10:40:55 -07003127 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3128 int slotId = SubscriptionManager.getSlotIndex(subId);
3129 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3130 throw new IllegalArgumentException("Invalid Subscription Id.");
3131 }
3132 return slotId;
3133 }
3134
Wink Saville36469e72014-06-11 15:17:00 -07003135 /**
3136 * Returns the network type for a subId
3137 */
3138 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003139 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003140 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003141 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003142 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3143 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003144
Malcolm Chend965c8b2018-02-28 15:00:40 -08003145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 final Phone phone = getPhone(subId);
3148 if (phone != null) {
3149 return phone.getServiceState().getDataNetworkType();
3150 } else {
3151 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3152 }
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003156 }
3157
3158 /**
3159 * Returns the data network type
3160 */
3161 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003162 public int getDataNetworkType(String callingPackage) {
3163 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003164 }
3165
3166 /**
3167 * Returns the data network type for a subId
3168 */
3169 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003170 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003171 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003172 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003173 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3174 }
3175
Malcolm Chend965c8b2018-02-28 15:00:40 -08003176 final long identity = Binder.clearCallingIdentity();
3177 try {
3178 final Phone phone = getPhone(subId);
3179 if (phone != null) {
3180 return phone.getServiceState().getDataNetworkType();
3181 } else {
3182 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3183 }
3184 } finally {
3185 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003186 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003187 }
3188
3189 /**
Wink Saville36469e72014-06-11 15:17:00 -07003190 * Returns the Voice network type for a subId
3191 */
3192 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003193 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003194 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003195 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003196 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3197 }
3198
Malcolm Chend965c8b2018-02-28 15:00:40 -08003199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 final Phone phone = getPhone(subId);
3202 if (phone != null) {
3203 return phone.getServiceState().getVoiceNetworkType();
3204 } else {
3205 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3206 }
3207 } finally {
3208 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003210 }
3211
3212 /**
3213 * @return true if a ICC card is present
3214 */
3215 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003216 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003217 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3218 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003219 }
3220
3221 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003222 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003223 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003224 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003225 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003226 final long identity = Binder.clearCallingIdentity();
3227 try {
3228 final Phone phone = PhoneFactory.getPhone(slotIndex);
3229 if (phone != null) {
3230 return phone.getIccCard().hasIccCard();
3231 } else {
3232 return false;
3233 }
3234 } finally {
3235 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003237 }
3238
3239 /**
3240 * Return if the current radio is LTE on CDMA. This
3241 * is a tri-state return value as for a period of time
3242 * the mode may be unknown.
3243 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003244 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003245 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003246 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003247 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003248 @Override
3249 public int getLteOnCdmaMode(String callingPackage) {
3250 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003251 }
3252
Sanket Padawe356d7632015-06-22 14:03:32 -07003253 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003254 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003256 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003257 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3258 }
3259
Malcolm Chend965c8b2018-02-28 15:00:40 -08003260 final long identity = Binder.clearCallingIdentity();
3261 try {
3262 final Phone phone = getPhone(subId);
3263 if (phone == null) {
3264 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3265 } else {
3266 return phone.getLteOnCdmaMode();
3267 }
3268 } finally {
3269 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003270 }
Wink Saville36469e72014-06-11 15:17:00 -07003271 }
3272
Wink Saville36469e72014-06-11 15:17:00 -07003273 /**
3274 * {@hide}
3275 * Returns Default subId, 0 in the case of single standby.
3276 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003277 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003278 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003279 }
3280
Shishir Agrawala9f32182016-04-12 12:00:16 -07003281 private int getSlotForDefaultSubscription() {
3282 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3283 }
3284
Wink Savilleb564aae2014-10-23 10:18:09 -07003285 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003286 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003287 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003288
Pengquan Meng466e2482018-09-21 15:54:48 -07003289 private boolean isActiveSubscription(int subId) {
3290 return mSubscriptionController.isActiveSubId(subId);
3291 }
3292
Ihab Awadf2177b72013-11-25 13:33:23 -08003293 /**
3294 * @see android.telephony.TelephonyManager.WifiCallingChoices
3295 */
3296 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003297 final long identity = Binder.clearCallingIdentity();
3298 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003299 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003300 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3301 getWhenToMakeWifiCallsDefaultPreference());
3302 } finally {
3303 Binder.restoreCallingIdentity(identity);
3304 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003305 }
3306
3307 /**
3308 * @see android.telephony.TelephonyManager.WifiCallingChoices
3309 */
3310 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003314 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003315 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3316 } finally {
3317 Binder.restoreCallingIdentity(identity);
3318 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003319 }
3320
Sailesh Nepald1e68152013-12-12 19:08:02 -08003321 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003322 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003323 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003324 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003325
Shishir Agrawal566b7612013-10-28 14:41:00 -07003326 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003327 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3328 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3330 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003331 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003332
Malcolm Chend965c8b2018-02-28 15:00:40 -08003333 final long identity = Binder.clearCallingIdentity();
3334 try {
3335 if (TextUtils.equals(ISDR_AID, aid)) {
3336 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003337 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3338 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003339 if (bestComponent == null
3340 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3341 loge("The calling package is not allowed to access ISD-R.");
3342 throw new SecurityException(
3343 "The calling package is not allowed to access ISD-R.");
3344 }
Derek Tan740e1672017-06-27 14:56:27 -07003345 }
Derek Tan740e1672017-06-27 14:56:27 -07003346
Malcolm Chend965c8b2018-02-28 15:00:40 -08003347 if (DBG) {
3348 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3349 }
3350 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3351 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3352 if (DBG) log("iccOpenLogicalChannel: " + response);
3353 return response;
3354 } finally {
3355 Binder.restoreCallingIdentity(identity);
3356 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003357 }
3358
3359 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003360 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3362 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003363
Malcolm Chend965c8b2018-02-28 15:00:40 -08003364 final long identity = Binder.clearCallingIdentity();
3365 try {
3366 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3367 if (channel < 0) {
3368 return false;
3369 }
3370 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3371 if (DBG) log("iccCloseLogicalChannel: " + success);
3372 return success;
3373 } finally {
3374 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003375 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003376 }
3377
3378 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003379 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003380 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3382 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003383
Malcolm Chend965c8b2018-02-28 15:00:40 -08003384 final long identity = Binder.clearCallingIdentity();
3385 try {
3386 if (DBG) {
3387 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3388 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3389 + p3 + " data=" + data);
3390 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003391
Malcolm Chend965c8b2018-02-28 15:00:40 -08003392 if (channel < 0) {
3393 return "";
3394 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003395
Malcolm Chend965c8b2018-02-28 15:00:40 -08003396 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3397 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3398 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003399
Malcolm Chend965c8b2018-02-28 15:00:40 -08003400 // Append the returned status code to the end of the response payload.
3401 String s = Integer.toHexString(
3402 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3403 if (response.payload != null) {
3404 s = IccUtils.bytesToHexString(response.payload) + s;
3405 }
3406 return s;
3407 } finally {
3408 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003409 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003410 }
Jake Hambye994d462014-02-03 13:10:13 -08003411
Evan Charltonc66da362014-05-16 14:06:40 -07003412 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003413 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3414 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3416 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003417 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003418
Malcolm Chend965c8b2018-02-28 15:00:40 -08003419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3422 && TextUtils.equals(ISDR_AID, data)) {
3423 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003424 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3425 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003426 if (bestComponent == null
3427 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3428 loge("The calling package is not allowed to select ISD-R.");
3429 throw new SecurityException(
3430 "The calling package is not allowed to select ISD-R.");
3431 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003432 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003433
Malcolm Chend965c8b2018-02-28 15:00:40 -08003434 if (DBG) {
3435 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3436 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3437 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003438
Malcolm Chend965c8b2018-02-28 15:00:40 -08003439 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3440 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3441 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003442
Malcolm Chend965c8b2018-02-28 15:00:40 -08003443 // Append the returned status code to the end of the response payload.
3444 String s = Integer.toHexString(
3445 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3446 if (response.payload != null) {
3447 s = IccUtils.bytesToHexString(response.payload) + s;
3448 }
3449 return s;
3450 } finally {
3451 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003452 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003453 }
3454
3455 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003456 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003457 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3459 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003460
Malcolm Chend965c8b2018-02-28 15:00:40 -08003461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 if (DBG) {
3464 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3465 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3466 }
3467
3468 IccIoResult response =
3469 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3470 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3471 subId);
3472
3473 if (DBG) {
3474 log("Exchange SIM_IO [R]" + response);
3475 }
3476
3477 byte[] result = null;
3478 int length = 2;
3479 if (response.payload != null) {
3480 length = 2 + response.payload.length;
3481 result = new byte[length];
3482 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3483 } else {
3484 result = new byte[length];
3485 }
3486
3487 result[length - 1] = (byte) response.sw2;
3488 result[length - 2] = (byte) response.sw1;
3489 return result;
3490 } finally {
3491 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003492 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003493 }
3494
Nathan Haroldb3014052017-01-25 15:57:32 -08003495 /**
3496 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3497 * on a particular subscription
3498 */
sqianb6e41952018-03-12 14:54:01 -07003499 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3500 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3501 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3502 return null;
3503 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003504
3505 final long identity = Binder.clearCallingIdentity();
3506 try {
3507 if (appType != TelephonyManager.APPTYPE_USIM
3508 && appType != TelephonyManager.APPTYPE_SIM) {
3509 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3510 return null;
3511 }
3512 Object response = sendRequest(
3513 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3514 if (response instanceof String[]) {
3515 return (String[]) response;
3516 }
3517 // Response is an Exception of some kind,
3518 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003519 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003520 } finally {
3521 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003522 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003523 }
3524
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003525 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003526 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3528 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003529
Malcolm Chend965c8b2018-02-28 15:00:40 -08003530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3533 if (response.payload == null) {
3534 return "";
3535 }
Evan Charltonc66da362014-05-16 14:06:40 -07003536
Malcolm Chend965c8b2018-02-28 15:00:40 -08003537 // Append the returned status code to the end of the response payload.
3538 String s = Integer.toHexString(
3539 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3540 s = IccUtils.bytesToHexString(response.payload) + s;
3541 return s;
3542 } finally {
3543 Binder.restoreCallingIdentity(identity);
3544 }
Evan Charltonc66da362014-05-16 14:06:40 -07003545 }
3546
Jake Hambye994d462014-02-03 13:10:13 -08003547 /**
3548 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3549 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3550 *
3551 * @param itemID the ID of the item to read
3552 * @return the NV item as a String, or null on error.
3553 */
3554 @Override
3555 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003556 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3558 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003559
3560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003563 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003564 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3565 return value;
3566 } finally {
3567 Binder.restoreCallingIdentity(identity);
3568 }
Jake Hambye994d462014-02-03 13:10:13 -08003569 }
3570
3571 /**
3572 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3573 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3574 *
3575 * @param itemID the ID of the item to read
3576 * @param itemValue the value to write, as a String
3577 * @return true on success; false on any failure
3578 */
3579 @Override
3580 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003581 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3583 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003584
3585 final long identity = Binder.clearCallingIdentity();
3586 try {
3587 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3588 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003589 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003590 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3591 return success;
3592 } finally {
3593 Binder.restoreCallingIdentity(identity);
3594 }
Jake Hambye994d462014-02-03 13:10:13 -08003595 }
3596
3597 /**
3598 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3599 * Used for device configuration by some CDMA operators.
3600 *
3601 * @param preferredRoamingList byte array containing the new PRL
3602 * @return true on success; false on any failure
3603 */
3604 @Override
3605 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3607 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003608
3609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3612 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3613 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3614 return success;
3615 } finally {
3616 Binder.restoreCallingIdentity(identity);
3617 }
Jake Hambye994d462014-02-03 13:10:13 -08003618 }
3619
3620 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003621 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003622 * Used for device configuration by some CDMA operators.
3623 *
chen xu1cc0abe2018-10-26 17:39:23 -07003624 * @param slotIndex - device slot.
3625 *
Jake Hambye994d462014-02-03 13:10:13 -08003626 * @return true on success; false on any failure
3627 */
3628 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003629 public boolean resetModemConfig(int slotIndex) {
3630 Phone phone = PhoneFactory.getPhone(slotIndex);
3631 if (phone != null) {
3632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3633 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003634
chen xu1cc0abe2018-10-26 17:39:23 -07003635 final long identity = Binder.clearCallingIdentity();
3636 try {
3637 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3638 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3639 return success;
3640 } finally {
3641 Binder.restoreCallingIdentity(identity);
3642 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003643 }
chen xu1cc0abe2018-10-26 17:39:23 -07003644 return false;
3645 }
3646
3647 /**
3648 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3649 *
3650 * @param slotIndex - device slot.
3651 *
3652 * @return true on success; false on any failure
3653 */
3654 @Override
3655 public boolean rebootModem(int slotIndex) {
3656 Phone phone = PhoneFactory.getPhone(slotIndex);
3657 if (phone != null) {
3658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3659 mApp, phone.getSubId(), "rebootModem");
3660
3661 final long identity = Binder.clearCallingIdentity();
3662 try {
3663 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3664 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3665 return success;
3666 } finally {
3667 Binder.restoreCallingIdentity(identity);
3668 }
3669 }
3670 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003671 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003672
Svet Ganovb320e182015-04-16 12:30:10 -07003673 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003674 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003676 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003677 return new String[0];
3678 }
3679
Malcolm Chend965c8b2018-02-28 15:00:40 -08003680 final long identity = Binder.clearCallingIdentity();
3681 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003682 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003683 } finally {
3684 Binder.restoreCallingIdentity(identity);
3685 }
Wink Saville36469e72014-06-11 15:17:00 -07003686 }
3687
Brad Ebinger51f743a2017-01-23 13:50:20 -08003688 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003689 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3690 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003691 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003692 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003693 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003694
3695 final long identity = Binder.clearCallingIdentity();
3696 try {
3697 PhoneFactory.getImsResolver().enableIms(slotId);
3698 } finally {
3699 Binder.restoreCallingIdentity(identity);
3700 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003701 }
3702
3703 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003704 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3705 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003706 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003707 public void disableIms(int slotId) {
3708 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003709
3710 final long identity = Binder.clearCallingIdentity();
3711 try {
3712 PhoneFactory.getImsResolver().disableIms(slotId);
3713 } finally {
3714 Binder.restoreCallingIdentity(identity);
3715 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003716 }
3717
3718 /**
3719 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3720 * feature or {@link null} if the service is not available. If the feature is available, the
3721 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3722 */
3723 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003724 IImsServiceFeatureCallback callback) {
3725 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003726
3727 final long identity = Binder.clearCallingIdentity();
3728 try {
3729 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3730 } finally {
3731 Binder.restoreCallingIdentity(identity);
3732 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003733 }
3734
3735 /**
3736 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3737 * feature during emergency calling or {@link null} if the service is not available. If the
3738 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3739 * listener for feature updates.
3740 */
3741 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3742 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003743
3744 final long identity = Binder.clearCallingIdentity();
3745 try {
3746 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003750 }
3751
Brad Ebinger5f64b052017-12-14 14:26:15 -08003752 /**
3753 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3754 * specified.
3755 */
3756 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3757 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003758
3759 final long identity = Binder.clearCallingIdentity();
3760 try {
3761 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3762 } finally {
3763 Binder.restoreCallingIdentity(identity);
3764 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003765 }
3766
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003767 /**
3768 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3769 * specified.
3770 */
3771 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3772 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003773
3774 final long identity = Binder.clearCallingIdentity();
3775 try {
3776 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3777 } finally {
3778 Binder.restoreCallingIdentity(identity);
3779 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003780 }
3781
Brad Ebinger884c07b2018-02-15 16:17:40 -08003782 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003783 * Sets the ImsService Package Name that Telephony will bind to.
3784 *
3785 * @param slotId the slot ID that the ImsService should bind for.
3786 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3787 * ImsService is the device default ImsService.
3788 * @param packageName The package name of the application that contains the ImsService to bind
3789 * to.
3790 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3791 * @hide
3792 */
3793 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003794 int[] subIds = SubscriptionManager.getSubId(slotId);
3795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3796 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3797 "setImsService");
3798
Malcolm Chend965c8b2018-02-28 15:00:40 -08003799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3802 isCarrierImsService, packageName);
3803 } finally {
3804 Binder.restoreCallingIdentity(identity);
3805 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003806 }
3807
3808 /**
3809 * Return the ImsService configuration.
3810 *
3811 * @param slotId The slot that the ImsService is associated with.
3812 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3813 * the device default.
3814 * @return the package name of the ImsService configuration.
3815 */
3816 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003817 int[] subIds = SubscriptionManager.getSubId(slotId);
3818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3819 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3820 "getImsService");
3821
Malcolm Chend965c8b2018-02-28 15:00:40 -08003822 final long identity = Binder.clearCallingIdentity();
3823 try {
3824 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3825 isCarrierImsService);
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
3828 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003829 }
3830
Wink Saville36469e72014-06-11 15:17:00 -07003831 public void setImsRegistrationState(boolean registered) {
3832 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003833
3834 final long identity = Binder.clearCallingIdentity();
3835 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003836 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003837 } finally {
3838 Binder.restoreCallingIdentity(identity);
3839 }
Wink Saville36469e72014-06-11 15:17:00 -07003840 }
3841
3842 /**
Stuart Scott54788802015-03-30 13:18:01 -07003843 * Set the network selection mode to automatic.
3844 *
3845 */
3846 @Override
3847 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3849 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003850
Pengquan Meng466e2482018-09-21 15:54:48 -07003851 if (!isActiveSubscription(subId)) {
3852 return;
3853 }
3854
Malcolm Chend965c8b2018-02-28 15:00:40 -08003855 final long identity = Binder.clearCallingIdentity();
3856 try {
3857 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3858 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3859 } finally {
3860 Binder.restoreCallingIdentity(identity);
3861 }
Stuart Scott54788802015-03-30 13:18:01 -07003862 }
3863
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003864 /**
3865 * Ask the radio to connect to the input network and change selection mode to manual.
3866 *
3867 * @param subId the id of the subscription.
3868 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3869 * the operator to attach to.
3870 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3871 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3872 * normal network selection next time.
3873 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003874 */
3875 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003876 public boolean setNetworkSelectionModeManual(
3877 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3879 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003880
3881 if (!isActiveSubscription(subId)) {
3882 return false;
3883 }
3884
Malcolm Chend965c8b2018-02-28 15:00:40 -08003885 final long identity = Binder.clearCallingIdentity();
3886 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003887 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003888 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003889 if (DBG) {
3890 log("setNetworkSelectionModeManual: subId: " + subId
3891 + " operator: " + operatorInfo);
3892 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003893 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3894 } finally {
3895 Binder.restoreCallingIdentity(identity);
3896 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003897 }
3898
3899 /**
3900 * Scans for available networks.
3901 */
3902 @Override
3903 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3905 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003906
Pengquan Meng0c05b502018-09-06 09:59:22 -07003907 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003908 try {
3909 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003910 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003911 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003912 } finally {
3913 Binder.restoreCallingIdentity(identity);
3914 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003915 }
3916
3917 /**
yinxub1bed742017-04-17 11:45:04 -07003918 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003919 *
yinxub1bed742017-04-17 11:45:04 -07003920 * @param subId id of the subscription
3921 * @param request contains the radio access networks with bands/channels to scan
3922 * @param messenger callback messenger for scan results or errors
3923 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003924 * @return the id of the requested scan which can be used to stop the scan.
3925 */
3926 @Override
3927 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3928 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3930 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003931
3932 final long identity = Binder.clearCallingIdentity();
3933 try {
3934 return mNetworkScanRequestTracker.startNetworkScan(
3935 request, messenger, binder, getPhone(subId));
3936 } finally {
3937 Binder.restoreCallingIdentity(identity);
3938 }
yinxu504e1392017-04-12 16:03:22 -07003939 }
3940
3941 /**
3942 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003943 *
3944 * @param subId id of the subscription
3945 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003946 */
3947 @Override
3948 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3950 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003951
3952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3955 } finally {
3956 Binder.restoreCallingIdentity(identity);
3957 }
yinxu504e1392017-04-12 16:03:22 -07003958 }
3959
3960 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003961 * Get the calculated preferred network type.
3962 * Used for debugging incorrect network type.
3963 *
3964 * @return the preferred network type, defined in RILConstants.java.
3965 */
3966 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003967 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003968 final Phone defaultPhone = getDefaultPhone();
3969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
3970 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003971 return RILConstants.PREFERRED_NETWORK_MODE;
3972 }
3973
Malcolm Chend965c8b2018-02-28 15:00:40 -08003974 final long identity = Binder.clearCallingIdentity();
3975 try {
3976 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003977 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003978 } finally {
3979 Binder.restoreCallingIdentity(identity);
3980 }
Junda Liu84d15a22014-07-02 11:21:04 -07003981 }
3982
3983 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003984 * Get the preferred network type.
3985 * Used for device configuration by some CDMA operators.
3986 *
3987 * @return the preferred network type, defined in RILConstants.java.
3988 */
3989 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003990 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3992 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003993
3994 final long identity = Binder.clearCallingIdentity();
3995 try {
3996 if (DBG) log("getPreferredNetworkType");
3997 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3998 int networkType = (result != null ? result[0] : -1);
3999 if (DBG) log("getPreferredNetworkType: " + networkType);
4000 return networkType;
4001 } finally {
4002 Binder.restoreCallingIdentity(identity);
4003 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004004 }
4005
4006 /**
4007 * Set the preferred network type.
4008 * Used for device configuration by some CDMA operators.
4009 *
4010 * @param networkType the preferred network type, defined in RILConstants.java.
4011 * @return true on success; false on any failure.
4012 */
4013 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004014 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4016 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004017
4018 final long identity = Binder.clearCallingIdentity();
4019 try {
4020 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4021 Boolean success = (Boolean) sendRequest(
4022 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4023 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4024 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004025 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004026 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4027 }
4028 return success;
4029 } finally {
4030 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004031 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004032 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004033
4034 /**
Junda Liu475951f2014-11-07 16:45:03 -08004035 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07004036 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004037 * tethering.
4038 *
4039 * @return 0: Not required. 1: required. 2: Not set.
4040 * @hide
4041 */
4042 @Override
4043 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004044 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004045
4046 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004047 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004048 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004049 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004050 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004051 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004052 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004053 dunRequired = 1;
4054 }
4055 return dunRequired;
4056 } finally {
4057 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004058 }
Junda Liu475951f2014-11-07 16:45:03 -08004059 }
4060
4061 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004062 * Set mobile data enabled
4063 * Used by the user through settings etc to turn on/off mobile data
4064 *
4065 * @param enable {@code true} turn turn data on, else {@code false}
4066 */
4067 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004068 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4070 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004071
4072 final long identity = Binder.clearCallingIdentity();
4073 try {
4074 int phoneId = mSubscriptionController.getPhoneId(subId);
4075 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4076 Phone phone = PhoneFactory.getPhone(phoneId);
4077 if (phone != null) {
4078 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004079 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004080 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004081 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004082 }
4083 } finally {
4084 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004085 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004086 }
4087
4088 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004089 * Get the user enabled state of Mobile Data.
4090 *
4091 * TODO: remove and use isUserDataEnabled.
4092 * This can't be removed now because some vendor codes
4093 * calls through ITelephony directly while they should
4094 * use TelephonyManager.
4095 *
4096 * @return true on enabled
4097 */
4098 @Override
4099 public boolean getDataEnabled(int subId) {
4100 return isUserDataEnabled(subId);
4101 }
4102
4103 /**
4104 * Get whether mobile data is enabled per user setting.
4105 *
4106 * There are other factors deciding whether mobile data is actually enabled, but they are
4107 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004108 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004109 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004110 *
4111 * @return {@code true} if data is enabled else {@code false}
4112 */
4113 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004114 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004115 try {
4116 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4117 null);
4118 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4120 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004121 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004122
4123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 int phoneId = mSubscriptionController.getPhoneId(subId);
4126 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4127 Phone phone = PhoneFactory.getPhone(phoneId);
4128 if (phone != null) {
4129 boolean retVal = phone.isUserDataEnabled();
4130 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4131 return retVal;
4132 } else {
4133 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4134 return false;
4135 }
4136 } finally {
4137 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004138 }
4139 }
4140
4141 /**
4142 * Get whether mobile data is enabled.
4143 *
4144 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4145 * whether mobile data is actually enabled.
4146 *
4147 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4148 *
4149 * @return {@code true} if data is enabled else {@code false}
4150 */
4151 @Override
4152 public boolean isDataEnabled(int subId) {
4153 try {
4154 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4155 null);
4156 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4158 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004159 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004160
4161 final long identity = Binder.clearCallingIdentity();
4162 try {
4163 int phoneId = mSubscriptionController.getPhoneId(subId);
4164 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4165 Phone phone = PhoneFactory.getPhone(phoneId);
4166 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004167 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004168 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4169 return retVal;
4170 } else {
4171 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4172 return false;
4173 }
4174 } finally {
4175 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004176 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004177 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004178
4179 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004180 public int getCarrierPrivilegeStatus(int subId) {
4181 final Phone phone = getPhone(subId);
4182 if (phone == null) {
4183 loge("getCarrierPrivilegeStatus: Invalid subId");
4184 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4185 }
4186 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004187 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004188 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004189 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4190 }
4191 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004192 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004193 }
Junda Liu29340342014-07-10 15:23:27 -07004194
4195 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004196 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4197 final Phone phone = getPhone(subId);
4198 if (phone == null) {
4199 loge("getCarrierPrivilegeStatus: Invalid subId");
4200 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4201 }
4202 UiccProfile profile =
4203 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4204 if (profile == null) {
4205 loge("getCarrierPrivilegeStatus: No UICC");
4206 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4207 }
4208 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4209 }
4210
4211 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004212 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004213 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004214 if (TextUtils.isEmpty(pkgName))
4215 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004216 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004217 if (card == null) {
4218 loge("checkCarrierPrivilegesForPackage: No UICC");
4219 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4220 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004221 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4222 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004223 }
4224
4225 @Override
4226 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004227 if (TextUtils.isEmpty(pkgName))
4228 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004229 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4230 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4231 UiccCard card = UiccController.getInstance().getUiccCard(i);
4232 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004233 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004234 continue;
4235 }
4236
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004237 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004238 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4239 break;
4240 }
4241 }
4242
4243 return result;
Junda Liu29340342014-07-10 15:23:27 -07004244 }
Derek Tan89e89d42014-07-08 17:00:10 -07004245
4246 @Override
Junda Liue64de782015-04-16 17:19:16 -07004247 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4248 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4249 loge("phoneId " + phoneId + " is not valid.");
4250 return null;
4251 }
4252 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004253 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004254 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004255 return null ;
4256 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004257 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004258 }
4259
Amith Yamasani6e118872016-02-19 12:53:51 -08004260 @Override
4261 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004262 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004263 List<String> privilegedPackages = new ArrayList<>();
4264 List<PackageInfo> packages = null;
4265 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4266 UiccCard card = UiccController.getInstance().getUiccCard(i);
4267 if (card == null) {
4268 // No UICC in that slot.
4269 continue;
4270 }
4271 if (card.hasCarrierPrivilegeRules()) {
4272 if (packages == null) {
4273 // Only check packages in user 0 for now
4274 packages = pm.getInstalledPackagesAsUser(
4275 PackageManager.MATCH_DISABLED_COMPONENTS
4276 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4277 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4278 }
4279 for (int p = packages.size() - 1; p >= 0; p--) {
4280 PackageInfo pkgInfo = packages.get(p);
4281 if (pkgInfo != null && pkgInfo.packageName != null
4282 && card.getCarrierPrivilegeStatus(pkgInfo)
4283 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4284 privilegedPackages.add(pkgInfo.packageName);
4285 }
4286 }
4287 }
4288 }
4289 return privilegedPackages;
4290 }
4291
Wink Savilleb564aae2014-10-23 10:18:09 -07004292 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004293 final Phone phone = getPhone(subId);
4294 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004295 if (card == null) {
4296 loge("getIccId: No UICC");
4297 return null;
4298 }
4299 String iccId = card.getIccId();
4300 if (TextUtils.isEmpty(iccId)) {
4301 loge("getIccId: ICC ID is null or empty.");
4302 return null;
4303 }
4304 return iccId;
4305 }
4306
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004307 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004308 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4309 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004310 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4311 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004312
Malcolm Chend965c8b2018-02-28 15:00:40 -08004313 final long identity = Binder.clearCallingIdentity();
4314 try {
4315 final String iccId = getIccId(subId);
4316 final Phone phone = getPhone(subId);
4317 if (phone == null) {
4318 return false;
4319 }
4320 final String subscriberId = phone.getSubscriberId();
4321
4322 if (DBG_MERGE) {
4323 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4324 + subscriberId + " to " + number);
4325 }
4326
4327 if (TextUtils.isEmpty(iccId)) {
4328 return false;
4329 }
4330
4331 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4332
4333 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4334 if (alphaTag == null) {
4335 editor.remove(alphaTagPrefKey);
4336 } else {
4337 editor.putString(alphaTagPrefKey, alphaTag);
4338 }
4339
4340 // Record both the line number and IMSI for this ICCID, since we need to
4341 // track all merged IMSIs based on line number
4342 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4343 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4344 if (number == null) {
4345 editor.remove(numberPrefKey);
4346 editor.remove(subscriberPrefKey);
4347 } else {
4348 editor.putString(numberPrefKey, number);
4349 editor.putString(subscriberPrefKey, subscriberId);
4350 }
4351
4352 editor.commit();
4353 return true;
4354 } finally {
4355 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004356 }
Derek Tan7226c842014-07-02 17:42:23 -07004357 }
4358
4359 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004360 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004361 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004362 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004363 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004364 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004365 return null;
4366 }
Derek Tan97ebb422014-09-05 16:55:38 -07004367
Malcolm Chend965c8b2018-02-28 15:00:40 -08004368 final long identity = Binder.clearCallingIdentity();
4369 try {
4370 String iccId = getIccId(subId);
4371 if (iccId != null) {
4372 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4373 if (DBG_MERGE) {
4374 log("getLine1NumberForDisplay returning "
4375 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4376 }
4377 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004378 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004379 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4380 return null;
4381 } finally {
4382 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004383 }
Derek Tan7226c842014-07-02 17:42:23 -07004384 }
4385
4386 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004387 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004388 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004389 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004390 return null;
4391 }
Derek Tan97ebb422014-09-05 16:55:38 -07004392
Malcolm Chend965c8b2018-02-28 15:00:40 -08004393 final long identity = Binder.clearCallingIdentity();
4394 try {
4395 String iccId = getIccId(subId);
4396 if (iccId != null) {
4397 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4398 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4399 }
4400 return null;
4401 } finally {
4402 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004403 }
Derek Tan7226c842014-07-02 17:42:23 -07004404 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004405
4406 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004407 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004408 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4409 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004410 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004411 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4412 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004413 return null;
4414 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004415
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004416 final long identity = Binder.clearCallingIdentity();
4417 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004418 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004419 final TelephonyManager tele = TelephonyManager.from(context);
4420 final SubscriptionManager sub = SubscriptionManager.from(context);
4421
4422 // Figure out what subscribers are currently active
4423 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4424 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4425 // the process, where TelephonyManager was instantiated.
4426 // Otherwise AppOps check will fail.
4427
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004428 final int[] subIds = sub.getActiveSubscriptionIdList();
4429 for (int subId : subIds) {
4430 activeSubscriberIds.add(tele.getSubscriberId(subId));
4431 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004432
4433 // First pass, find a number override for an active subscriber
4434 String mergeNumber = null;
4435 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4436 for (String key : prefs.keySet()) {
4437 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4438 final String subscriberId = (String) prefs.get(key);
4439 if (activeSubscriberIds.contains(subscriberId)) {
4440 final String iccId = key.substring(
4441 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4442 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4443 mergeNumber = (String) prefs.get(numberKey);
4444 if (DBG_MERGE) {
4445 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4446 + " for active subscriber " + subscriberId);
4447 }
4448 if (!TextUtils.isEmpty(mergeNumber)) {
4449 break;
4450 }
4451 }
4452 }
4453 }
4454
4455 // Shortcut when no active merged subscribers
4456 if (TextUtils.isEmpty(mergeNumber)) {
4457 return null;
4458 }
4459
4460 // Second pass, find all subscribers under that line override
4461 final ArraySet<String> result = new ArraySet<>();
4462 for (String key : prefs.keySet()) {
4463 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4464 final String number = (String) prefs.get(key);
4465 if (mergeNumber.equals(number)) {
4466 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4467 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4468 final String subscriberId = (String) prefs.get(subscriberKey);
4469 if (!TextUtils.isEmpty(subscriberId)) {
4470 result.add(subscriberId);
4471 }
4472 }
4473 }
4474 }
4475
4476 final String[] resultArray = result.toArray(new String[result.size()]);
4477 Arrays.sort(resultArray);
4478 if (DBG_MERGE) {
4479 Slog.d(LOG_TAG,
4480 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4481 }
4482 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004483 } finally {
4484 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004485 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004486 }
4487
4488 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004489 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004490 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4491 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004492
4493 final long identity = Binder.clearCallingIdentity();
4494 try {
4495 final Phone phone = getPhone(subId);
4496 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4497 } finally {
4498 Binder.restoreCallingIdentity(identity);
4499 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004500 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004501
4502 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004503 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004504 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4505 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004506 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004507
4508 final long identity = Binder.clearCallingIdentity();
4509 try {
4510 final Phone phone = getPhone(subId);
4511 if (phone == null) {
4512 return false;
4513 }
4514 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4515 cdmaNonRoamingList);
4516 } finally {
4517 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004518 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004519 }
4520
4521 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004522 @Deprecated
4523 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4524 enforceModifyPermission();
4525
4526 int returnValue = 0;
4527 try {
vagdevie435a3e2018-08-15 16:01:53 -07004528 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004529 if(result.exception == null) {
4530 if (result.result != null) {
4531 byte[] responseData = (byte[])(result.result);
4532 if(responseData.length > oemResp.length) {
4533 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4534 responseData.length + "bytes. Buffer Size is " +
4535 oemResp.length + "bytes.");
4536 }
4537 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4538 returnValue = responseData.length;
4539 }
4540 } else {
4541 CommandException ex = (CommandException) result.exception;
4542 returnValue = ex.getCommandError().ordinal();
4543 if(returnValue > 0) returnValue *= -1;
4544 }
4545 } catch (RuntimeException e) {
4546 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4547 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4548 if(returnValue > 0) returnValue *= -1;
4549 }
4550
4551 return returnValue;
4552 }
4553
4554 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004555 public void setRadioCapability(RadioAccessFamily[] rafs) {
4556 try {
4557 ProxyController.getInstance().setRadioCapability(rafs);
4558 } catch (RuntimeException e) {
4559 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4560 }
4561 }
4562
4563 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004564 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004565 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004566 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004567 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004568 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004569 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004570 final long identity = Binder.clearCallingIdentity();
4571 try {
chen xufeeed752018-10-26 14:17:57 -07004572 TelephonyPermissions
4573 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4574 mApp, phone.getSubId(), "getRadioAccessFamily");
4575 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004576 } finally {
4577 Binder.restoreCallingIdentity(identity);
4578 }
chen xufeeed752018-10-26 14:17:57 -07004579 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004580 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004581
4582 @Override
4583 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004584 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004585 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004586
4587 final long identity = Binder.clearCallingIdentity();
4588 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004589 ImsManager.getInstance(defaultPhone.getContext(),
4590 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004591 } finally {
4592 Binder.restoreCallingIdentity(identity);
4593 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004594 }
4595
4596 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004597 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004598 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004600 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004601 return false;
4602 }
Svet Ganovb320e182015-04-16 12:30:10 -07004603
Malcolm Chend965c8b2018-02-28 15:00:40 -08004604 final long identity = Binder.clearCallingIdentity();
4605 try {
4606 // Check the user preference and the system-level IMS setting. Even if the user has
4607 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4608 // In the long run, we may instead need to check if there exists a connection service
4609 // which can support video calling.
4610 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004611 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004612 return imsManager.isVtEnabledByPlatform()
4613 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4614 && imsManager.isVtEnabledByUser();
4615 } finally {
4616 Binder.restoreCallingIdentity(identity);
4617 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004618 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004619
Andrew Leea1239f22015-03-02 17:44:07 -08004620 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004621 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4623 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4624 return false;
4625 }
4626
4627 final long identity = Binder.clearCallingIdentity();
4628 try {
4629 CarrierConfigManager configManager =
4630 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004631 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004632 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4633 } finally {
4634 Binder.restoreCallingIdentity(identity);
4635 }
Andrew Leea1239f22015-03-02 17:44:07 -08004636 }
4637
4638 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004639 public boolean isWorldPhone(int subId, String callingPackage) {
4640 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4641 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4642 return false;
4643 }
4644
4645 final long identity = Binder.clearCallingIdentity();
4646 try {
4647 CarrierConfigManager configManager =
4648 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004649 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004650 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4651 } finally {
4652 Binder.restoreCallingIdentity(identity);
4653 }
Andrew Leea1239f22015-03-02 17:44:07 -08004654 }
4655
Andrew Lee9431b832015-03-09 18:46:45 -07004656 @Override
4657 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004658 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004659 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004660 }
4661
4662 @Override
4663 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004664 final long identity = Binder.clearCallingIdentity();
4665 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004666 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004667 } finally {
4668 Binder.restoreCallingIdentity(identity);
4669 }
Andrew Lee9431b832015-03-09 18:46:45 -07004670 }
4671
Hall Liuf6668912018-10-31 17:05:23 -07004672 /**
4673 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4674 * support for the feature and device firmware support.
4675 *
4676 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4677 */
4678 @Override
4679 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004680 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004681 final Phone phone = getPhone(subscriptionId);
4682 if (phone == null) {
4683 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4684 return false;
4685 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004686 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004687 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004688 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4689 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004690 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004691 return isCarrierSupported && isDeviceSupported;
4692 } finally {
4693 Binder.restoreCallingIdentity(identity);
4694 }
Hall Liu98187582018-01-22 19:15:32 -08004695 }
4696
Hall Liuf6668912018-10-31 17:05:23 -07004697 /**
4698 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4699 * both also support RTT.
4700 */
4701 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004702 final long identity = Binder.clearCallingIdentity();
4703 try {
Hall Liuf6668912018-10-31 17:05:23 -07004704 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004705 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004706 } finally {
4707 Binder.restoreCallingIdentity(identity);
4708 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004709 }
4710
Sanket Padawe7310cc72015-01-14 09:53:20 -08004711 /**
4712 * Returns the unique device ID of phone, for example, the IMEI for
4713 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4714 *
4715 * <p>Requires Permission:
4716 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4717 */
4718 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004719 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004720 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004721 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004722 return null;
4723 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004724 int subId = phone.getSubId();
4725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4726 mApp, subId, callingPackage, "getDeviceId")) {
4727 return null;
4728 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004729
4730 final long identity = Binder.clearCallingIdentity();
4731 try {
4732 return phone.getDeviceId();
4733 } finally {
4734 Binder.restoreCallingIdentity(identity);
4735 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004736 }
4737
Ping Sunc67b7c22016-03-02 19:16:45 +08004738 /**
4739 * {@hide}
4740 * Returns the IMS Registration Status on a particular subid
4741 *
4742 * @param subId
4743 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004744 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004745 Phone phone = getPhone(subId);
4746 if (phone != null) {
4747 return phone.isImsRegistered();
4748 } else {
4749 return false;
4750 }
4751 }
4752
Santos Cordon7a1885b2015-02-03 11:15:19 -08004753 @Override
4754 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004755 final long identity = Binder.clearCallingIdentity();
4756 try {
4757 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4758 } finally {
4759 Binder.restoreCallingIdentity(identity);
4760 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004761 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004762
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004763 /**
4764 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004765 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004766 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004767 final long identity = Binder.clearCallingIdentity();
4768 try {
4769 Phone phone = getPhone(subId);
4770 if (phone != null) {
4771 return phone.isWifiCallingEnabled();
4772 } else {
4773 return false;
4774 }
4775 } finally {
4776 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004777 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004778 }
4779
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004780 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004781 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004782 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004783 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004784 final long identity = Binder.clearCallingIdentity();
4785 try {
4786 Phone phone = getPhone(subId);
4787 if (phone != null) {
4788 return phone.isVideoEnabled();
4789 } else {
4790 return false;
4791 }
4792 } finally {
4793 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004794 }
4795 }
4796
4797 /**
4798 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4799 * defined in {@link ImsRegistrationImplBase}.
4800 */
4801 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004802 final long identity = Binder.clearCallingIdentity();
4803 try {
4804 Phone phone = getPhone(subId);
4805 if (phone != null) {
4806 return phone.getImsRegistrationTech();
4807 } else {
4808 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4809 }
4810 } finally {
4811 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004812 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004813 }
4814
Stuart Scott8eef64f2015-04-08 15:13:54 -07004815 @Override
4816 public void factoryReset(int subId) {
4817 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004818 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4819 return;
4820 }
4821
Svet Ganovcc087f82015-05-12 20:35:54 -07004822 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004823
Svet Ganovcc087f82015-05-12 20:35:54 -07004824 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004825 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4826 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004827 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004828 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004829 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004830 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
4831 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07004832 }
4833 } finally {
4834 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004835 }
4836 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004837
4838 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08004839 public String getSimLocaleForSubscriber(int subId) {
4840 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
4841 final Phone phone = getPhone(subId);
4842 if (phone == null) {
4843 log("getSimLocaleForSubscriber, invalid subId");
4844 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004845 final long identity = Binder.clearCallingIdentity();
4846 try {
chen xu2e6dfec2019-01-21 23:31:38 -08004847 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
4848 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004849 // Try and fetch the locale from the carrier properties or from the SIM language
4850 // preferences (EF-PL and EF-LI)...
4851 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004852 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08004853 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
4854 if (localeFromDefaultSim != null) {
4855 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4856 if (DBG) log("Using locale from subId: " + subId + " locale: "
4857 + localeFromDefaultSim);
4858 return localeFromDefaultSim.toLanguageTag();
4859 } else {
4860 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004861 }
4862 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004863
Malcolm Chend965c8b2018-02-28 15:00:40 -08004864 // The SIM language preferences only store a language (e.g. fr = French), not an
4865 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4866 // the SIM and carrier preferences does not include a country we add the country
4867 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004868 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004869 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08004870 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004871 return mccLocale.toLanguageTag();
4872 }
4873
4874 if (DBG) log("No locale found - returning null");
4875 return null;
4876 } finally {
4877 Binder.restoreCallingIdentity(identity);
4878 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004879 }
4880
4881 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004882 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004883 }
4884
Malcolm Chend965c8b2018-02-28 15:00:40 -08004885 /**
4886 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4887 */
4888 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004889 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004890 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004891
Chenjie Yu1ba97252018-01-11 18:16:20 -08004892 private final ModemActivityInfo mLastModemActivityInfo =
4893 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4894
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004895 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004896 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4897 * representing the state of the modem.
4898 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004899 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4900 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004901 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004902 */
4903 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004904 public void requestModemActivityInfo(ResultReceiver result) {
4905 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004906 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004907
4908 final long identity = Binder.clearCallingIdentity();
4909 try {
4910 ModemActivityInfo ret = null;
4911 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004912 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4913 CMD_GET_MODEM_ACTIVITY_INFO,
4914 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004915 if (isModemActivityInfoValid(info)) {
4916 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4917 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4918 mergedTxTimeMs[i] =
4919 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4920 }
4921 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4922 mLastModemActivityInfo.setSleepTimeMillis(
4923 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4924 mLastModemActivityInfo.setIdleTimeMillis(
4925 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4926 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4927 mLastModemActivityInfo.setRxTimeMillis(
4928 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4929 mLastModemActivityInfo.setEnergyUsed(
4930 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004931 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004932 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4933 mLastModemActivityInfo.getSleepTimeMillis(),
4934 mLastModemActivityInfo.getIdleTimeMillis(),
4935 mLastModemActivityInfo.getTxTimeMillis(),
4936 mLastModemActivityInfo.getRxTimeMillis(),
4937 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004938 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004939 Bundle bundle = new Bundle();
4940 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4941 result.send(0, bundle);
4942 } finally {
4943 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004944 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004945 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004946
Siddharth Rayf5d29552018-06-17 15:02:38 -07004947 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4948 // less than total activity duration.
4949 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4950 if (info == null) {
4951 return false;
4952 }
4953 int activityDurationMs =
4954 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4955 int totalTxTimeMs = 0;
4956 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4957 totalTxTimeMs += info.getTxTimeMillis()[i];
4958 }
4959 return (info.isValid()
4960 && (info.getSleepTimeMillis() <= activityDurationMs)
4961 && (info.getIdleTimeMillis() <= activityDurationMs)
4962 && (info.getRxTimeMillis() <= activityDurationMs)
4963 && (totalTxTimeMs <= activityDurationMs));
4964 }
4965
Jack Yu85bd38a2015-11-09 11:34:32 -08004966 /**
4967 * {@hide}
4968 * Returns the service state information on specified subscription.
4969 */
4970 @Override
4971 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004973 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004974 return null;
4975 }
4976
Malcolm Chend965c8b2018-02-28 15:00:40 -08004977 final long identity = Binder.clearCallingIdentity();
4978 try {
4979 final Phone phone = getPhone(subId);
4980 if (phone == null) {
4981 return null;
4982 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004983
Malcolm Chend965c8b2018-02-28 15:00:40 -08004984 return phone.getServiceState();
4985 } finally {
4986 Binder.restoreCallingIdentity(identity);
4987 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004988 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004989
4990 /**
4991 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4992 *
4993 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4994 * voicemail ringtone.
4995 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4996 * PhoneAccount.
4997 */
4998 @Override
4999 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005000 final long identity = Binder.clearCallingIdentity();
5001 try {
5002 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5003 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005004 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005005 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005006
Malcolm Chend965c8b2018-02-28 15:00:40 -08005007 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5008 } finally {
5009 Binder.restoreCallingIdentity(identity);
5010 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005011 }
5012
5013 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005014 * Sets the per-account voicemail ringtone.
5015 *
5016 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5017 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5018 *
5019 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5020 * voicemail ringtone.
5021 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5022 * PhoneAccount.
5023 */
5024 @Override
5025 public void setVoicemailRingtoneUri(String callingPackage,
5026 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005027 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005028 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5029 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005030 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5032 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5033 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005034 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005035
5036 final long identity = Binder.clearCallingIdentity();
5037 try {
5038 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5039 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005040 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005041 }
5042 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5043 } finally {
5044 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005045 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005046 }
5047
5048 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005049 * Returns whether vibration is set for voicemail notification in Phone settings.
5050 *
5051 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5052 * voicemail vibration setting.
5053 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5054 */
5055 @Override
5056 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005057 final long identity = Binder.clearCallingIdentity();
5058 try {
5059 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5060 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005061 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005062 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005063
Malcolm Chend965c8b2018-02-28 15:00:40 -08005064 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5065 } finally {
5066 Binder.restoreCallingIdentity(identity);
5067 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005068 }
5069
Youhan Wange64578a2016-05-02 15:32:42 -07005070 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005071 * Sets the per-account voicemail vibration.
5072 *
5073 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5074 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5075 *
5076 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5077 * voicemail vibration setting.
5078 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5079 * specific PhoneAccount.
5080 */
5081 @Override
5082 public void setVoicemailVibrationEnabled(String callingPackage,
5083 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005084 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005085 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5086 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005087 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5089 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5090 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005091 }
5092
Malcolm Chend965c8b2018-02-28 15:00:40 -08005093 final long identity = Binder.clearCallingIdentity();
5094 try {
5095 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5096 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005097 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005098 }
5099 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5100 } finally {
5101 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005102 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005103 }
5104
5105 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005106 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5107 *
5108 * @throws SecurityException if the caller does not have the required permission
5109 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005110 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005111 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005112 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005113 }
5114
5115 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005116 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5117 * permission.
5118 *
5119 * @throws SecurityException if the caller does not have the required permission
5120 */
5121 private void enforceSendSmsPermission() {
5122 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5123 }
5124
5125 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005126 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005127 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005128 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005129 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005130 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005131 final long identity = Binder.clearCallingIdentity();
5132 try {
5133 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005134 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005135 if (componentName == null) {
5136 throw new SecurityException(
5137 "Caller not current active visual voicemail package[null]");
5138 }
5139 String vvmPackage = componentName.getPackageName();
5140 if (!callingPackage.equals(vvmPackage)) {
5141 throw new SecurityException("Caller not current active visual voicemail package["
5142 + vvmPackage + "]");
5143 }
5144 } finally {
5145 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005146 }
5147 }
5148
5149 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005150 * Return the application ID for the app type.
5151 *
5152 * @param subId the subscription ID that this request applies to.
5153 * @param appType the uicc app type.
5154 * @return Application ID for specificied app type, or null if no uicc.
5155 */
5156 @Override
5157 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005158 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005159 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005160
5161 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005162 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005163 if (phone == null) {
5164 return null;
5165 }
5166 String aid = null;
5167 try {
5168 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5169 .getApplicationByType(appType).getAid();
5170 } catch (Exception e) {
5171 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5172 }
5173 return aid;
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005176 }
Youhan Wange64578a2016-05-02 15:32:42 -07005177 }
5178
Youhan Wang4001d252016-05-11 10:29:41 -07005179 /**
5180 * Return the Electronic Serial Number.
5181 *
5182 * @param subId the subscription ID that this request applies to.
5183 * @return ESN or null if error.
5184 */
5185 @Override
5186 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005187 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005188 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005189
5190 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005191 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005192 if (phone == null) {
5193 return null;
5194 }
5195 String esn = null;
5196 try {
5197 esn = phone.getEsn();
5198 } catch (Exception e) {
5199 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5200 }
5201 return esn;
5202 } finally {
5203 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005204 }
Youhan Wang4001d252016-05-11 10:29:41 -07005205 }
5206
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005207 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005208 * Return the Preferred Roaming List Version.
5209 *
5210 * @param subId the subscription ID that this request applies to.
5211 * @return PRLVersion or null if error.
5212 */
5213 @Override
5214 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005215 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005216 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005217
5218 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005219 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005220 if (phone == null) {
5221 return null;
5222 }
5223 String cdmaPrlVersion = null;
5224 try {
5225 cdmaPrlVersion = phone.getCdmaPrlVersion();
5226 } catch (Exception e) {
5227 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5228 }
5229 return cdmaPrlVersion;
5230 } finally {
5231 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005232 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005233 }
5234
5235 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005236 * Get snapshot of Telephony histograms
5237 * @return List of Telephony histograms
5238 * @hide
5239 */
5240 @Override
5241 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5243 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005244
5245 final long identity = Binder.clearCallingIdentity();
5246 try {
5247 return RIL.getTelephonyRILTimingHistograms();
5248 } finally {
5249 Binder.restoreCallingIdentity(identity);
5250 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005251 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005252
5253 /**
5254 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005255 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5256 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005257 * Require system privileges. In the future we may add this to carrier APIs.
5258 *
Michele Berionne0963c862018-11-27 18:57:59 -08005259 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005260 */
5261 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005262 @TelephonyManager.SetCarrierRestrictionResult
5263 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005264 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005265 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005266
Michele Berionne0963c862018-11-27 18:57:59 -08005267 if (carrierRestrictionRules == null) {
5268 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005269 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005270
Malcolm Chend965c8b2018-02-28 15:00:40 -08005271 final long identity = Binder.clearCallingIdentity();
5272 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005273 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005274 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005278 }
5279
5280 /**
5281 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005282 * Get the allowed carrier list and the excluded carrier list, including the priority between
5283 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005284 * Require system privileges. In the future we may add this to carrier APIs.
5285 *
Michele Berionne0963c862018-11-27 18:57:59 -08005286 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005287 */
5288 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005289 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005290 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005291 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005292
5293 final long identity = Binder.clearCallingIdentity();
5294 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005295 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5296 if (response instanceof CarrierRestrictionRules) {
5297 return (CarrierRestrictionRules) response;
5298 }
5299 // Response is an Exception of some kind,
5300 // which is signalled to the user as a NULL retval
5301 return null;
5302 } catch (Exception e) {
5303 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5304 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005305 } finally {
5306 Binder.restoreCallingIdentity(identity);
5307 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005308 }
5309
fionaxu59545b42016-05-25 15:53:37 -07005310 /**
5311 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5312 * @param subId the subscription ID that this action applies to.
5313 * @param enabled control enable or disable metered apns.
5314 * {@hide}
5315 */
5316 @Override
5317 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5318 enforceModifyPermission();
5319 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005320
5321 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005322 if (phone == null) {
5323 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5324 return;
5325 }
5326 try {
5327 phone.carrierActionSetMeteredApnsEnabled(enabled);
5328 } catch (Exception e) {
5329 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005330 } finally {
5331 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005332 }
5333 }
5334
5335 /**
5336 * Action set from carrier signalling broadcast receivers to enable/disable radio
5337 * @param subId the subscription ID that this action applies to.
5338 * @param enabled control enable or disable radio.
5339 * {@hide}
5340 */
5341 @Override
5342 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5343 enforceModifyPermission();
5344 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005345
5346 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005347 if (phone == null) {
5348 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5349 return;
5350 }
5351 try {
5352 phone.carrierActionSetRadioEnabled(enabled);
5353 } catch (Exception e) {
5354 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005355 } finally {
5356 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005357 }
5358 }
5359
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005360 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005361 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5362 * network status based on which carrier apps could apply actions accordingly,
5363 * enable/disable default url handler for example.
5364 *
5365 * @param subId the subscription ID that this action applies to.
5366 * @param report control start/stop reporting the default network status.
5367 * {@hide}
5368 */
5369 @Override
5370 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5371 enforceModifyPermission();
5372 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005373
5374 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005375 if (phone == null) {
5376 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5377 return;
5378 }
5379 try {
5380 phone.carrierActionReportDefaultNetworkStatus(report);
5381 } catch (Exception e) {
5382 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005383 } finally {
5384 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005385 }
5386 }
5387
5388 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005389 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5390 * bug report is being generated.
5391 */
5392 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005393 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005394 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5395 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005396 writer.println("Permission Denial: can't dump Phone from pid="
5397 + Binder.getCallingPid()
5398 + ", uid=" + Binder.getCallingUid()
5399 + "without permission "
5400 + android.Manifest.permission.DUMP);
5401 return;
5402 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005403 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005404 }
Jack Yueb89b242016-06-22 13:27:47 -07005405
Brad Ebingerdac2f002018-04-03 15:17:52 -07005406 @Override
5407 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5408 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5409 throws RemoteException {
5410 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5411 }
5412
Jack Yueb89b242016-06-22 13:27:47 -07005413 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005414 * Get aggregated video call data usage since boot.
5415 *
5416 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5417 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005418 * {@hide}
5419 */
5420 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005421 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005422 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5423 null);
5424
Malcolm Chend965c8b2018-02-28 15:00:40 -08005425 final long identity = Binder.clearCallingIdentity();
5426 try {
5427 // NetworkStatsService keeps tracking the active network interface and identity. It
5428 // records the delta with the corresponding network identity.
5429 // We just return the total video call data usage snapshot since boot.
5430 Phone phone = getPhone(subId);
5431 if (phone != null) {
5432 return phone.getVtDataUsage(perUidStats);
5433 }
5434 return null;
5435 } finally {
5436 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005437 }
Jack Yueb89b242016-06-22 13:27:47 -07005438 }
Jack Yu75ab2952016-07-08 14:29:33 -07005439
5440 /**
5441 * Policy control of data connection. Usually used when data limit is passed.
5442 * @param enabled True if enabling the data, otherwise disabling.
5443 * @param subId Subscription index
5444 * {@hide}
5445 */
5446 @Override
5447 public void setPolicyDataEnabled(boolean enabled, int subId) {
5448 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005449
5450 final long identity = Binder.clearCallingIdentity();
5451 try {
5452 Phone phone = getPhone(subId);
5453 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005454 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005455 }
5456 } finally {
5457 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005458 }
5459 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005460
5461 /**
5462 * Get Client request stats
5463 * @return List of Client Request Stats
5464 * @hide
5465 */
5466 @Override
5467 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005468 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005469 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005470 return null;
5471 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005472 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005473
Malcolm Chend965c8b2018-02-28 15:00:40 -08005474 final long identity = Binder.clearCallingIdentity();
5475 try {
5476 if (phone != null) {
5477 return phone.getClientRequestStats();
5478 }
5479
5480 return null;
5481 } finally {
5482 Binder.restoreCallingIdentity(identity);
5483 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005484 }
5485
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005486 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005487 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005488 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005489 }
Jack Yueb4124c2017-02-16 15:32:43 -08005490
5491 /**
Grace Chen70990072017-03-24 17:21:30 -07005492 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005493 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005494 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005495 * @param state State of SIM (power down, power up, pass through)
5496 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5497 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5498 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005499 *
5500 **/
5501 @Override
Grace Chen70990072017-03-24 17:21:30 -07005502 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005503 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005504 Phone phone = PhoneFactory.getPhone(slotIndex);
5505
vagdevie435a3e2018-08-15 16:01:53 -07005506 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5507
Malcolm Chend965c8b2018-02-28 15:00:40 -08005508 final long identity = Binder.clearCallingIdentity();
5509 try {
5510 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005511 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005512 }
5513 } finally {
5514 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005515 }
5516 }
Shuo Qiandd210312017-04-12 22:11:33 +00005517
Tyler Gunn65d45c22017-06-05 11:22:26 -07005518 private boolean isUssdApiAllowed(int subId) {
5519 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005520 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005521 if (configManager == null) {
5522 return false;
5523 }
5524 PersistableBundle pb = configManager.getConfigForSubId(subId);
5525 if (pb == null) {
5526 return false;
5527 }
5528 return pb.getBoolean(
5529 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5530 }
5531
Shuo Qiandd210312017-04-12 22:11:33 +00005532 /**
5533 * Check if phone is in emergency callback mode
5534 * @return true if phone is in emergency callback mode
5535 * @param subId sub id
5536 */
goneil9c5f4872017-12-05 14:07:56 -08005537 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005538 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005539 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005540 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005541
5542 final long identity = Binder.clearCallingIdentity();
5543 try {
5544 if (phone != null) {
5545 return phone.isInEcm();
5546 } else {
5547 return false;
5548 }
5549 } finally {
5550 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005551 }
5552 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005553
5554 /**
5555 * Get the current signal strength information for the given subscription.
5556 * Because this information is not updated when the device is in a low power state
5557 * it should not be relied-upon to be current.
5558 * @param subId Subscription index
5559 * @return the most recent cached signal strength info from the modem
5560 */
5561 @Override
5562 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005563 final long identity = Binder.clearCallingIdentity();
5564 try {
5565 Phone p = getPhone(subId);
5566 if (p == null) {
5567 return null;
5568 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005569
Malcolm Chend965c8b2018-02-28 15:00:40 -08005570 return p.getSignalStrength();
5571 } finally {
5572 Binder.restoreCallingIdentity(identity);
5573 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005574 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005575
Pengquan Meng9140aec2018-08-22 14:49:57 -07005576 /**
chen xu907e5a22018-10-11 13:21:04 -07005577 * Get the current modem radio state for the given slot.
5578 * @param slotIndex slot index.
5579 * @param callingPackage the name of the package making the call.
5580 * @return the current radio power state from the modem
5581 */
5582 @Override
5583 public int getRadioPowerState(int slotIndex, String callingPackage) {
5584 Phone phone = PhoneFactory.getPhone(slotIndex);
5585 if (phone != null) {
5586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5587 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5588 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5589 }
5590
5591 final long identity = Binder.clearCallingIdentity();
5592 try {
5593 return phone.getRadioPowerState();
5594 } finally {
5595 Binder.restoreCallingIdentity(identity);
5596 }
5597 }
5598 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5599 }
5600
5601 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005602 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5603 *
5604 * <p>Requires one of the following permissions:
5605 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5606 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5607 * privileges.
5608 *
5609 * @param subId subscription id
5610 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5611 * {@code false}.
5612 */
5613 @Override
5614 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005615 boolean isEnabled = false;
5616 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005617 try {
5618 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005619 null /* message */);
5620 Phone phone = getPhone(subId);
5621 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005622 } catch (Exception e) {
5623 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5624 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005625 } finally {
5626 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005627 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005628 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005629 }
5630
5631
5632 /**
5633 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5634 *
5635 * <p> Requires permission:
5636 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5637 * privileges.
5638 *
5639 * @param subId subscription id
5640 * @param isEnabled {@code true} means enable, {@code false} means disable.
5641 */
5642 @Override
5643 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005644 final long identity = Binder.clearCallingIdentity();
5645 try {
5646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5647 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005648
Pengquan Meng0c05b502018-09-06 09:59:22 -07005649 Phone phone = getPhone(subId);
5650 if (phone != null) {
5651 phone.setDataRoamingEnabled(isEnabled);
5652 }
5653 } finally {
5654 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005655 }
5656 }
5657
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005658 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005659 public boolean isManualNetworkSelectionAllowed(int subId) {
5660 boolean isAllowed = true;
5661 final long identity = Binder.clearCallingIdentity();
5662 try {
5663 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5664 mApp, subId, "isManualNetworkSelectionAllowed");
5665 Phone phone = getPhone(subId);
5666 if (phone != null) {
5667 isAllowed = phone.isCspPlmnEnabled();
5668 }
5669 } finally {
5670 Binder.restoreCallingIdentity(identity);
5671 }
5672 return isAllowed;
5673 }
5674
5675 @Override
Jordan Liu5aa07002018-12-18 15:44:48 -08005676 public UiccCardInfo[] getUiccCardsInfo() {
5677 enforceReadPrivilegedPermission("getUiccCardsInfo");
5678
5679 final long identity = Binder.clearCallingIdentity();
5680 try {
5681 ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos();
5682 return cards.toArray(new UiccCardInfo[cards.size()]);
5683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
5686 }
5687
5688 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005689 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005690 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005691
Malcolm Chend965c8b2018-02-28 15:00:40 -08005692 final long identity = Binder.clearCallingIdentity();
5693 try {
5694 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5695 if (slots == null) {
5696 Rlog.i(LOG_TAG, "slots is null.");
5697 return null;
5698 }
5699
5700 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5701 for (int i = 0; i < slots.length; i++) {
5702 UiccSlot slot = slots[i];
5703 if (slot == null) {
5704 continue;
5705 }
5706
5707 String cardId;
5708 UiccCard card = slot.getUiccCard();
5709 if (card != null) {
5710 cardId = card.getCardId();
5711 } else {
5712 cardId = slot.getIccId();
5713 }
5714
5715 int cardState = 0;
5716 switch (slot.getCardState()) {
5717 case CARDSTATE_ABSENT:
5718 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5719 break;
5720 case CARDSTATE_PRESENT:
5721 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5722 break;
5723 case CARDSTATE_ERROR:
5724 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5725 break;
5726 case CARDSTATE_RESTRICTED:
5727 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5728 break;
5729 default:
5730 break;
5731
5732 }
5733
5734 infos[i] = new UiccSlotInfo(
5735 slot.isActive(),
5736 slot.isEuicc(),
5737 cardId,
5738 cardState,
5739 slot.getPhoneId(),
5740 slot.isExtendedApduSupported());
5741 }
5742 return infos;
5743 } finally {
5744 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005745 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005746 }
5747
5748 @Override
5749 public boolean switchSlots(int[] physicalSlots) {
5750 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005751
5752 final long identity = Binder.clearCallingIdentity();
5753 try {
5754 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5755 } finally {
5756 Binder.restoreCallingIdentity(identity);
5757 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005758 }
Jack Yu4c988042018-02-27 15:30:01 -08005759
5760 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08005761 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
5762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5763 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
5764 return TelephonyManager.INVALID_CARD_ID;
5765 }
5766
5767 final long identity = Binder.clearCallingIdentity();
5768 try {
5769 return UiccController.getInstance().getCardIdForDefaultEuicc();
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
5773 }
5774
5775 @Override
Jack Yu4c988042018-02-27 15:30:01 -08005776 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5777 enforceModifyPermission();
5778 final Phone phone = getPhone(subId);
5779 if (phone == null) {
5780 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5781 return;
5782 }
5783
Malcolm Chend965c8b2018-02-28 15:00:40 -08005784 final long identity = Binder.clearCallingIdentity();
5785 try {
5786 phone.setRadioIndicationUpdateMode(filters, mode);
5787 } finally {
5788 Binder.restoreCallingIdentity(identity);
5789 }
Jack Yu4c988042018-02-27 15:30:01 -08005790 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005791
5792 /**
goneil47ffb6e2018-04-06 15:40:58 -07005793 * A test API to reload the UICC profile.
5794 *
5795 * <p>Requires that the calling app has permission
5796 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5797 * @hide
5798 */
5799 @Override
5800 public void refreshUiccProfile(int subId) {
5801 enforceModifyPermission();
5802
5803 final long identity = Binder.clearCallingIdentity();
5804 try {
5805 Phone phone = getPhone(subId);
5806 if (phone == null) {
5807 return;
5808 }
5809 UiccCard uiccCard = phone.getUiccCard();
5810 if (uiccCard == null) {
5811 return;
5812 }
5813 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5814 if (uiccProfile == null) {
5815 return;
5816 }
5817 uiccProfile.refresh();
5818 } finally {
5819 Binder.restoreCallingIdentity(identity);
5820 }
5821 }
5822
5823 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005824 * Returns false if the mobile data is disabled by default, otherwise return true.
5825 */
5826 private boolean getDefaultDataEnabled() {
5827 return "true".equalsIgnoreCase(
5828 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5829 }
5830
5831 /**
5832 * Returns true if the data roaming is enabled by default, i.e the system property
5833 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5834 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5835 */
5836 private boolean getDefaultDataRoamingEnabled(int subId) {
5837 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005838 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005839 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5840 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5841 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5842 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5843 return isDataRoamingEnabled;
5844 }
5845
5846 /**
5847 * Returns the default network type for the given {@code subId}, if the default network type is
5848 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5849 */
5850 private int getDefaultNetworkType(int subId) {
5851 return Integer.parseInt(
5852 TelephonyManager.getTelephonyProperty(
5853 mSubscriptionController.getPhoneId(subId),
5854 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5855 String.valueOf(Phone.PREFERRED_NT_MODE)));
5856 }
fionaxua13278b2018-03-21 00:08:13 -07005857
5858 @Override
5859 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5860 gid1, String gid2, String plmn, String spn) {
5861 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005862
5863 final long identity = Binder.clearCallingIdentity();
5864 try {
5865 final Phone phone = getPhone(subId);
5866 if (phone == null) {
5867 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5868 return;
5869 }
5870 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5871 } finally {
5872 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005873 }
fionaxua13278b2018-03-21 00:08:13 -07005874 }
5875
5876 @Override
5877 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005878 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005879
5880 final long identity = Binder.clearCallingIdentity();
5881 try {
5882 final Phone phone = getPhone(subId);
5883 if (phone == null) {
5884 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5885 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5886 }
5887 return phone.getCarrierIdListVersion();
5888 } finally {
5889 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005890 }
fionaxua13278b2018-03-21 00:08:13 -07005891 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005892
5893 @Override
5894 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5896 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5897 return -1;
5898 }
5899
5900 final long identity = Binder.clearCallingIdentity();
5901 try {
5902 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
5906 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005907
5908 @Override
5909 public int getCdmaRoamingMode(int subId) {
5910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5911 mApp, subId, "getCdmaRoamingMode");
5912
5913 final long identity = Binder.clearCallingIdentity();
5914 try {
5915 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5916 } finally {
5917 Binder.restoreCallingIdentity(identity);
5918 }
5919 }
5920
5921 @Override
5922 public boolean setCdmaRoamingMode(int subId, int mode) {
5923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5924 mApp, subId, "setCdmaRoamingMode");
5925
5926 final long identity = Binder.clearCallingIdentity();
5927 try {
5928 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5929 } finally {
5930 Binder.restoreCallingIdentity(identity);
5931 }
5932 }
5933
5934 @Override
5935 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5937 mApp, subId, "setCdmaSubscriptionMode");
5938
5939 final long identity = Binder.clearCallingIdentity();
5940 try {
5941 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5942 } finally {
5943 Binder.restoreCallingIdentity(identity);
5944 }
5945 }
chen xu7ee67862018-10-30 22:27:10 -07005946
sqian2fff4a32018-11-05 14:18:37 -08005947 private void ensureUserRunning(int userId) {
5948 if (!mUserManager.isUserRunning(userId)) {
5949 throw new IllegalStateException("User " + userId + " does not exist or not running");
5950 }
5951 }
5952
5953 /**
5954 * Returns a list of SMS apps on a given user.
5955 *
5956 * Only the shell user (UID 2000 or 0) can call it.
5957 * Target user must be running.
5958 */
5959 @Override
5960 public String[] getSmsApps(int userId) {
5961 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5962 ensureUserRunning(userId);
5963
5964 final Collection<SmsApplicationData> apps =
5965 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5966
5967 String[] ret = new String[apps.size()];
5968 int i = 0;
5969 for (SmsApplicationData app : apps) {
5970 ret[i++] = app.mPackageName;
5971 }
5972 return ret;
5973 }
5974
5975 /**
5976 * Returns the default SMS app package name on a given user.
5977 *
5978 * Only the shell user (UID 2000 or 0) can call it.
5979 * Target user must be running.
5980 */
5981 @Override
5982 public String getDefaultSmsApp(int userId) {
5983 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5984 ensureUserRunning(userId);
5985
5986 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5987 /* updateIfNeeded= */ true, userId);
5988 return cn == null ? null : cn.getPackageName();
5989 }
5990
5991 /**
5992 * Set a package as the default SMS app on a given user.
5993 *
5994 * Only the shell user (UID 2000 or 0) can call it.
5995 * Target user must be running.
5996 */
5997 @Override
5998 public void setDefaultSmsApp(int userId, String packageName) {
5999 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6000 ensureUserRunning(userId);
6001
6002 boolean found = false;
6003 for (String pkg : getSmsApps(userId)) {
6004 if (TextUtils.equals(packageName, pkg)) {
6005 found = true;
6006 break;
6007 }
6008 }
6009 if (!found) {
6010 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6011 }
6012
6013 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6014 }
6015
chen xu7ee67862018-10-30 22:27:10 -07006016 @Override
sqian04b86072018-11-07 14:02:21 -08006017 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6018 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006019 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6020 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6021 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6022 }
6023 final long identity = Binder.clearCallingIdentity();
6024 try {
sqian991b35e2018-12-12 16:48:18 -08006025 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6026 for (Phone phone: PhoneFactory.getPhones()) {
6027 if (phone.getEmergencyNumberTracker() != null
6028 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6029 emergencyNumberListInternal.put(
6030 phone.getSubId(),
6031 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6032 }
sqian03bca152018-12-05 18:48:28 -08006033 }
sqian991b35e2018-12-12 16:48:18 -08006034 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006035 } finally {
6036 Binder.restoreCallingIdentity(identity);
6037 }
sqian04b86072018-11-07 14:02:21 -08006038 }
6039
6040 @Override
sqian03bca152018-12-05 18:48:28 -08006041 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6042 final Phone defaultPhone = getDefaultPhone();
6043 if (!exactMatch) {
6044 TelephonyPermissions
6045 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6046 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6047 }
6048 final long identity = Binder.clearCallingIdentity();
6049 try {
sqian991b35e2018-12-12 16:48:18 -08006050 for (Phone phone: PhoneFactory.getPhones()) {
6051 if (phone.getEmergencyNumberTracker() != null
6052 && phone.getEmergencyNumberTracker() != null) {
6053 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6054 number, exactMatch)) {
6055 return true;
sqian03bca152018-12-05 18:48:28 -08006056 }
6057 }
sqian03bca152018-12-05 18:48:28 -08006058 }
6059 return false;
6060 } finally {
6061 Binder.restoreCallingIdentity(identity);
6062 }
6063 }
6064
sqian04b86072018-11-07 14:02:21 -08006065 @Override
chen xu7ee67862018-10-30 22:27:10 -07006066 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6067 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6068 Phone phone = getPhone(subId);
6069 if (phone == null) {
6070 return null;
6071 }
6072 final long identity = Binder.clearCallingIdentity();
6073 try {
6074 UiccProfile profile = UiccController.getInstance()
6075 .getUiccProfileForPhone(phone.getPhoneId());
6076 if (profile != null) {
6077 return profile.getCertsFromCarrierPrivilegeAccessRules();
6078 }
6079 } finally {
6080 Binder.restoreCallingIdentity(identity);
6081 }
6082 return null;
6083 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006084
6085 /**
6086 * Enable or disable a modem stack.
6087 */
6088 @Override
6089 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6090 enforceModifyPermission();
6091
6092 final long identity = Binder.clearCallingIdentity();
6093 try {
6094 Phone phone = PhoneFactory.getPhone(slotIndex);
6095 if (phone == null) {
6096 return false;
6097 } else {
6098 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6099 }
6100 } finally {
6101 Binder.restoreCallingIdentity(identity);
6102 }
6103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006104}