blob: c19539bab7a5ef55bf1314d7c6ca9d09e809c09e [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
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070028import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070029import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070032import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070038import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Looper;
40import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070042import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080043import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070044import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070046import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070047import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070049import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070050import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070051import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080052import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070053import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080054import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080055import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070056import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070057import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070059import android.telephony.CellInfoGsm;
60import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070061import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070063import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070064import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080065import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070066import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080067import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070068import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070069import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070070import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080072import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070073import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080074import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080075import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070076import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070077import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000078import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070079import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070081import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080082import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080083import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070084import android.telephony.gsm.GsmCellLocation;
Brad Ebinger4c460712018-10-01 10:40:55 -070085import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080086import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070087import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080088import android.telephony.ims.aidl.IImsMmTelFeature;
89import android.telephony.ims.aidl.IImsRcsFeature;
90import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070091import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080092import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080094import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080096import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080097import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080098
Brad Ebinger4c460712018-10-01 10:40:55 -070099import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700100import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800101import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700102import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700103import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700104import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800105import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700106import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700107import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800110import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700111import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100112import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700113import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700114import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700116import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800117import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700118import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700119import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700120import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700121import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700122import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700123import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800124import com.android.internal.telephony.SmsApplication;
125import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800126import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800127import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700128import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.uicc.IccIoResult;
130import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800131import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700132import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800133import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700134import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800135import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000136import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700137import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800138import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700139import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800140import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700141import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700142import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800143
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700144import java.io.FileDescriptor;
145import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800146import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800148import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800149import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800150import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100151import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800152import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153
154/**
155 * Implementation of the ITelephony interface.
156 */
Santos Cordon117fee72014-05-16 17:56:12 -0700157public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158 private static final String LOG_TAG = "PhoneInterfaceManager";
159 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
160 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800161 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162
163 // Message codes used with mMainThreadHandler
164 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700165 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
166 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167 private static final int CMD_OPEN_CHANNEL = 9;
168 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
169 private static final int CMD_CLOSE_CHANNEL = 11;
170 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800171 private static final int CMD_NV_READ_ITEM = 13;
172 private static final int EVENT_NV_READ_ITEM_DONE = 14;
173 private static final int CMD_NV_WRITE_ITEM = 15;
174 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
175 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
176 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700177 private static final int CMD_RESET_MODEM_CONFIG = 19;
178 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800179 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
180 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
181 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
182 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800183 private static final int CMD_SEND_ENVELOPE = 25;
184 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000185 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
186 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700187 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
188 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
189 private static final int CMD_EXCHANGE_SIM_IO = 31;
190 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800191 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
192 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700193 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
194 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700195 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
196 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700197 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
198 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
199 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
200 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700201 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
202 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
203 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
204 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700205 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800206 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
207 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000208 private static final int CMD_SWITCH_SLOTS = 50;
209 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700210 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
211 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
212 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
213 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
214 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
215 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
216 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
217 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700218 private static final int CMD_GET_ALL_CELL_INFO = 60;
219 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
220 private static final int CMD_GET_CELL_LOCATION = 62;
221 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700222 private static final int CMD_MODEM_REBOOT = 64;
223 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700224 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
225 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800227 // Parameters of select command.
228 private static final int SELECT_COMMAND = 0xA4;
229 private static final int SELECT_P1 = 0x04;
230 private static final int SELECT_P2 = 0;
231 private static final int SELECT_P3 = 0x10;
232
Pengquan Meng85728fb2018-03-12 16:31:21 -0700233 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
234 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
235 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
236
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237 /** The singleton instance. */
238 private static PhoneInterfaceManager sInstance;
239
Wink Saville3ab207e2014-11-20 13:07:20 -0800240 private PhoneGlobals mApp;
241 private Phone mPhone;
242 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700243 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800244 private AppOpsManager mAppOps;
245 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800246 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800247 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700248 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249
Derek Tan97ebb422014-09-05 16:55:38 -0700250 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
251 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800252 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700253
Derek Tan740e1672017-06-27 14:56:27 -0700254 // The AID of ISD-R.
255 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
256
yinxub1bed742017-04-17 11:45:04 -0700257 private NetworkScanRequestTracker mNetworkScanRequestTracker;
258
David Kelly5e06a7f2018-03-12 14:10:59 +0000259 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
260 private static final int MANUFACTURER_CODE_LENGTH = 8;
261
Derek Tan89e89d42014-07-08 17:00:10 -0700262 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700263 * A request object to use for transmitting data to an ICC.
264 */
265 private static final class IccAPDUArgument {
266 public int channel, cla, command, p1, p2, p3;
267 public String data;
268
269 public IccAPDUArgument(int channel, int cla, int command,
270 int p1, int p2, int p3, String data) {
271 this.channel = channel;
272 this.cla = cla;
273 this.command = command;
274 this.p1 = p1;
275 this.p2 = p2;
276 this.p3 = p3;
277 this.data = data;
278 }
279 }
280
281 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700282 * A request object to use for transmitting data to an ICC.
283 */
284 private static final class ManualNetworkSelectionArgument {
285 public OperatorInfo operatorInfo;
286 public boolean persistSelection;
287
288 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
289 this.operatorInfo = operatorInfo;
290 this.persistSelection = persistSelection;
291 }
292 }
293
294 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
296 * request after sending. The main thread will notify the request when it is complete.
297 */
298 private static final class MainThreadRequest {
299 /** The argument to use for the request */
300 public Object argument;
301 /** The result of the request that is run on the main thread */
302 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800303 // The subscriber id that this request applies to. Defaults to
304 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
305 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306
Nathan Harold92bed182018-10-12 18:16:49 -0700307 // In cases where subId is unavailable, the caller needs to specify the phone.
308 public Phone phone;
309
vagdevie435a3e2018-08-15 16:01:53 -0700310 public WorkSource workSource;
311
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312 public MainThreadRequest(Object argument) {
313 this.argument = argument;
314 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800315
Nathan Harold92bed182018-10-12 18:16:49 -0700316 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
317 this.argument = argument;
318 if (phone != null) {
319 this.phone = phone;
320 }
321 this.workSource = workSource;
322 }
323
vagdevie435a3e2018-08-15 16:01:53 -0700324 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800325 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800326 if (subId != null) {
327 this.subId = subId;
328 }
vagdevie435a3e2018-08-15 16:01:53 -0700329 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331 }
332
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800333 private static final class IncomingThirdPartyCallArgs {
334 public final ComponentName component;
335 public final String callId;
336 public final String callerDisplayName;
337
338 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
339 String callerDisplayName) {
340 this.component = component;
341 this.callId = callId;
342 this.callerDisplayName = callerDisplayName;
343 }
344 }
345
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 /**
347 * A handler that processes messages on the main thread in the phone process. Since many
348 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
349 * inbound binder threads to the main thread in the phone process. The Binder thread
350 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
351 * on, which will be notified when the operation completes and will contain the result of the
352 * request.
353 *
354 * <p>If a MainThreadRequest object is provided in the msg.obj field,
355 * note that request.result must be set to something non-null for the calling thread to
356 * unblock.
357 */
358 private final class MainThreadHandler extends Handler {
359 @Override
360 public void handleMessage(Message msg) {
361 MainThreadRequest request;
362 Message onCompleted;
363 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800364 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700365 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366
367 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700368 case CMD_HANDLE_USSD_REQUEST: {
369 request = (MainThreadRequest) msg.obj;
370 final Phone phone = getPhoneFromRequest(request);
371 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
372 String ussdRequest = ussdObject.first;
373 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700374
Pengquan Meng0c05b502018-09-06 09:59:22 -0700375 if (!isUssdApiAllowed(request.subId)) {
376 // Carrier does not support use of this API, return failure.
377 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
378 UssdResponse response = new UssdResponse(ussdRequest, null);
379 Bundle returnData = new Bundle();
380 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
381 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700382
Pengquan Meng0c05b502018-09-06 09:59:22 -0700383 request.result = true;
384 notifyRequester(request);
385 return;
386 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700387
Pengquan Meng0c05b502018-09-06 09:59:22 -0700388 try {
389 request.result = phone != null
390 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
391 } catch (CallStateException cse) {
392 request.result = false;
393 }
394 // Wake up the requesting thread
395 notifyRequester(request);
396 break;
pkanwar32d516d2016-10-14 19:37:38 -0700397 }
398
Yorke Lee716f67e2015-06-17 15:39:16 -0700399 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700401 final Phone phone = getPhoneFromRequest(request);
402 request.result = phone != null ?
403 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
404 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700406 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700410 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700411 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800413 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700414 if (uiccCard == null) {
415 loge("iccTransmitApduLogicalChannel: No UICC");
416 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700417 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700418 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700419 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
420 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700421 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700422 iccArgument.channel, iccArgument.cla, iccArgument.command,
423 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700424 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700425 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700426 break;
427
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 ar = (AsyncResult) msg.obj;
430 request = (MainThreadRequest) ar.userObj;
431 if (ar.exception == null && ar.result != null) {
432 request.result = ar.result;
433 } else {
434 request.result = new IccIoResult(0x6F, 0, (byte[])null);
435 if (ar.result == null) {
436 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800437 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800439 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700440 } else {
441 loge("iccTransmitApduLogicalChannel: Unknown exception");
442 }
443 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700444 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 break;
446
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
448 request = (MainThreadRequest) msg.obj;
449 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800450 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 if (uiccCard == null) {
452 loge("iccTransmitApduBasicChannel: No UICC");
453 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700454 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 } else {
456 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
457 request);
458 uiccCard.iccTransmitApduBasicChannel(
459 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
460 iccArgument.p3, iccArgument.data, onCompleted);
461 }
462 break;
463
464 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
465 ar = (AsyncResult) msg.obj;
466 request = (MainThreadRequest) ar.userObj;
467 if (ar.exception == null && ar.result != null) {
468 request.result = ar.result;
469 } else {
470 request.result = new IccIoResult(0x6F, 0, (byte[])null);
471 if (ar.result == null) {
472 loge("iccTransmitApduBasicChannel: Empty response");
473 } else if (ar.exception instanceof CommandException) {
474 loge("iccTransmitApduBasicChannel: CommandException: " +
475 ar.exception);
476 } else {
477 loge("iccTransmitApduBasicChannel: Unknown exception");
478 }
479 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700480 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700481 break;
482
483 case CMD_EXCHANGE_SIM_IO:
484 request = (MainThreadRequest) msg.obj;
485 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800486 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 if (uiccCard == null) {
488 loge("iccExchangeSimIO: No UICC");
489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700490 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 } else {
492 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
493 request);
494 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
495 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
496 iccArgument.data, onCompleted);
497 }
498 break;
499
500 case EVENT_EXCHANGE_SIM_IO_DONE:
501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result;
505 } else {
506 request.result = new IccIoResult(0x6f, 0, (byte[])null);
507 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700508 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 break;
510
Derek Tan4d5e5c12014-02-04 11:54:58 -0800511 case CMD_SEND_ENVELOPE:
512 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800513 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700514 if (uiccCard == null) {
515 loge("sendEnvelopeWithStatus: No UICC");
516 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700517 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700518 } else {
519 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
520 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
521 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800522 break;
523
524 case EVENT_SEND_ENVELOPE_DONE:
525 ar = (AsyncResult) msg.obj;
526 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700527 if (ar.exception == null && ar.result != null) {
528 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800529 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
531 if (ar.result == null) {
532 loge("sendEnvelopeWithStatus: Empty response");
533 } else if (ar.exception instanceof CommandException) {
534 loge("sendEnvelopeWithStatus: CommandException: " +
535 ar.exception);
536 } else {
537 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
538 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800539 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700540 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800541 break;
542
Shishir Agrawal566b7612013-10-28 14:41:00 -0700543 case CMD_OPEN_CHANNEL:
544 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800545 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800546 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 if (uiccCard == null) {
548 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800549 request.result = new IccOpenLogicalChannelResponse(-1,
550 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700551 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700552 } else {
553 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800554 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
555 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 break;
558
559 case EVENT_OPEN_CHANNEL_DONE:
560 ar = (AsyncResult) msg.obj;
561 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 int[] result = (int[]) ar.result;
565 int channelId = result[0];
566 byte[] selectResponse = null;
567 if (result.length > 1) {
568 selectResponse = new byte[result.length - 1];
569 for (int i = 1; i < result.length; ++i) {
570 selectResponse[i - 1] = (byte) result[i];
571 }
572 }
573 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700574 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 if (ar.result == null) {
577 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700579 if (ar.exception != null) {
580 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
581 }
582
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700583 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700584 if (ar.exception instanceof CommandException) {
585 CommandException.Error error =
586 ((CommandException) (ar.exception)).getCommandError();
587 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700588 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700589 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700590 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 }
592 }
593 openChannelResp = new IccOpenLogicalChannelResponse(
594 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700596 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700597 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 break;
599
600 case CMD_CLOSE_CHANNEL:
601 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800602 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700603 if (uiccCard == null) {
604 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900605 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700606 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700607 } else {
608 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
609 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
610 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 break;
612
613 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800614 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
615 break;
616
617 case CMD_NV_READ_ITEM:
618 request = (MainThreadRequest) msg.obj;
619 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700620 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800621 break;
622
623 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 ar = (AsyncResult) msg.obj;
625 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800626 if (ar.exception == null && ar.result != null) {
627 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800629 request.result = "";
630 if (ar.result == null) {
631 loge("nvReadItem: Empty response");
632 } else if (ar.exception instanceof CommandException) {
633 loge("nvReadItem: CommandException: " +
634 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800636 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 }
638 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700639 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 break;
641
Jake Hambye994d462014-02-03 13:10:13 -0800642 case CMD_NV_WRITE_ITEM:
643 request = (MainThreadRequest) msg.obj;
644 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
645 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdevie435a3e2018-08-15 16:01:53 -0700646 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
647 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800648 break;
649
650 case EVENT_NV_WRITE_ITEM_DONE:
651 handleNullReturnEvent(msg, "nvWriteItem");
652 break;
653
654 case CMD_NV_WRITE_CDMA_PRL:
655 request = (MainThreadRequest) msg.obj;
656 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
657 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
658 break;
659
660 case EVENT_NV_WRITE_CDMA_PRL_DONE:
661 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
662 break;
663
chen xu1cc0abe2018-10-26 17:39:23 -0700664 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800665 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700666 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
667 mPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800668 break;
669
chen xu1cc0abe2018-10-26 17:39:23 -0700670 case EVENT_RESET_MODEM_CONFIG_DONE:
671 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800672 break;
673
Jake Hamby7c27be32014-03-03 13:25:59 -0800674 case CMD_GET_PREFERRED_NETWORK_TYPE:
675 request = (MainThreadRequest) msg.obj;
676 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700677 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800678 break;
679
680 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
681 ar = (AsyncResult) msg.obj;
682 request = (MainThreadRequest) ar.userObj;
683 if (ar.exception == null && ar.result != null) {
684 request.result = ar.result; // Integer
685 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800686 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800687 if (ar.result == null) {
688 loge("getPreferredNetworkType: Empty response");
689 } else if (ar.exception instanceof CommandException) {
690 loge("getPreferredNetworkType: CommandException: " +
691 ar.exception);
692 } else {
693 loge("getPreferredNetworkType: Unknown exception");
694 }
695 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700696 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800697 break;
698
699 case CMD_SET_PREFERRED_NETWORK_TYPE:
700 request = (MainThreadRequest) msg.obj;
701 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
702 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700703 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 break;
705
706 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
707 handleNullReturnEvent(msg, "setPreferredNetworkType");
708 break;
709
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000710 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
711 request = (MainThreadRequest)msg.obj;
712 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700713 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000714 break;
715
716 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
717 ar = (AsyncResult)msg.obj;
718 request = (MainThreadRequest)ar.userObj;
719 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700720 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000721 break;
722
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800723 case CMD_SET_VOICEMAIL_NUMBER:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
726 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800727 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
728 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800729 break;
730
731 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
732 handleNullReturnEvent(msg, "setVoicemailNumber");
733 break;
734
Stuart Scott54788802015-03-30 13:18:01 -0700735 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
738 request);
739 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
740 break;
741
742 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
743 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
744 break;
745
Shishir Agrawal302c8692015-06-19 13:49:39 -0700746 case CMD_PERFORM_NETWORK_SCAN:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
749 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
750 break;
751
752 case EVENT_PERFORM_NETWORK_SCAN_DONE:
753 ar = (AsyncResult) msg.obj;
754 request = (MainThreadRequest) ar.userObj;
755 CellNetworkScanResult cellScanResult;
756 if (ar.exception == null && ar.result != null) {
757 cellScanResult = new CellNetworkScanResult(
758 CellNetworkScanResult.STATUS_SUCCESS,
759 (List<OperatorInfo>) ar.result);
760 } else {
761 if (ar.result == null) {
762 loge("getCellNetworkScanResults: Empty response");
763 }
764 if (ar.exception != null) {
765 loge("getCellNetworkScanResults: Exception: " + ar.exception);
766 }
767 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
768 if (ar.exception instanceof CommandException) {
769 CommandException.Error error =
770 ((CommandException) (ar.exception)).getCommandError();
771 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
772 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
773 } else if (error == CommandException.Error.GENERIC_FAILURE) {
774 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
775 }
776 }
777 cellScanResult = new CellNetworkScanResult(errorCode, null);
778 }
779 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700780 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700781 break;
782
783 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
784 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700785 ManualNetworkSelectionArgument selArg =
786 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700787 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
788 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700789 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
790 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700791 break;
792
793 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700794 ar = (AsyncResult) msg.obj;
795 request = (MainThreadRequest) ar.userObj;
796 if (ar.exception == null) {
797 request.result = true;
798 } else {
799 request.result = false;
800 loge("setNetworkSelectionModeManual " + ar.exception);
801 }
802 notifyRequester(request);
803 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700804 break;
805
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700806 case CMD_GET_MODEM_ACTIVITY_INFO:
807 request = (MainThreadRequest) msg.obj;
808 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700809 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700810 break;
811
812 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
813 ar = (AsyncResult) msg.obj;
814 request = (MainThreadRequest) ar.userObj;
815 if (ar.exception == null && ar.result != null) {
816 request.result = ar.result;
817 } else {
818 if (ar.result == null) {
819 loge("queryModemActivityInfo: Empty response");
820 } else if (ar.exception instanceof CommandException) {
821 loge("queryModemActivityInfo: CommandException: " +
822 ar.exception);
823 } else {
824 loge("queryModemActivityInfo: Unknown exception");
825 }
826 }
Amit Mahajand4766222016-01-28 15:28:28 -0800827 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
828 if (request.result == null) {
829 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
830 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700831 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700832 break;
833
Meng Wang1a7c35a2016-05-05 20:56:15 -0700834 case CMD_SET_ALLOWED_CARRIERS:
835 request = (MainThreadRequest) msg.obj;
836 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
837 mPhone.setAllowedCarriers(
838 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700839 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700840 break;
841
842 case EVENT_SET_ALLOWED_CARRIERS_DONE:
843 ar = (AsyncResult) msg.obj;
844 request = (MainThreadRequest) ar.userObj;
845 if (ar.exception == null && ar.result != null) {
846 request.result = ar.result;
847 } else {
848 if (ar.result == null) {
849 loge("setAllowedCarriers: Empty response");
850 } else if (ar.exception instanceof CommandException) {
851 loge("setAllowedCarriers: CommandException: " +
852 ar.exception);
853 } else {
854 loge("setAllowedCarriers: Unknown exception");
855 }
856 }
857 // Result cannot be null. Return -1 on error.
858 if (request.result == null) {
859 request.result = new int[]{-1};
860 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700861 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700862 break;
863
864 case CMD_GET_ALLOWED_CARRIERS:
865 request = (MainThreadRequest) msg.obj;
866 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700867 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700868 break;
869
870 case EVENT_GET_ALLOWED_CARRIERS_DONE:
871 ar = (AsyncResult) msg.obj;
872 request = (MainThreadRequest) ar.userObj;
873 if (ar.exception == null && ar.result != null) {
874 request.result = ar.result;
875 } else {
876 if (ar.result == null) {
877 loge("getAllowedCarriers: Empty response");
878 } else if (ar.exception instanceof CommandException) {
879 loge("getAllowedCarriers: CommandException: " +
880 ar.exception);
881 } else {
882 loge("getAllowedCarriers: Unknown exception");
883 }
884 }
885 // Result cannot be null. Return empty list of CarrierIdentifier.
886 if (request.result == null) {
887 request.result = new ArrayList<CarrierIdentifier>(0);
888 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700889 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700890 break;
891
Nathan Haroldb3014052017-01-25 15:57:32 -0800892 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
895 if (ar.exception == null && ar.result != null) {
896 request.result = ar.result;
897 } else {
898 request.result = new IllegalArgumentException(
899 "Failed to retrieve Forbidden Plmns");
900 if (ar.result == null) {
901 loge("getForbiddenPlmns: Empty response");
902 } else {
903 loge("getForbiddenPlmns: Unknown exception");
904 }
905 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700906 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800907 break;
908
909 case CMD_GET_FORBIDDEN_PLMNS:
910 request = (MainThreadRequest) msg.obj;
911 uiccCard = getUiccCardFromRequest(request);
912 if (uiccCard == null) {
913 loge("getForbiddenPlmns() UiccCard is null");
914 request.result = new IllegalArgumentException(
915 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700916 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800917 break;
918 }
919 Integer appType = (Integer) request.argument;
920 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
921 if (uiccApp == null) {
922 loge("getForbiddenPlmns() no app with specified type -- "
923 + appType);
924 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700925 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800926 break;
927 } else {
928 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
929 + " specified type -- " + appType);
930 }
931 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
932 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
933 onCompleted);
934 break;
935
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000936 case CMD_SWITCH_SLOTS:
937 request = (MainThreadRequest) msg.obj;
938 int[] physicalSlots = (int[]) request.argument;
939 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
940 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
941 break;
942
943 case EVENT_SWITCH_SLOTS_DONE:
944 ar = (AsyncResult) msg.obj;
945 request = (MainThreadRequest) ar.userObj;
946 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700947 notifyRequester(request);
948 break;
949 case CMD_GET_NETWORK_SELECTION_MODE:
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
952 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
953 break;
954
955 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
956 ar = (AsyncResult) msg.obj;
957 request = (MainThreadRequest) ar.userObj;
958 if (ar.exception != null) {
959 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
960 } else {
961 int mode = ((int[]) ar.result)[0];
962 if (mode == 0) {
963 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
964 } else {
965 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
966 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000967 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700968 notifyRequester(request);
969 break;
970 case CMD_GET_CDMA_ROAMING_MODE:
971 request = (MainThreadRequest) msg.obj;
972 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
973 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
974 break;
975 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
976 ar = (AsyncResult) msg.obj;
977 request = (MainThreadRequest) ar.userObj;
978 if (ar.exception != null) {
979 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
980 } else {
981 request.result = ((int[]) ar.result)[0];
982 }
983 notifyRequester(request);
984 break;
985 case CMD_SET_CDMA_ROAMING_MODE:
986 request = (MainThreadRequest) msg.obj;
987 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
988 int mode = (int) request.argument;
989 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
990 break;
991 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
992 ar = (AsyncResult) msg.obj;
993 request = (MainThreadRequest) ar.userObj;
994 request.result = ar.exception == null;
995 notifyRequester(request);
996 break;
997 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
998 request = (MainThreadRequest) msg.obj;
999 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1000 int subscriptionMode = (int) request.argument;
1001 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1002 break;
1003 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1004 ar = (AsyncResult) msg.obj;
1005 request = (MainThreadRequest) ar.userObj;
1006 request.result = ar.exception == null;
1007 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001008 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001009 case CMD_GET_ALL_CELL_INFO:
1010 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001011 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001012 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001013 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001014 case EVENT_GET_ALL_CELL_INFO_DONE:
1015 ar = (AsyncResult) msg.obj;
1016 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001017 // If a timeout occurs, the response will be null
1018 request.result = (ar.exception == null && ar.result != null)
1019 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001020 synchronized (request) {
1021 request.notifyAll();
1022 }
1023 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001024 case CMD_REQUEST_CELL_INFO_UPDATE:
1025 request = (MainThreadRequest) msg.obj;
1026 request.phone.requestCellInfoUpdate(request.workSource,
1027 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1028 break;
1029 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1033 try {
1034 if (ar.exception != null) {
1035 // something went wrong... the response is null
1036 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1037 cb.onCellInfo(null);
1038 } else if (ar.result == null) {
1039 // timeout occurred, so force the result to non-null "empty"
1040 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1041 cb.onCellInfo(new ArrayList<CellInfo>());
1042 } else {
1043 // use the result as returned
1044 cb.onCellInfo((List<CellInfo>) ar.result);
1045 }
1046 } catch (RemoteException re) {
1047 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1048 }
1049 break;
1050 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 request = (MainThreadRequest) msg.obj;
1052 WorkSource ws = (WorkSource) request.argument;
1053 Phone phone = getPhoneFromRequest(request);
1054 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1055 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001056 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 ar = (AsyncResult) msg.obj;
1058 request = (MainThreadRequest) ar.userObj;
1059 if (ar.exception == null) {
1060 request.result = ar.result;
1061 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001062 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1064 ? new CdmaCellLocation() : new GsmCellLocation();
1065 }
1066
1067 synchronized (request) {
1068 request.notifyAll();
1069 }
1070 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001071 case CMD_MODEM_REBOOT:
1072 request = (MainThreadRequest) msg.obj;
1073 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
1074 mPhone.rebootModem(onCompleted);
1075 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001076 case EVENT_CMD_MODEM_REBOOT_DONE:
1077 handleNullReturnEvent(msg, "rebootModem");
1078 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001079 default:
1080 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1081 break;
1082 }
1083 }
Jake Hambye994d462014-02-03 13:10:13 -08001084
Pengquan Meng0c05b502018-09-06 09:59:22 -07001085 private void notifyRequester(MainThreadRequest request) {
1086 synchronized (request) {
1087 request.notifyAll();
1088 }
1089 }
1090
Jake Hambye994d462014-02-03 13:10:13 -08001091 private void handleNullReturnEvent(Message msg, String command) {
1092 AsyncResult ar = (AsyncResult) msg.obj;
1093 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1094 if (ar.exception == null) {
1095 request.result = true;
1096 } else {
1097 request.result = false;
1098 if (ar.exception instanceof CommandException) {
1099 loge(command + ": CommandException: " + ar.exception);
1100 } else {
1101 loge(command + ": Unknown exception");
1102 }
1103 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001104 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001106 }
1107
1108 /**
1109 * Posts the specified command to be executed on the main thread,
1110 * waits for the request to complete, and returns the result.
1111 * @see #sendRequestAsync
1112 */
1113 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001114 return sendRequest(
1115 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001116 }
1117
1118 /**
1119 * Posts the specified command to be executed on the main thread,
1120 * waits for the request to complete, and returns the result.
1121 * @see #sendRequestAsync
1122 */
1123 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1124 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001125 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001126 }
1127
1128 /**
1129 * Posts the specified command to be executed on the main thread,
1130 * waits for the request to complete, and returns the result.
1131 * @see #sendRequestAsync
1132 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001133 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001134 return sendRequest(command, argument, subId, 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 */
Nathan Harold92bed182018-10-12 18:16:49 -07001142 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1143 return sendRequest(command, argument, subId, null, workSource);
1144 }
1145
1146 /**
1147 * Posts the specified command to be executed on the main thread,
1148 * waits for the request to complete, and returns the result.
1149 * @see #sendRequestAsync
1150 */
1151 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1152 return sendRequest(
1153 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1154 }
1155
1156 /**
1157 * Posts the specified command to be executed on the main thread,
1158 * waits for the request to complete, and returns the result.
1159 * @see #sendRequestAsync
1160 */
1161 private Object sendRequest(
1162 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001163 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1164 throw new RuntimeException("This method will deadlock if called from the main thread.");
1165 }
1166
Nathan Harold92bed182018-10-12 18:16:49 -07001167 MainThreadRequest request = null;
1168 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1169 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1170 } else if (phone != null) {
1171 request = new MainThreadRequest(argument, phone, workSource);
1172 } else {
1173 request = new MainThreadRequest(argument, subId, workSource);
1174 }
1175
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001176 Message msg = mMainThreadHandler.obtainMessage(command, request);
1177 msg.sendToTarget();
1178
1179 // Wait for the request to complete
1180 synchronized (request) {
1181 while (request.result == null) {
1182 try {
1183 request.wait();
1184 } catch (InterruptedException e) {
1185 // Do nothing, go back and wait until the request is complete
1186 }
1187 }
1188 }
1189 return request.result;
1190 }
1191
1192 /**
1193 * Asynchronous ("fire and forget") version of sendRequest():
1194 * Posts the specified command to be executed on the main thread, and
1195 * returns immediately.
1196 * @see #sendRequest
1197 */
1198 private void sendRequestAsync(int command) {
1199 mMainThreadHandler.sendEmptyMessage(command);
1200 }
1201
1202 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001203 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001204 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001205 */
1206 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001207 sendRequestAsync(command, argument, null, null);
1208 }
1209
1210 /**
1211 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1212 * @see {@link #sendRequest(int,Object)}
1213 */
1214 private void sendRequestAsync(
1215 int command, Object argument, Phone phone, WorkSource workSource) {
1216 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001217 Message msg = mMainThreadHandler.obtainMessage(command, request);
1218 msg.sendToTarget();
1219 }
1220
1221 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001222 * Initialize the singleton PhoneInterfaceManager instance.
1223 * This is only done once, at startup, from PhoneApp.onCreate().
1224 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001225 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001226 synchronized (PhoneInterfaceManager.class) {
1227 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001228 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001229 } else {
1230 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1231 }
1232 return sInstance;
1233 }
1234 }
1235
1236 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001237 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001238 mApp = app;
1239 mPhone = phone;
1240 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001241 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001242 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1243 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001244 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001245 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001246 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001247 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001248 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001249
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001250 publish();
1251 }
1252
1253 private void publish() {
1254 if (DBG) log("publish: " + this);
1255
1256 ServiceManager.addService("phone", this);
1257 }
1258
Stuart Scott584921c2015-01-15 17:10:34 -08001259 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001260 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1261 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001262 }
1263
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001264 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1265 Phone phone = getPhoneFromRequest(request);
1266 return phone == null ? null :
1267 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1268 }
1269
Wink Saville36469e72014-06-11 15:17:00 -07001270 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001271 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001272 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001273 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274
1275 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001276 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001277 }
1278
Wink Savilleb564aae2014-10-23 10:18:09 -07001279 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001280 if (DBG) log("dial: " + number);
1281 // No permission check needed here: This is just a wrapper around the
1282 // ACTION_DIAL intent, which is available to any app since it puts up
1283 // the UI before it does anything.
1284
Malcolm Chend965c8b2018-02-28 15:00:40 -08001285 final long identity = Binder.clearCallingIdentity();
1286 try {
1287 String url = createTelUrl(number);
1288 if (url == null) {
1289 return;
1290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001291
Malcolm Chend965c8b2018-02-28 15:00:40 -08001292 // PENDING: should we just silently fail if phone is offhook or ringing?
1293 PhoneConstants.State state = mCM.getState(subId);
1294 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1295 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1296 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1297 mApp.startActivity(intent);
1298 }
1299 } finally {
1300 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001301 }
1302 }
1303
1304 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001305 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001306 }
1307
Wink Savilleb564aae2014-10-23 10:18:09 -07001308 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001309 if (DBG) log("call: " + number);
1310
1311 // This is just a wrapper around the ACTION_CALL intent, but we still
1312 // need to do a permission check since we're calling startActivity()
1313 // from the context of the phone app.
1314 enforceCallPermission();
1315
1316 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1317 != AppOpsManager.MODE_ALLOWED) {
1318 return;
1319 }
1320
Malcolm Chend965c8b2018-02-28 15:00:40 -08001321 final long identity = Binder.clearCallingIdentity();
1322 try {
1323 String url = createTelUrl(number);
1324 if (url == null) {
1325 return;
1326 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327
Malcolm Chend965c8b2018-02-28 15:00:40 -08001328 boolean isValid = false;
1329 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1330 if (slist != null) {
1331 for (SubscriptionInfo subInfoRecord : slist) {
1332 if (subInfoRecord.getSubscriptionId() == subId) {
1333 isValid = true;
1334 break;
1335 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001336 }
Wink Saville08874612014-08-31 19:19:58 -07001337 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001338 if (!isValid) {
1339 return;
1340 }
Wink Saville08874612014-08-31 19:19:58 -07001341
Malcolm Chend965c8b2018-02-28 15:00:40 -08001342 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1343 intent.putExtra(SUBSCRIPTION_KEY, subId);
1344 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1345 mApp.startActivity(intent);
1346 } finally {
1347 Binder.restoreCallingIdentity(identity);
1348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349 }
1350
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001351 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001352 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001353 }
1354
Wink Savilleb564aae2014-10-23 10:18:09 -07001355 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001356 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001357 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1358 }
1359
1360 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001361 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001362 }
1363
Wink Savilleb564aae2014-10-23 10:18:09 -07001364 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001365 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001366 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1367 }
1368
1369 /** {@hide} */
1370 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001371 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001372 }
1373
Wink Savilleb564aae2014-10-23 10:18:09 -07001374 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001376
1377 final long identity = Binder.clearCallingIdentity();
1378 try {
1379 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1380 checkSimPin.start();
1381 return checkSimPin.unlockSim(null, pin);
1382 } finally {
1383 Binder.restoreCallingIdentity(identity);
1384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 }
1386
Wink Saville9de0f752013-10-22 19:04:03 -07001387 /** {@hide} */
1388 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001389 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001390 }
1391
Wink Savilleb564aae2014-10-23 10:18:09 -07001392 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001394
1395 final long identity = Binder.clearCallingIdentity();
1396 try {
1397 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1398 checkSimPuk.start();
1399 return checkSimPuk.unlockSim(puk, pin);
1400 } finally {
1401 Binder.restoreCallingIdentity(identity);
1402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 }
1404
1405 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001406 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 * a synchronous one.
1408 */
1409 private static class UnlockSim extends Thread {
1410
1411 private final IccCard mSimCard;
1412
1413 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001414 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1415 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001416
1417 // For replies from SimCard interface
1418 private Handler mHandler;
1419
1420 // For async handler to identify request type
1421 private static final int SUPPLY_PIN_COMPLETE = 100;
1422
1423 public UnlockSim(IccCard simCard) {
1424 mSimCard = simCard;
1425 }
1426
1427 @Override
1428 public void run() {
1429 Looper.prepare();
1430 synchronized (UnlockSim.this) {
1431 mHandler = new Handler() {
1432 @Override
1433 public void handleMessage(Message msg) {
1434 AsyncResult ar = (AsyncResult) msg.obj;
1435 switch (msg.what) {
1436 case SUPPLY_PIN_COMPLETE:
1437 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1438 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001439 mRetryCount = msg.arg1;
1440 if (ar.exception != null) {
1441 if (ar.exception instanceof CommandException &&
1442 ((CommandException)(ar.exception)).getCommandError()
1443 == CommandException.Error.PASSWORD_INCORRECT) {
1444 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1445 } else {
1446 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1447 }
1448 } else {
1449 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 mDone = true;
1452 UnlockSim.this.notifyAll();
1453 }
1454 break;
1455 }
1456 }
1457 };
1458 UnlockSim.this.notifyAll();
1459 }
1460 Looper.loop();
1461 }
1462
1463 /*
1464 * Use PIN or PUK to unlock SIM card
1465 *
1466 * If PUK is null, unlock SIM card with PIN
1467 *
1468 * If PUK is not null, unlock SIM card with PUK and set PIN code
1469 */
Wink Saville9de0f752013-10-22 19:04:03 -07001470 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471
1472 while (mHandler == null) {
1473 try {
1474 wait();
1475 } catch (InterruptedException e) {
1476 Thread.currentThread().interrupt();
1477 }
1478 }
1479 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1480
1481 if (puk == null) {
1482 mSimCard.supplyPin(pin, callback);
1483 } else {
1484 mSimCard.supplyPuk(puk, pin, callback);
1485 }
1486
1487 while (!mDone) {
1488 try {
1489 Log.d(LOG_TAG, "wait for done");
1490 wait();
1491 } catch (InterruptedException e) {
1492 // Restore the interrupted status
1493 Thread.currentThread().interrupt();
1494 }
1495 }
1496 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001497 int[] resultArray = new int[2];
1498 resultArray[0] = mResult;
1499 resultArray[1] = mRetryCount;
1500 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 }
1502 }
1503
1504 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001505 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001506
1507 }
1508
Wink Savilleb564aae2014-10-23 10:18:09 -07001509 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001510 // No permission check needed here: this call is harmless, and it's
1511 // needed for the ServiceState.requestStateUpdate() call (which is
1512 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001513 final long identity = Binder.clearCallingIdentity();
1514 try {
1515 final Phone phone = getPhone(subId);
1516 if (phone != null) {
1517 phone.updateServiceLocation();
1518 }
1519 } finally {
1520 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522 }
1523
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001524 @Override
1525 public boolean isRadioOn(String callingPackage) {
1526 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001527 }
1528
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001529 @Override
1530 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001532 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001533 return false;
1534 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001535
1536 final long identity = Binder.clearCallingIdentity();
1537 try {
1538 return isRadioOnForSubscriber(subId);
1539 } finally {
1540 Binder.restoreCallingIdentity(identity);
1541 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001542 }
1543
1544 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001545 final long identity = Binder.clearCallingIdentity();
1546 try {
1547 final Phone phone = getPhone(subId);
1548 if (phone != null) {
1549 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1550 } else {
1551 return false;
1552 }
1553 } finally {
1554 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 }
1557
1558 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001559 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001560 }
Wink Saville36469e72014-06-11 15:17:00 -07001561
Wink Savilleb564aae2014-10-23 10:18:09 -07001562 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001564
1565 final long identity = Binder.clearCallingIdentity();
1566 try {
1567 final Phone phone = getPhone(subId);
1568 if (phone != null) {
1569 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1570 }
1571 } finally {
1572 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001573 }
Wink Saville36469e72014-06-11 15:17:00 -07001574 }
1575
1576 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001577 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001578 }
1579
Wink Savilleb564aae2014-10-23 10:18:09 -07001580 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001581 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001582
1583 final long identity = Binder.clearCallingIdentity();
1584 try {
1585 final Phone phone = getPhone(subId);
1586 if (phone == null) {
1587 return false;
1588 }
1589 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1590 toggleRadioOnOffForSubscriber(subId);
1591 }
1592 return true;
1593 } finally {
1594 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001595 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596 }
Wink Saville36469e72014-06-11 15:17:00 -07001597
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001598 public boolean needMobileRadioShutdown() {
1599 /*
1600 * If any of the Radios are available, it will need to be
1601 * shutdown. So return true if any Radio is available.
1602 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001603 final long identity = Binder.clearCallingIdentity();
1604 try {
1605 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1606 Phone phone = PhoneFactory.getPhone(i);
1607 if (phone != null && phone.isRadioAvailable()) return true;
1608 }
1609 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1610 return false;
1611 } finally {
1612 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001613 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001614 }
1615
Malcolm Chend965c8b2018-02-28 15:00:40 -08001616 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001617 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001618 enforceModifyPermission();
1619
1620 final long identity = Binder.clearCallingIdentity();
1621 try {
1622 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1623 logv("Shutting down Phone " + i);
1624 shutdownRadioUsingPhoneId(i);
1625 }
1626 } finally {
1627 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001628 }
1629 }
1630
1631 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001632 Phone phone = PhoneFactory.getPhone(phoneId);
1633 if (phone != null && phone.isRadioAvailable()) {
1634 phone.shutdownRadio();
1635 }
1636 }
1637
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001639 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001640
1641 final long identity = Binder.clearCallingIdentity();
1642 try {
1643 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1644 if (defaultPhone != null) {
1645 defaultPhone.setRadioPower(turnOn);
1646 return true;
1647 } else {
1648 loge("There's no default phone.");
1649 return false;
1650 }
1651 } finally {
1652 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001653 }
Wink Saville36469e72014-06-11 15:17:00 -07001654 }
1655
Wink Savilleb564aae2014-10-23 10:18:09 -07001656 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001658
1659 final long identity = Binder.clearCallingIdentity();
1660 try {
1661 final Phone phone = getPhone(subId);
1662 if (phone != null) {
1663 phone.setRadioPower(turnOn);
1664 return true;
1665 } else {
1666 return false;
1667 }
1668 } finally {
1669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 }
1672
Wink Saville36469e72014-06-11 15:17:00 -07001673 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001674 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 public boolean enableDataConnectivity() {
1676 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001677
1678 final long identity = Binder.clearCallingIdentity();
1679 try {
1680 int subId = mSubscriptionController.getDefaultDataSubId();
1681 final Phone phone = getPhone(subId);
1682 if (phone != null) {
1683 phone.setUserDataEnabled(true);
1684 return true;
1685 } else {
1686 return false;
1687 }
1688 } finally {
1689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 }
1692
Wink Saville36469e72014-06-11 15:17:00 -07001693 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001694 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 public boolean disableDataConnectivity() {
1696 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001697
1698 final long identity = Binder.clearCallingIdentity();
1699 try {
1700 int subId = mSubscriptionController.getDefaultDataSubId();
1701 final Phone phone = getPhone(subId);
1702 if (phone != null) {
1703 phone.setUserDataEnabled(false);
1704 return true;
1705 } else {
1706 return false;
1707 }
1708 } finally {
1709 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001710 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 }
1712
Sanket Padawe356d7632015-06-22 14:03:32 -07001713 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001714 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001715 final long identity = Binder.clearCallingIdentity();
1716 try {
1717 final Phone phone = getPhone(subId);
1718 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001719 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001720 } else {
1721 return false;
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
1728 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001729 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001730 }
1731
pkanwarae03a6b2016-11-06 20:37:09 -08001732 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001733 enforceCallPermission();
1734
1735 final long identity = Binder.clearCallingIdentity();
1736 try {
1737 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1738 return;
1739 }
1740 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1741 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1742 } finally {
1743 Binder.restoreCallingIdentity(identity);
1744 }
pkanwar32d516d2016-10-14 19:37:38 -07001745 };
1746
Wink Savilleb564aae2014-10-23 10:18:09 -07001747 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001749
1750 final long identity = Binder.clearCallingIdentity();
1751 try {
1752 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1753 return false;
1754 }
1755 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1756 } finally {
1757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001758 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 }
1760
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001762 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001763 }
1764
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001765 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001766 final long identity = Binder.clearCallingIdentity();
1767 try {
1768 Phone phone = PhoneFactory.getPhone(slotIndex);
1769 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1770 PhoneConstantConversions.convertCallState(phone.getState());
1771 } finally {
1772 Binder.restoreCallingIdentity(identity);
1773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 }
1775
Sanket Padawe356d7632015-06-22 14:03:32 -07001776 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001778 final long identity = Binder.clearCallingIdentity();
1779 try {
1780 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1781 if (phone != null) {
1782 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1783 } else {
1784 return PhoneConstantConversions.convertDataState(
1785 PhoneConstants.DataState.DISCONNECTED);
1786 }
1787 } finally {
1788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 }
1791
Sanket Padawe356d7632015-06-22 14:03:32 -07001792 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001794 final long identity = Binder.clearCallingIdentity();
1795 try {
1796 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1797 if (phone != null) {
1798 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1799 } else {
1800 return TelephonyManager.DATA_ACTIVITY_NONE;
1801 }
1802 } finally {
1803 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001804 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 }
1806
1807 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001808 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001809 mPhone.getContext().getSystemService(AppOpsManager.class)
1810 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001811 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001812 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001813 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 }
1815
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001816 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001817 final long identity = Binder.clearCallingIdentity();
1818 try {
1819 if (DBG_LOC) log("getCellLocation: is active user");
1820 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001821 int subId = mSubscriptionController.getDefaultDataSubId();
1822 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1823 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001824 return data;
1825 } finally {
1826 Binder.restoreCallingIdentity(identity);
1827 }
Svetoslav64fad262015-04-14 14:35:21 -07001828 }
1829
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001831 public String getNetworkCountryIsoForPhone(int phoneId) {
1832 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1833 // registered cell info, so return a NULL country instead.
1834 final long identity = Binder.clearCallingIdentity();
1835 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001836 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1837 // Get default phone in this case.
1838 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1839 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001840 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001841 // Todo: fix this when we can get the actual cellular network info when the device
1842 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001843 if (TelephonyManager.NETWORK_TYPE_IWLAN
1844 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1845 return "";
1846 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001847 Phone phone = PhoneFactory.getPhone(phoneId);
1848 if (phone != null) {
1849 ServiceStateTracker sst = phone.getServiceStateTracker();
1850 if (sst != null) {
1851 LocaleTracker lt = sst.getLocaleTracker();
1852 if (lt != null) {
1853 return lt.getCurrentCountry();
1854 }
1855 }
1856 }
1857 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001858 } finally {
1859 Binder.restoreCallingIdentity(identity);
1860 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001861 }
1862
1863 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001864 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001865 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001866 }
1867
Sanket Padawe356d7632015-06-22 14:03:32 -07001868 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001869 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 mApp.enforceCallingOrSelfPermission(
1871 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001872
1873 final long identity = Binder.clearCallingIdentity();
1874 try {
1875 final Phone phone = getPhone(subId);
1876 if (phone != null) {
1877 phone.enableLocationUpdates();
1878 }
1879 } finally {
1880 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 }
1883
1884 @Override
1885 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001886 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001887 }
1888
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001890 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 mApp.enforceCallingOrSelfPermission(
1892 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001893
1894 final long identity = Binder.clearCallingIdentity();
1895 try {
1896 final Phone phone = getPhone(subId);
1897 if (phone != null) {
1898 phone.disableLocationUpdates();
1899 }
1900 } finally {
1901 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 }
1904
Nathan Harold31d7ff32018-10-15 20:20:30 -07001905 /**
1906 * Returns the target SDK version number for a given package name.
1907 *
1908 * @return target SDK if the package is found or INT_MAX.
1909 */
1910 private int getTargetSdk(String packageName) {
1911 try {
1912 final ApplicationInfo ai =
1913 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1914 if (ai != null) return ai.targetSdkVersion;
1915 } catch (PackageManager.NameNotFoundException unexpected) {
1916 }
1917 return Integer.MAX_VALUE;
1918 }
1919
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 @Override
1921 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001922 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1923 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001924 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1925 throw new SecurityException(
1926 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1927 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001928
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1930 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1931 return null;
1932 }
Svetoslav64fad262015-04-14 14:35:21 -07001933
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001934 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001935
Nathan Haroldf180aac2018-06-01 18:43:55 -07001936 List<CellInfo> info = getAllCellInfo(callingPackage);
1937 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938
Nathan Haroldf180aac2018-06-01 18:43:55 -07001939 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1940 for (CellInfo ci : info) {
1941 if (ci instanceof CellInfoGsm) {
1942 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1943 } else if (ci instanceof CellInfoWcdma) {
1944 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001947 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948 }
1949
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001950 private List<CellInfo> getCachedCellInfo() {
1951 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1952 for (Phone phone : PhoneFactory.getPhones()) {
1953 List<CellInfo> info = phone.getAllCellInfo();
1954 if (info != null) cellInfos.addAll(info);
1955 }
1956 return cellInfos;
1957 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958
1959 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001960 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001961 mPhone.getContext().getSystemService(AppOpsManager.class)
1962 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001963 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001964 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001965 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 }
1967
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001968 final int targetSdk = getTargetSdk(callingPackage);
1969 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1970 return getCachedCellInfo();
1971 }
1972
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001973 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001974 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001975 final long identity = Binder.clearCallingIdentity();
1976 try {
1977 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1978 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001979 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001980 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001981 if (info != null) cellInfos.addAll(info);
1982 }
1983 return cellInfos;
1984 } finally {
1985 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001986 }
1987 }
1988
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001989 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001990 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
1991 requestCellInfoUpdateInternal(
1992 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
1993 }
1994
1995 @Override
1996 public void requestCellInfoUpdateWithWorkSource(
1997 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
1998 enforceModifyPermission();
1999 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2000 }
2001
2002 private void requestCellInfoUpdateInternal(
2003 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2004 mPhone.getContext().getSystemService(AppOpsManager.class)
2005 .checkPackage(Binder.getCallingUid(), callingPackage);
2006 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
2007 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
2008 return;
2009 }
2010
2011 final Phone phone = getPhone(subId);
2012 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2013
2014 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2015 }
2016
2017 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002019 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002020 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002021
2022 final long identity = Binder.clearCallingIdentity();
2023 try {
2024 mPhone.setCellInfoListRate(rateInMillis, workSource);
2025 } finally {
2026 Binder.restoreCallingIdentity(identity);
2027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 }
2029
Shishir Agrawala9f32182016-04-12 12:00:16 -07002030 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002031 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002032 Phone phone = PhoneFactory.getPhone(slotIndex);
2033 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002034 return null;
2035 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002036 int subId = phone.getSubId();
2037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2038 mApp, subId, callingPackage, "getImeiForSlot")) {
2039 return null;
2040 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002041
2042 final long identity = Binder.clearCallingIdentity();
2043 try {
2044 return phone.getImei();
2045 } finally {
2046 Binder.restoreCallingIdentity(identity);
2047 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002048 }
2049
2050 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002051 public String getTypeAllocationCodeForSlot(int slotIndex) {
2052 Phone phone = PhoneFactory.getPhone(slotIndex);
2053 String tac = null;
2054 if (phone != null) {
2055 String imei = phone.getImei();
2056 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2057 }
2058 return tac;
2059 }
2060
2061 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002062 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002063 Phone phone = PhoneFactory.getPhone(slotIndex);
2064 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002065 return null;
2066 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002067 int subId = phone.getSubId();
2068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2069 mApp, subId, callingPackage, "getMeidForSlot")) {
2070 return null;
2071 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002072
2073 final long identity = Binder.clearCallingIdentity();
2074 try {
2075 return phone.getMeid();
2076 } finally {
2077 Binder.restoreCallingIdentity(identity);
2078 }
Jack Yu2af8d712017-03-15 17:14:14 -07002079 }
2080
2081 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002082 public String getManufacturerCodeForSlot(int slotIndex) {
2083 Phone phone = PhoneFactory.getPhone(slotIndex);
2084 String manufacturerCode = null;
2085 if (phone != null) {
2086 String meid = phone.getMeid();
2087 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2088 }
2089 return manufacturerCode;
2090 }
2091
2092 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002093 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002094 Phone phone = PhoneFactory.getPhone(slotIndex);
2095 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002096 return null;
2097 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002098 int subId = phone.getSubId();
2099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2100 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2101 return null;
2102 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002103
2104 final long identity = Binder.clearCallingIdentity();
2105 try {
2106 return phone.getDeviceSvn();
2107 } finally {
2108 Binder.restoreCallingIdentity(identity);
2109 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002110 }
2111
fionaxu43304da2017-11-27 22:51:16 -08002112 @Override
2113 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 final Phone phone = getPhone(subId);
2117 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2118 } finally {
2119 Binder.restoreCallingIdentity(identity);
2120 }
fionaxu43304da2017-11-27 22:51:16 -08002121 }
2122
2123 @Override
2124 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002125 final long identity = Binder.clearCallingIdentity();
2126 try {
2127 final Phone phone = getPhone(subId);
2128 return phone == null ? null : phone.getCarrierName();
2129 } finally {
2130 Binder.restoreCallingIdentity(identity);
2131 }
fionaxu43304da2017-11-27 22:51:16 -08002132 }
2133
calvinpaneed9ae82018-11-01 19:43:06 +08002134 @Override
2135 public int getSubscriptionMNOCarrierId(int subId) {
2136 final long identity = Binder.clearCallingIdentity();
2137 try {
2138 final Phone phone = getPhone(subId);
2139 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId();
2140 } finally {
2141 Binder.restoreCallingIdentity(identity);
2142 }
2143 }
2144
chen xuc93cc282018-11-04 17:17:00 -08002145 @Override
2146 public int getSubscriptionPreciseCarrierId(int subId) {
2147 final long identity = Binder.clearCallingIdentity();
2148 try {
2149 final Phone phone = getPhone(subId);
2150 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2151 : phone.getPreciseCarrierId();
2152 } finally {
2153 Binder.restoreCallingIdentity(identity);
2154 }
2155 }
2156
2157 @Override
2158 public String getSubscriptionPreciseCarrierName(int subId) {
2159 final long identity = Binder.clearCallingIdentity();
2160 try {
2161 final Phone phone = getPhone(subId);
2162 return phone == null ? null : phone.getPreciseCarrierName();
2163 } finally {
2164 Binder.restoreCallingIdentity(identity);
2165 }
2166 }
2167
chen xu02581692018-11-11 19:03:44 -08002168 @Override
2169 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc) {
2170 final Phone phone = PhoneFactory.getPhone(slotIndex);
2171 if (phone == null) {
2172 return TelephonyManager.UNKNOWN_CARRIER_ID;
2173 }
2174 final long identity = Binder.clearCallingIdentity();
2175 try {
2176 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2177 } finally {
2178 Binder.restoreCallingIdentity(identity);
2179 }
2180 }
2181
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 //
2183 // Internal helper methods.
2184 //
2185
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002186 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002187 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2188 *
2189 * @throws SecurityException if the caller does not have the required permission
2190 */
2191 private void enforceModifyPermission() {
2192 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2193 }
2194
2195 /**
2196 * Make sure the caller has the CALL_PHONE permission.
2197 *
2198 * @throws SecurityException if the caller does not have the required permission
2199 */
2200 private void enforceCallPermission() {
2201 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2202 }
2203
Stuart Scott8eef64f2015-04-08 15:13:54 -07002204 private void enforceConnectivityInternalPermission() {
2205 mApp.enforceCallingOrSelfPermission(
2206 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2207 "ConnectivityService");
2208 }
2209
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 private String createTelUrl(String number) {
2211 if (TextUtils.isEmpty(number)) {
2212 return null;
2213 }
2214
Jake Hambye994d462014-02-03 13:10:13 -08002215 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 }
2217
Ihab Awadf9e92732013-12-05 18:02:52 -08002218 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2220 }
2221
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002222 private static void logv(String msg) {
2223 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2224 }
2225
Ihab Awadf9e92732013-12-05 18:02:52 -08002226 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2228 }
2229
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002230 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002232 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002233 }
2234
Sanket Padawe356d7632015-06-22 14:03:32 -07002235 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002236 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002237 final long identity = Binder.clearCallingIdentity();
2238 try {
2239 final Phone phone = PhoneFactory.getPhone(slotIndex);
2240 if (phone == null) {
2241 return PhoneConstants.PHONE_TYPE_NONE;
2242 } else {
2243 return phone.getPhoneType();
2244 }
2245 } finally {
2246 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002247 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 }
2249
2250 /**
2251 * Returns the CDMA ERI icon index to display
2252 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002253 @Override
2254 public int getCdmaEriIconIndex(String callingPackage) {
2255 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002256 }
2257
Sanket Padawe356d7632015-06-22 14:03:32 -07002258 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002259 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002261 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002262 return -1;
2263 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002264
2265 final long identity = Binder.clearCallingIdentity();
2266 try {
2267 final Phone phone = getPhone(subId);
2268 if (phone != null) {
2269 return phone.getCdmaEriIconIndex();
2270 } else {
2271 return -1;
2272 }
2273 } finally {
2274 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 }
2277
2278 /**
2279 * Returns the CDMA ERI icon mode,
2280 * 0 - ON
2281 * 1 - FLASHING
2282 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002283 @Override
2284 public int getCdmaEriIconMode(String callingPackage) {
2285 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002286 }
2287
Sanket Padawe356d7632015-06-22 14:03:32 -07002288 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002289 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002291 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002292 return -1;
2293 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002294
2295 final long identity = Binder.clearCallingIdentity();
2296 try {
2297 final Phone phone = getPhone(subId);
2298 if (phone != null) {
2299 return phone.getCdmaEriIconMode();
2300 } else {
2301 return -1;
2302 }
2303 } finally {
2304 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002305 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 }
2307
2308 /**
2309 * Returns the CDMA ERI text,
2310 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002311 @Override
2312 public String getCdmaEriText(String callingPackage) {
2313 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002314 }
2315
Sanket Padawe356d7632015-06-22 14:03:32 -07002316 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002317 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002318 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002319 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002320 return null;
2321 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002322
2323 final long identity = Binder.clearCallingIdentity();
2324 try {
2325 final Phone phone = getPhone(subId);
2326 if (phone != null) {
2327 return phone.getCdmaEriText();
2328 } else {
2329 return null;
2330 }
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 }
2335
2336 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002337 * Returns the CDMA MDN.
2338 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002339 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002340 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2342 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002343
2344 final long identity = Binder.clearCallingIdentity();
2345 try {
2346 final Phone phone = getPhone(subId);
2347 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2348 return phone.getLine1Number();
2349 } else {
2350 return null;
2351 }
2352 } finally {
2353 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002354 }
2355 }
2356
2357 /**
2358 * Returns the CDMA MIN.
2359 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002360 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002361 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2363 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002364
2365 final long identity = Binder.clearCallingIdentity();
2366 try {
2367 final Phone phone = getPhone(subId);
2368 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2369 return phone.getCdmaMin();
2370 } else {
2371 return null;
2372 }
2373 } finally {
2374 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002375 }
2376 }
2377
2378 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 * Returns true if CDMA provisioning needs to run.
2380 */
2381 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002382 final long identity = Binder.clearCallingIdentity();
2383 try {
2384 return mPhone.needsOtaServiceProvisioning();
2385 } finally {
2386 Binder.restoreCallingIdentity(identity);
2387 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 }
2389
2390 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002391 * Sets the voice mail number of a given subId.
2392 */
2393 @Override
2394 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002395 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002396
2397 final long identity = Binder.clearCallingIdentity();
2398 try {
2399 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2400 new Pair<String, String>(alphaTag, number), new Integer(subId));
2401 return success;
2402 } finally {
2403 Binder.restoreCallingIdentity(identity);
2404 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002405 }
2406
Ta-wei Yen87c49842016-05-13 21:19:52 -07002407 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002408 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2409 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2410 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2411 if (!TextUtils.equals(callingPackage, systemDialer)) {
2412 throw new SecurityException("caller must be system dialer");
2413 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002414
2415 final long identity = Binder.clearCallingIdentity();
2416 try {
2417 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2418 if (phoneAccountHandle == null) {
2419 return null;
2420 }
2421 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2422 } finally {
2423 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002424 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002425 }
2426
2427 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002428 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002429 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002430 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002431 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002432 return null;
2433 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002434
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002435 final long identity = Binder.clearCallingIdentity();
2436 try {
2437 return RemoteVvmTaskManager
2438 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2439 } finally {
2440 Binder.restoreCallingIdentity(identity);
2441 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002442 }
2443
2444 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002445 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2446 VisualVoicemailSmsFilterSettings settings) {
2447 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002448
2449 final long identity = Binder.clearCallingIdentity();
2450 try {
2451 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2452 mPhone.getContext(), callingPackage, subId, settings);
2453 } finally {
2454 Binder.restoreCallingIdentity(identity);
2455 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002456 }
2457
2458 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002459 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2460 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002461
2462 final long identity = Binder.clearCallingIdentity();
2463 try {
2464 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2465 mPhone.getContext(), callingPackage, subId);
2466 } finally {
2467 Binder.restoreCallingIdentity(identity);
2468 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002469 }
2470
2471 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002472 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2473 String callingPackage, int subId) {
2474 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002475
2476 final long identity = Binder.clearCallingIdentity();
2477 try {
2478 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2479 mPhone.getContext(), callingPackage, subId);
2480 } finally {
2481 Binder.restoreCallingIdentity(identity);
2482 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002483 }
2484
2485 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002486 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002487 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002488
2489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2492 mPhone.getContext(), subId);
2493 } finally {
2494 Binder.restoreCallingIdentity(identity);
2495 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002496 }
2497
2498 @Override
2499 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2500 String number, int port, String text, PendingIntent sentIntent) {
2501 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002502 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002503 enforceSendSmsPermission();
2504 // Make the calls as the phone process.
2505 final long identity = Binder.clearCallingIdentity();
2506 try {
2507 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2508 if (port == 0) {
2509 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2510 sentIntent, null, false);
2511 } else {
2512 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2513 smsManager.sendDataMessageWithSelfPermissions(number, null,
2514 (short) port, data, sentIntent, null);
2515 }
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
2518 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002519 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002520 /**
fionaxu0152e512016-11-14 13:36:14 -08002521 * Sets the voice activation state of a given subId.
2522 */
2523 @Override
2524 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2526 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002527
2528 final long identity = Binder.clearCallingIdentity();
2529 try {
2530 final Phone phone = getPhone(subId);
2531 if (phone != null) {
2532 phone.setVoiceActivationState(activationState);
2533 } else {
2534 loge("setVoiceActivationState fails with invalid subId: " + subId);
2535 }
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002538 }
2539 }
2540
2541 /**
2542 * Sets the data activation state of a given subId.
2543 */
2544 @Override
2545 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2547 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002548
2549 final long identity = Binder.clearCallingIdentity();
2550 try {
2551 final Phone phone = getPhone(subId);
2552 if (phone != null) {
2553 phone.setDataActivationState(activationState);
2554 } else {
2555 loge("setVoiceActivationState fails with invalid subId: " + subId);
2556 }
2557 } finally {
2558 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002559 }
2560 }
2561
2562 /**
2563 * Returns the voice activation state of a given subId.
2564 */
2565 @Override
2566 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002567 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002568
fionaxu0152e512016-11-14 13:36:14 -08002569 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 if (phone != null) {
2573 return phone.getVoiceActivationState();
2574 } else {
2575 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2576 }
2577 } finally {
2578 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002579 }
2580 }
2581
2582 /**
2583 * Returns the data activation state of a given subId.
2584 */
2585 @Override
2586 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002587 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002588
fionaxu0152e512016-11-14 13:36:14 -08002589 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002590 final long identity = Binder.clearCallingIdentity();
2591 try {
2592 if (phone != null) {
2593 return phone.getDataActivationState();
2594 } else {
2595 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2596 }
2597 } finally {
2598 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002599 }
2600 }
2601
2602 /**
Wink Saville36469e72014-06-11 15:17:00 -07002603 * Returns the unread count of voicemails for a subId
2604 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002605 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002606 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2608 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2609 return 0;
2610 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002611 final long identity = Binder.clearCallingIdentity();
2612 try {
2613 final Phone phone = getPhone(subId);
2614 if (phone != null) {
2615 return phone.getVoiceMessageCount();
2616 } else {
2617 return 0;
2618 }
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002622 }
2623
2624 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002625 * returns true, if the device is in a state where both voice and data
2626 * are supported simultaneously. This can change based on location or network condition.
2627 */
2628 @Override
2629 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002630 final long identity = Binder.clearCallingIdentity();
2631 try {
2632 final Phone phone = getPhone(subId);
2633 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2634 } finally {
2635 Binder.restoreCallingIdentity(identity);
2636 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002637 }
2638
2639 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002640 * Send the dialer code if called from the current default dialer or the caller has
2641 * carrier privilege.
2642 * @param inputCode The dialer code to send
2643 */
2644 @Override
2645 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2646 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2647 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2648 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002649 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2650 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002651 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002652
2653 final long identity = Binder.clearCallingIdentity();
2654 try {
2655 mPhone.sendDialerSpecialCode(inputCode);
2656 } finally {
2657 Binder.restoreCallingIdentity(identity);
2658 }
fionaxu235cc5e2017-03-06 22:25:57 -08002659 }
2660
2661 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002662 * Returns the data network type.
2663 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002664 *
2665 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2666 */
2667 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002668 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002669 final long identity = Binder.clearCallingIdentity();
2670 try {
2671 final Phone phone = getPhone(getDefaultSubscription());
2672 if (phone != null) {
2673 return phone.getServiceState().getDataNetworkType();
2674 } else {
2675 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2676 }
2677 } finally {
2678 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002679 }
Wink Saville36469e72014-06-11 15:17:00 -07002680 }
2681
Pengquan Meng0c05b502018-09-06 09:59:22 -07002682 @Override
2683 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002684 if (!isActiveSubscription(subId)) {
2685 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2686 }
2687
Pengquan Meng0c05b502018-09-06 09:59:22 -07002688 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2689 }
2690
Brad Ebinger4c460712018-10-01 10:40:55 -07002691 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002692 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2693 throws RemoteException {
2694 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002695 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2696 final long token = Binder.clearCallingIdentity();
2697 try {
2698 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2699 .addRegistrationCallbackForSubscription(c, subId);
2700 } finally {
2701 Binder.restoreCallingIdentity(token);
2702 }
2703 }
2704
2705 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002706 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2707 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002708 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2709 Binder.withCleanCallingIdentity(() ->
2710 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2711 .removeRegistrationCallbackForSubscription(c, subId));
2712 }
2713
2714 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002715 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2716 throws RemoteException {
2717 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002718 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2719 final long token = Binder.clearCallingIdentity();
2720 try {
2721 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2722 .addCapabilitiesCallbackForSubscription(c, subId);
2723 } finally {
2724 Binder.restoreCallingIdentity(token);
2725 }
2726 }
2727
2728 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002729 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2730 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002731 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2732 Binder.withCleanCallingIdentity(() ->
2733 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2734 .removeCapabilitiesCallbackForSubscription(c, subId));
2735 }
2736
2737 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002738 public boolean isCapable(int subId, int capability, int regTech) {
2739 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002740 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2741 final long token = Binder.clearCallingIdentity();
2742 try {
2743 return ImsManager.getInstance(mPhone.getContext(),
2744 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2745 } catch (ImsException e) {
2746 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2747 return false;
2748 } finally {
2749 Binder.restoreCallingIdentity(token);
2750 }
2751 }
2752
2753 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002754 public boolean isAvailable(int subId, int capability, int regTech) {
2755 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002756 final long token = Binder.clearCallingIdentity();
2757 try {
2758 Phone phone = getPhone(subId);
2759 if (phone == null) return false;
2760 return phone.isImsCapabilityAvailable(capability, regTech);
2761 } finally {
2762 Binder.restoreCallingIdentity(token);
2763 }
2764 }
2765
2766 @Override
2767 public boolean isAdvancedCallingSettingEnabled(int subId) {
2768 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2769 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2770 final long token = Binder.clearCallingIdentity();
2771 try {
2772 return ImsManager.getInstance(mPhone.getContext(),
2773 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2774 } finally {
2775 Binder.restoreCallingIdentity(token);
2776 }
2777 }
2778
2779 @Override
2780 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2782 "setAdvancedCallingSetting");
2783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2786 ImsManager.getInstance(mPhone.getContext(),
2787 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2788 } finally {
2789 Binder.restoreCallingIdentity(identity);
2790 }
2791 }
2792
2793 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002794 public boolean isVtSettingEnabled(int subId) {
2795 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002796 final long identity = Binder.clearCallingIdentity();
2797 try {
2798 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2799 return ImsManager.getInstance(mPhone.getContext(),
2800 getSlotIndexOrException(subId)).isVtEnabledByUser();
2801 } finally {
2802 Binder.restoreCallingIdentity(identity);
2803 }
2804 }
2805
2806 @Override
2807 public void setVtSetting(int subId, boolean isEnabled) {
2808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2809 "setVtSetting");
2810 final long identity = Binder.clearCallingIdentity();
2811 try {
2812 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2813 ImsManager.getInstance(mPhone.getContext(),
2814 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
2817 }
2818 }
2819
2820 @Override
2821 public boolean isVoWiFiSettingEnabled(int subId) {
2822 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2826 return ImsManager.getInstance(mPhone.getContext(),
2827 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
2830 }
2831 }
2832
2833 @Override
2834 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2836 "setVoWiFiSetting");
2837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2840 ImsManager.getInstance(mPhone.getContext(),
2841 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
2844 }
2845 }
2846
2847 @Override
2848 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2849 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2853 return ImsManager.getInstance(mPhone.getContext(),
2854 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2855 } finally {
2856 Binder.restoreCallingIdentity(identity);
2857 }
2858 }
2859
2860 @Override
2861 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2863 "setVoWiFiRoamingSetting");
2864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2867 ImsManager.getInstance(mPhone.getContext(),
2868 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
2871 }
2872 }
2873
2874 @Override
2875 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2877 "setVoWiFiNonPersistent");
2878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2881 ImsManager.getInstance(mPhone.getContext(),
2882 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2883 } finally {
2884 Binder.restoreCallingIdentity(identity);
2885 }
2886 }
2887
2888 @Override
2889 public int getVoWiFiModeSetting(int subId) {
2890 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2894 return ImsManager.getInstance(mPhone.getContext(),
2895 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2896 } finally {
2897 Binder.restoreCallingIdentity(identity);
2898 }
2899 }
2900
2901 @Override
2902 public void setVoWiFiModeSetting(int subId, int mode) {
2903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2904 "setVoWiFiModeSetting");
2905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2908 ImsManager.getInstance(mPhone.getContext(),
2909 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
2912 }
2913 }
2914
2915 @Override
2916 public int getVoWiFiRoamingModeSetting(int subId) {
2917 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2918 final long identity = Binder.clearCallingIdentity();
2919 try {
2920 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2921 return ImsManager.getInstance(mPhone.getContext(),
2922 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2923 } finally {
2924 Binder.restoreCallingIdentity(identity);
2925 }
2926 }
2927
2928 @Override
2929 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2930 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2931 "setVoWiFiRoamingModeSetting");
2932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2935 ImsManager.getInstance(mPhone.getContext(),
2936 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2937 } finally {
2938 Binder.restoreCallingIdentity(identity);
2939 }
2940 }
2941
2942 @Override
2943 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2945 "setRttCapabilityEnabled");
2946 final long identity = Binder.clearCallingIdentity();
2947 try {
2948 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2949 ImsManager.getInstance(mPhone.getContext(),
2950 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
2953 }
2954 }
2955
2956 @Override
2957 public boolean isTtyOverVolteEnabled(int subId) {
2958 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2962 return ImsManager.getInstance(mPhone.getContext(),
2963 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2964 } finally {
2965 Binder.restoreCallingIdentity(identity);
2966 }
2967 }
2968
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002969 @Override
2970 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2971 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
2972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2975 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2976 .getConfigInterface().addConfigCallback(callback);
2977 } catch (ImsException e) {
2978 throw new IllegalArgumentException(e.getMessage());
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
2985 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2986 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
2987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2990 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2991 .getConfigInterface().removeConfigCallback(callback);
2992 } catch (ImsException e) {
2993 throw new IllegalArgumentException(e.getMessage());
2994 } finally {
2995 Binder.restoreCallingIdentity(identity);
2996 }
2997 }
2998
2999 @Override
3000 public int getImsProvisioningInt(int subId, int key) {
3001 enforceReadPrivilegedPermission("getImsProvisioningInt");
3002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3005 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3006 .getConfigInterface().getConfigInt(key);
3007 } catch (ImsException e) {
3008 throw new IllegalArgumentException(e.getMessage());
3009 } finally {
3010 Binder.restoreCallingIdentity(identity);
3011 }
3012 }
3013
3014 @Override
3015 public String getImsProvisioningString(int subId, int key) {
3016 enforceReadPrivilegedPermission("getImsProvisioningString");
3017 final long identity = Binder.clearCallingIdentity();
3018 try {
3019 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3020 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3021 .getConfigInterface().getConfigString(key);
3022 } catch (ImsException e) {
3023 throw new IllegalArgumentException(e.getMessage());
3024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
3027 }
3028
3029 @Override
3030 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3032 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3036 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3037 .getConfigInterface().setConfig(key, value);
3038 } catch (ImsException e) {
3039 throw new IllegalArgumentException(e.getMessage());
3040 } finally {
3041 Binder.restoreCallingIdentity(identity);
3042 }
3043 }
3044
3045 @Override
3046 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3048 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3052 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3053 .getConfigInterface().setConfig(key, value);
3054 } catch (ImsException e) {
3055 throw new IllegalArgumentException(e.getMessage());
3056 } finally {
3057 Binder.restoreCallingIdentity(identity);
3058 }
3059 }
3060
Brad Ebinger4c460712018-10-01 10:40:55 -07003061 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3062 int slotId = SubscriptionManager.getSlotIndex(subId);
3063 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3064 throw new IllegalArgumentException("Invalid Subscription Id.");
3065 }
3066 return slotId;
3067 }
3068
Wink Saville36469e72014-06-11 15:17:00 -07003069 /**
3070 * Returns the network type for a subId
3071 */
3072 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003073 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003075 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003076 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3077 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003078
Malcolm Chend965c8b2018-02-28 15:00:40 -08003079 final long identity = Binder.clearCallingIdentity();
3080 try {
3081 final Phone phone = getPhone(subId);
3082 if (phone != null) {
3083 return phone.getServiceState().getDataNetworkType();
3084 } else {
3085 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3086 }
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003090 }
3091
3092 /**
3093 * Returns the data network type
3094 */
3095 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003096 public int getDataNetworkType(String callingPackage) {
3097 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003098 }
3099
3100 /**
3101 * Returns the data network type for a subId
3102 */
3103 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003104 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003105 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003106 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003107 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3108 }
3109
Malcolm Chend965c8b2018-02-28 15:00:40 -08003110 final long identity = Binder.clearCallingIdentity();
3111 try {
3112 final Phone phone = getPhone(subId);
3113 if (phone != null) {
3114 return phone.getServiceState().getDataNetworkType();
3115 } else {
3116 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3117 }
3118 } finally {
3119 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003120 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003121 }
3122
3123 /**
Wink Saville36469e72014-06-11 15:17:00 -07003124 * Returns the Voice network type for a subId
3125 */
3126 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003127 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003129 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003130 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3131 }
3132
Malcolm Chend965c8b2018-02-28 15:00:40 -08003133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 final Phone phone = getPhone(subId);
3136 if (phone != null) {
3137 return phone.getServiceState().getVoiceNetworkType();
3138 } else {
3139 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3140 }
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144 }
3145
3146 /**
3147 * @return true if a ICC card is present
3148 */
3149 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003150 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003151 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3152 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003153 }
3154
3155 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003156 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003157 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003158 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003159 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003160 final long identity = Binder.clearCallingIdentity();
3161 try {
3162 final Phone phone = PhoneFactory.getPhone(slotIndex);
3163 if (phone != null) {
3164 return phone.getIccCard().hasIccCard();
3165 } else {
3166 return false;
3167 }
3168 } finally {
3169 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003170 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003171 }
3172
3173 /**
3174 * Return if the current radio is LTE on CDMA. This
3175 * is a tri-state return value as for a period of time
3176 * the mode may be unknown.
3177 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003178 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003179 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003180 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003181 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003182 @Override
3183 public int getLteOnCdmaMode(String callingPackage) {
3184 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003185 }
3186
Sanket Padawe356d7632015-06-22 14:03:32 -07003187 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003188 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003190 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003191 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3192 }
3193
Malcolm Chend965c8b2018-02-28 15:00:40 -08003194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 final Phone phone = getPhone(subId);
3197 if (phone == null) {
3198 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3199 } else {
3200 return phone.getLteOnCdmaMode();
3201 }
3202 } finally {
3203 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003204 }
Wink Saville36469e72014-06-11 15:17:00 -07003205 }
3206
3207 public void setPhone(Phone phone) {
3208 mPhone = phone;
3209 }
3210
3211 /**
3212 * {@hide}
3213 * Returns Default subId, 0 in the case of single standby.
3214 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003215 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003216 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003217 }
3218
Shishir Agrawala9f32182016-04-12 12:00:16 -07003219 private int getSlotForDefaultSubscription() {
3220 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3221 }
3222
Wink Savilleb564aae2014-10-23 10:18:09 -07003223 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003224 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003225 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003226
Pengquan Meng466e2482018-09-21 15:54:48 -07003227 private boolean isActiveSubscription(int subId) {
3228 return mSubscriptionController.isActiveSubId(subId);
3229 }
3230
Ihab Awadf2177b72013-11-25 13:33:23 -08003231 /**
3232 * @see android.telephony.TelephonyManager.WifiCallingChoices
3233 */
3234 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003235 final long identity = Binder.clearCallingIdentity();
3236 try {
3237 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3238 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3239 getWhenToMakeWifiCallsDefaultPreference());
3240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003243 }
3244
3245 /**
3246 * @see android.telephony.TelephonyManager.WifiCallingChoices
3247 */
3248 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003249 final long identity = Binder.clearCallingIdentity();
3250 try {
3251 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3252 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3253 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3254 } finally {
3255 Binder.restoreCallingIdentity(identity);
3256 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003257 }
3258
Sailesh Nepald1e68152013-12-12 19:08:02 -08003259 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003260 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003261 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003262 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003263
Shishir Agrawal566b7612013-10-28 14:41:00 -07003264 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003265 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3266 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3268 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003269 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003270
Malcolm Chend965c8b2018-02-28 15:00:40 -08003271 final long identity = Binder.clearCallingIdentity();
3272 try {
3273 if (TextUtils.equals(ISDR_AID, aid)) {
3274 // Only allows LPA to open logical channel to ISD-R.
3275 ComponentInfo bestComponent =
3276 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3277 if (bestComponent == null
3278 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3279 loge("The calling package is not allowed to access ISD-R.");
3280 throw new SecurityException(
3281 "The calling package is not allowed to access ISD-R.");
3282 }
Derek Tan740e1672017-06-27 14:56:27 -07003283 }
Derek Tan740e1672017-06-27 14:56:27 -07003284
Malcolm Chend965c8b2018-02-28 15:00:40 -08003285 if (DBG) {
3286 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3287 }
3288 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3289 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3290 if (DBG) log("iccOpenLogicalChannel: " + response);
3291 return response;
3292 } finally {
3293 Binder.restoreCallingIdentity(identity);
3294 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003295 }
3296
3297 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003298 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3300 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003301
Malcolm Chend965c8b2018-02-28 15:00:40 -08003302 final long identity = Binder.clearCallingIdentity();
3303 try {
3304 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3305 if (channel < 0) {
3306 return false;
3307 }
3308 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3309 if (DBG) log("iccCloseLogicalChannel: " + success);
3310 return success;
3311 } finally {
3312 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003313 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003314 }
3315
3316 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003317 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003318 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3320 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003321
Malcolm Chend965c8b2018-02-28 15:00:40 -08003322 final long identity = Binder.clearCallingIdentity();
3323 try {
3324 if (DBG) {
3325 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3326 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3327 + p3 + " data=" + data);
3328 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003329
Malcolm Chend965c8b2018-02-28 15:00:40 -08003330 if (channel < 0) {
3331 return "";
3332 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003333
Malcolm Chend965c8b2018-02-28 15:00:40 -08003334 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3335 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3336 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003337
Malcolm Chend965c8b2018-02-28 15:00:40 -08003338 // Append the returned status code to the end of the response payload.
3339 String s = Integer.toHexString(
3340 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3341 if (response.payload != null) {
3342 s = IccUtils.bytesToHexString(response.payload) + s;
3343 }
3344 return s;
3345 } finally {
3346 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003347 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003348 }
Jake Hambye994d462014-02-03 13:10:13 -08003349
Evan Charltonc66da362014-05-16 14:06:40 -07003350 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003351 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3352 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3354 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003355 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003356
Malcolm Chend965c8b2018-02-28 15:00:40 -08003357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3360 && TextUtils.equals(ISDR_AID, data)) {
3361 // Only allows LPA to select ISD-R.
3362 ComponentInfo bestComponent =
3363 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3364 if (bestComponent == null
3365 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3366 loge("The calling package is not allowed to select ISD-R.");
3367 throw new SecurityException(
3368 "The calling package is not allowed to select ISD-R.");
3369 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003370 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003371
Malcolm Chend965c8b2018-02-28 15:00:40 -08003372 if (DBG) {
3373 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3374 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3375 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003376
Malcolm Chend965c8b2018-02-28 15:00:40 -08003377 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3378 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3379 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003380
Malcolm Chend965c8b2018-02-28 15:00:40 -08003381 // Append the returned status code to the end of the response payload.
3382 String s = Integer.toHexString(
3383 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3384 if (response.payload != null) {
3385 s = IccUtils.bytesToHexString(response.payload) + s;
3386 }
3387 return s;
3388 } finally {
3389 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003390 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003391 }
3392
3393 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003394 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003395 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3397 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003398
Malcolm Chend965c8b2018-02-28 15:00:40 -08003399 final long identity = Binder.clearCallingIdentity();
3400 try {
3401 if (DBG) {
3402 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3403 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3404 }
3405
3406 IccIoResult response =
3407 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3408 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3409 subId);
3410
3411 if (DBG) {
3412 log("Exchange SIM_IO [R]" + response);
3413 }
3414
3415 byte[] result = null;
3416 int length = 2;
3417 if (response.payload != null) {
3418 length = 2 + response.payload.length;
3419 result = new byte[length];
3420 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3421 } else {
3422 result = new byte[length];
3423 }
3424
3425 result[length - 1] = (byte) response.sw2;
3426 result[length - 2] = (byte) response.sw1;
3427 return result;
3428 } finally {
3429 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003430 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003431 }
3432
Nathan Haroldb3014052017-01-25 15:57:32 -08003433 /**
3434 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3435 * on a particular subscription
3436 */
sqianb6e41952018-03-12 14:54:01 -07003437 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3439 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3440 return null;
3441 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003442
3443 final long identity = Binder.clearCallingIdentity();
3444 try {
3445 if (appType != TelephonyManager.APPTYPE_USIM
3446 && appType != TelephonyManager.APPTYPE_SIM) {
3447 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3448 return null;
3449 }
3450 Object response = sendRequest(
3451 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3452 if (response instanceof String[]) {
3453 return (String[]) response;
3454 }
3455 // Response is an Exception of some kind,
3456 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003457 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003458 } finally {
3459 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003460 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003461 }
3462
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003463 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003464 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3466 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003467
Malcolm Chend965c8b2018-02-28 15:00:40 -08003468 final long identity = Binder.clearCallingIdentity();
3469 try {
3470 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3471 if (response.payload == null) {
3472 return "";
3473 }
Evan Charltonc66da362014-05-16 14:06:40 -07003474
Malcolm Chend965c8b2018-02-28 15:00:40 -08003475 // Append the returned status code to the end of the response payload.
3476 String s = Integer.toHexString(
3477 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3478 s = IccUtils.bytesToHexString(response.payload) + s;
3479 return s;
3480 } finally {
3481 Binder.restoreCallingIdentity(identity);
3482 }
Evan Charltonc66da362014-05-16 14:06:40 -07003483 }
3484
Jake Hambye994d462014-02-03 13:10:13 -08003485 /**
3486 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3487 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3488 *
3489 * @param itemID the ID of the item to read
3490 * @return the NV item as a String, or null on error.
3491 */
3492 @Override
3493 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003494 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3496 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003497
3498 final long identity = Binder.clearCallingIdentity();
3499 try {
3500 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003501 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003502 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3503 return value;
3504 } finally {
3505 Binder.restoreCallingIdentity(identity);
3506 }
Jake Hambye994d462014-02-03 13:10:13 -08003507 }
3508
3509 /**
3510 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3511 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3512 *
3513 * @param itemID the ID of the item to read
3514 * @param itemValue the value to write, as a String
3515 * @return true on success; false on any failure
3516 */
3517 @Override
3518 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003519 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3521 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003522
3523 final long identity = Binder.clearCallingIdentity();
3524 try {
3525 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3526 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003527 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003528 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3529 return success;
3530 } finally {
3531 Binder.restoreCallingIdentity(identity);
3532 }
Jake Hambye994d462014-02-03 13:10:13 -08003533 }
3534
3535 /**
3536 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3537 * Used for device configuration by some CDMA operators.
3538 *
3539 * @param preferredRoamingList byte array containing the new PRL
3540 * @return true on success; false on any failure
3541 */
3542 @Override
3543 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3545 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003546
3547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3550 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3551 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3552 return success;
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
Jake Hambye994d462014-02-03 13:10:13 -08003556 }
3557
3558 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003559 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003560 * Used for device configuration by some CDMA operators.
3561 *
chen xu1cc0abe2018-10-26 17:39:23 -07003562 * @param slotIndex - device slot.
3563 *
Jake Hambye994d462014-02-03 13:10:13 -08003564 * @return true on success; false on any failure
3565 */
3566 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003567 public boolean resetModemConfig(int slotIndex) {
3568 Phone phone = PhoneFactory.getPhone(slotIndex);
3569 if (phone != null) {
3570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3571 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003572
chen xu1cc0abe2018-10-26 17:39:23 -07003573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3576 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3577 return success;
3578 } finally {
3579 Binder.restoreCallingIdentity(identity);
3580 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003581 }
chen xu1cc0abe2018-10-26 17:39:23 -07003582 return false;
3583 }
3584
3585 /**
3586 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3587 *
3588 * @param slotIndex - device slot.
3589 *
3590 * @return true on success; false on any failure
3591 */
3592 @Override
3593 public boolean rebootModem(int slotIndex) {
3594 Phone phone = PhoneFactory.getPhone(slotIndex);
3595 if (phone != null) {
3596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3597 mApp, phone.getSubId(), "rebootModem");
3598
3599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3602 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3603 return success;
3604 } finally {
3605 Binder.restoreCallingIdentity(identity);
3606 }
3607 }
3608 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003609 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003610
Svet Ganovb320e182015-04-16 12:30:10 -07003611 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003612 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003613 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003614 return new String[0];
3615 }
3616
Malcolm Chend965c8b2018-02-28 15:00:40 -08003617 final long identity = Binder.clearCallingIdentity();
3618 try {
3619 return mPhone.getPcscfAddress(apnType);
3620 } finally {
3621 Binder.restoreCallingIdentity(identity);
3622 }
Wink Saville36469e72014-06-11 15:17:00 -07003623 }
3624
Brad Ebinger51f743a2017-01-23 13:50:20 -08003625 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003626 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3627 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003628 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003629 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003630 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003631
3632 final long identity = Binder.clearCallingIdentity();
3633 try {
3634 PhoneFactory.getImsResolver().enableIms(slotId);
3635 } finally {
3636 Binder.restoreCallingIdentity(identity);
3637 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003638 }
3639
3640 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003641 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3642 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003643 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003644 public void disableIms(int slotId) {
3645 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003646
3647 final long identity = Binder.clearCallingIdentity();
3648 try {
3649 PhoneFactory.getImsResolver().disableIms(slotId);
3650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003653 }
3654
3655 /**
3656 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3657 * feature or {@link null} if the service is not available. If the feature is available, the
3658 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3659 */
3660 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003661 IImsServiceFeatureCallback callback) {
3662 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003663
3664 final long identity = Binder.clearCallingIdentity();
3665 try {
3666 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3667 } finally {
3668 Binder.restoreCallingIdentity(identity);
3669 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003670 }
3671
3672 /**
3673 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3674 * feature during emergency calling or {@link null} if the service is not available. If the
3675 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3676 * listener for feature updates.
3677 */
3678 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3679 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003680
3681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3684 } finally {
3685 Binder.restoreCallingIdentity(identity);
3686 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003687 }
3688
Brad Ebinger5f64b052017-12-14 14:26:15 -08003689 /**
3690 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3691 * specified.
3692 */
3693 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3694 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003695
3696 final long identity = Binder.clearCallingIdentity();
3697 try {
3698 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3699 } finally {
3700 Binder.restoreCallingIdentity(identity);
3701 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003702 }
3703
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003704 /**
3705 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3706 * specified.
3707 */
3708 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3709 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003710
3711 final long identity = Binder.clearCallingIdentity();
3712 try {
3713 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3714 } finally {
3715 Binder.restoreCallingIdentity(identity);
3716 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003717 }
3718
Brad Ebinger884c07b2018-02-15 16:17:40 -08003719 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003720 * Sets the ImsService Package Name that Telephony will bind to.
3721 *
3722 * @param slotId the slot ID that the ImsService should bind for.
3723 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3724 * ImsService is the device default ImsService.
3725 * @param packageName The package name of the application that contains the ImsService to bind
3726 * to.
3727 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3728 * @hide
3729 */
3730 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003731 int[] subIds = SubscriptionManager.getSubId(slotId);
3732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3733 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3734 "setImsService");
3735
Malcolm Chend965c8b2018-02-28 15:00:40 -08003736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3739 isCarrierImsService, packageName);
3740 } finally {
3741 Binder.restoreCallingIdentity(identity);
3742 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003743 }
3744
3745 /**
3746 * Return the ImsService configuration.
3747 *
3748 * @param slotId The slot that the ImsService is associated with.
3749 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3750 * the device default.
3751 * @return the package name of the ImsService configuration.
3752 */
3753 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003754 int[] subIds = SubscriptionManager.getSubId(slotId);
3755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3756 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3757 "getImsService");
3758
Malcolm Chend965c8b2018-02-28 15:00:40 -08003759 final long identity = Binder.clearCallingIdentity();
3760 try {
3761 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3762 isCarrierImsService);
3763 } finally {
3764 Binder.restoreCallingIdentity(identity);
3765 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003766 }
3767
Wink Saville36469e72014-06-11 15:17:00 -07003768 public void setImsRegistrationState(boolean registered) {
3769 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003770
3771 final long identity = Binder.clearCallingIdentity();
3772 try {
3773 mPhone.setImsRegistrationState(registered);
3774 } finally {
3775 Binder.restoreCallingIdentity(identity);
3776 }
Wink Saville36469e72014-06-11 15:17:00 -07003777 }
3778
3779 /**
Stuart Scott54788802015-03-30 13:18:01 -07003780 * Set the network selection mode to automatic.
3781 *
3782 */
3783 @Override
3784 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3786 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003787
Pengquan Meng466e2482018-09-21 15:54:48 -07003788 if (!isActiveSubscription(subId)) {
3789 return;
3790 }
3791
Malcolm Chend965c8b2018-02-28 15:00:40 -08003792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3795 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3796 } finally {
3797 Binder.restoreCallingIdentity(identity);
3798 }
Stuart Scott54788802015-03-30 13:18:01 -07003799 }
3800
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003801 /**
3802 * Ask the radio to connect to the input network and change selection mode to manual.
3803 *
3804 * @param subId the id of the subscription.
3805 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3806 * the operator to attach to.
3807 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3808 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3809 * normal network selection next time.
3810 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003811 */
3812 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003813 public boolean setNetworkSelectionModeManual(
3814 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3816 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003817
3818 if (!isActiveSubscription(subId)) {
3819 return false;
3820 }
3821
Malcolm Chend965c8b2018-02-28 15:00:40 -08003822 final long identity = Binder.clearCallingIdentity();
3823 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003824 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003825 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003826 if (DBG) {
3827 log("setNetworkSelectionModeManual: subId: " + subId
3828 + " operator: " + operatorInfo);
3829 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003830 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
3833 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003834 }
3835
3836 /**
3837 * Scans for available networks.
3838 */
3839 @Override
3840 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3842 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003843
Pengquan Meng0c05b502018-09-06 09:59:22 -07003844 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003845 try {
3846 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003847 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003848 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003849 } finally {
3850 Binder.restoreCallingIdentity(identity);
3851 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003852 }
3853
3854 /**
yinxub1bed742017-04-17 11:45:04 -07003855 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003856 *
yinxub1bed742017-04-17 11:45:04 -07003857 * @param subId id of the subscription
3858 * @param request contains the radio access networks with bands/channels to scan
3859 * @param messenger callback messenger for scan results or errors
3860 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003861 * @return the id of the requested scan which can be used to stop the scan.
3862 */
3863 @Override
3864 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3865 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3867 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003868
3869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 return mNetworkScanRequestTracker.startNetworkScan(
3872 request, messenger, binder, getPhone(subId));
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
3875 }
yinxu504e1392017-04-12 16:03:22 -07003876 }
3877
3878 /**
3879 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003880 *
3881 * @param subId id of the subscription
3882 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003883 */
3884 @Override
3885 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3887 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003888
3889 final long identity = Binder.clearCallingIdentity();
3890 try {
3891 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3892 } finally {
3893 Binder.restoreCallingIdentity(identity);
3894 }
yinxu504e1392017-04-12 16:03:22 -07003895 }
3896
3897 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003898 * Get the calculated preferred network type.
3899 * Used for debugging incorrect network type.
3900 *
3901 * @return the preferred network type, defined in RILConstants.java.
3902 */
3903 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003904 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003906 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003907 return RILConstants.PREFERRED_NETWORK_MODE;
3908 }
3909
Malcolm Chend965c8b2018-02-28 15:00:40 -08003910 final long identity = Binder.clearCallingIdentity();
3911 try {
3912 // FIXME: need to get SubId from somewhere.
3913 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3914 } finally {
3915 Binder.restoreCallingIdentity(identity);
3916 }
Junda Liu84d15a22014-07-02 11:21:04 -07003917 }
3918
3919 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003920 * Get the preferred network type.
3921 * Used for device configuration by some CDMA operators.
3922 *
3923 * @return the preferred network type, defined in RILConstants.java.
3924 */
3925 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003926 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3928 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003929
3930 final long identity = Binder.clearCallingIdentity();
3931 try {
3932 if (DBG) log("getPreferredNetworkType");
3933 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3934 int networkType = (result != null ? result[0] : -1);
3935 if (DBG) log("getPreferredNetworkType: " + networkType);
3936 return networkType;
3937 } finally {
3938 Binder.restoreCallingIdentity(identity);
3939 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003940 }
3941
3942 /**
3943 * Set the preferred network type.
3944 * Used for device configuration by some CDMA operators.
3945 *
3946 * @param networkType the preferred network type, defined in RILConstants.java.
3947 * @return true on success; false on any failure.
3948 */
3949 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003950 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3952 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003953
3954 final long identity = Binder.clearCallingIdentity();
3955 try {
3956 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3957 Boolean success = (Boolean) sendRequest(
3958 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3959 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3960 if (success) {
3961 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3962 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3963 }
3964 return success;
3965 } finally {
3966 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003967 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003968 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003969
3970 /**
Junda Liu475951f2014-11-07 16:45:03 -08003971 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07003972 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003973 * tethering.
3974 *
3975 * @return 0: Not required. 1: required. 2: Not set.
3976 * @hide
3977 */
3978 @Override
3979 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003980 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003981
3982 final long identity = Binder.clearCallingIdentity();
3983 try {
3984 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3985 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07003986 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Malcolm Chend965c8b2018-02-28 15:00:40 -08003987 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3988 dunRequired = 1;
3989 }
3990 return dunRequired;
3991 } finally {
3992 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003993 }
Junda Liu475951f2014-11-07 16:45:03 -08003994 }
3995
3996 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003997 * Set mobile data enabled
3998 * Used by the user through settings etc to turn on/off mobile data
3999 *
4000 * @param enable {@code true} turn turn data on, else {@code false}
4001 */
4002 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004003 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4005 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004006
4007 final long identity = Binder.clearCallingIdentity();
4008 try {
4009 int phoneId = mSubscriptionController.getPhoneId(subId);
4010 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4011 Phone phone = PhoneFactory.getPhone(phoneId);
4012 if (phone != null) {
4013 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
4014 phone.setUserDataEnabled(enable);
4015 } else {
4016 loge("setUserDataEnabled: no phone for subId=" + subId);
4017 }
4018 } finally {
4019 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004020 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004021 }
4022
4023 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004024 * Get the user enabled state of Mobile Data.
4025 *
4026 * TODO: remove and use isUserDataEnabled.
4027 * This can't be removed now because some vendor codes
4028 * calls through ITelephony directly while they should
4029 * use TelephonyManager.
4030 *
4031 * @return true on enabled
4032 */
4033 @Override
4034 public boolean getDataEnabled(int subId) {
4035 return isUserDataEnabled(subId);
4036 }
4037
4038 /**
4039 * Get whether mobile data is enabled per user setting.
4040 *
4041 * There are other factors deciding whether mobile data is actually enabled, but they are
4042 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004043 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004044 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004045 *
4046 * @return {@code true} if data is enabled else {@code false}
4047 */
4048 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004049 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004050 try {
4051 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4052 null);
4053 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4055 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004056 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004057
4058 final long identity = Binder.clearCallingIdentity();
4059 try {
4060 int phoneId = mSubscriptionController.getPhoneId(subId);
4061 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4062 Phone phone = PhoneFactory.getPhone(phoneId);
4063 if (phone != null) {
4064 boolean retVal = phone.isUserDataEnabled();
4065 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4066 return retVal;
4067 } else {
4068 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4069 return false;
4070 }
4071 } finally {
4072 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004073 }
4074 }
4075
4076 /**
4077 * Get whether mobile data is enabled.
4078 *
4079 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4080 * whether mobile data is actually enabled.
4081 *
4082 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4083 *
4084 * @return {@code true} if data is enabled else {@code false}
4085 */
4086 @Override
4087 public boolean isDataEnabled(int subId) {
4088 try {
4089 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4090 null);
4091 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4093 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004094 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004095
4096 final long identity = Binder.clearCallingIdentity();
4097 try {
4098 int phoneId = mSubscriptionController.getPhoneId(subId);
4099 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4100 Phone phone = PhoneFactory.getPhone(phoneId);
4101 if (phone != null) {
4102 boolean retVal = phone.isDataEnabled();
4103 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4104 return retVal;
4105 } else {
4106 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4107 return false;
4108 }
4109 } finally {
4110 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004111 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004112 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004113
4114 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004115 public int getCarrierPrivilegeStatus(int subId) {
4116 final Phone phone = getPhone(subId);
4117 if (phone == null) {
4118 loge("getCarrierPrivilegeStatus: Invalid subId");
4119 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4120 }
4121 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004122 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004123 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004124 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4125 }
4126 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004127 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004128 }
Junda Liu29340342014-07-10 15:23:27 -07004129
4130 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004131 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4132 final Phone phone = getPhone(subId);
4133 if (phone == null) {
4134 loge("getCarrierPrivilegeStatus: Invalid subId");
4135 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4136 }
4137 UiccProfile profile =
4138 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4139 if (profile == null) {
4140 loge("getCarrierPrivilegeStatus: No UICC");
4141 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4142 }
4143 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4144 }
4145
4146 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004147 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004148 if (TextUtils.isEmpty(pkgName))
4149 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08004150 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004151 if (card == null) {
4152 loge("checkCarrierPrivilegesForPackage: No UICC");
4153 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4154 }
Zach Johnson50ecba32015-05-19 00:24:21 -07004155 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
4156 }
4157
4158 @Override
4159 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004160 if (TextUtils.isEmpty(pkgName))
4161 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004162 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4163 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4164 UiccCard card = UiccController.getInstance().getUiccCard(i);
4165 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004166 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004167 continue;
4168 }
4169
4170 result = card.getCarrierPrivilegeStatus(
4171 mPhone.getContext().getPackageManager(), pkgName);
4172 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4173 break;
4174 }
4175 }
4176
4177 return result;
Junda Liu29340342014-07-10 15:23:27 -07004178 }
Derek Tan89e89d42014-07-08 17:00:10 -07004179
4180 @Override
Junda Liue64de782015-04-16 17:19:16 -07004181 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4182 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4183 loge("phoneId " + phoneId + " is not valid.");
4184 return null;
4185 }
4186 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004187 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004188 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004189 return null ;
4190 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004191 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004192 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004193 }
4194
Amith Yamasani6e118872016-02-19 12:53:51 -08004195 @Override
4196 public List<String> getPackagesWithCarrierPrivileges() {
4197 PackageManager pm = mPhone.getContext().getPackageManager();
4198 List<String> privilegedPackages = new ArrayList<>();
4199 List<PackageInfo> packages = null;
4200 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4201 UiccCard card = UiccController.getInstance().getUiccCard(i);
4202 if (card == null) {
4203 // No UICC in that slot.
4204 continue;
4205 }
4206 if (card.hasCarrierPrivilegeRules()) {
4207 if (packages == null) {
4208 // Only check packages in user 0 for now
4209 packages = pm.getInstalledPackagesAsUser(
4210 PackageManager.MATCH_DISABLED_COMPONENTS
4211 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4212 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4213 }
4214 for (int p = packages.size() - 1; p >= 0; p--) {
4215 PackageInfo pkgInfo = packages.get(p);
4216 if (pkgInfo != null && pkgInfo.packageName != null
4217 && card.getCarrierPrivilegeStatus(pkgInfo)
4218 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4219 privilegedPackages.add(pkgInfo.packageName);
4220 }
4221 }
4222 }
4223 }
4224 return privilegedPackages;
4225 }
4226
Wink Savilleb564aae2014-10-23 10:18:09 -07004227 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004228 final Phone phone = getPhone(subId);
4229 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004230 if (card == null) {
4231 loge("getIccId: No UICC");
4232 return null;
4233 }
4234 String iccId = card.getIccId();
4235 if (TextUtils.isEmpty(iccId)) {
4236 loge("getIccId: ICC ID is null or empty.");
4237 return null;
4238 }
4239 return iccId;
4240 }
4241
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004242 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004243 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4244 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004245 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4246 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004247
Malcolm Chend965c8b2018-02-28 15:00:40 -08004248 final long identity = Binder.clearCallingIdentity();
4249 try {
4250 final String iccId = getIccId(subId);
4251 final Phone phone = getPhone(subId);
4252 if (phone == null) {
4253 return false;
4254 }
4255 final String subscriberId = phone.getSubscriberId();
4256
4257 if (DBG_MERGE) {
4258 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4259 + subscriberId + " to " + number);
4260 }
4261
4262 if (TextUtils.isEmpty(iccId)) {
4263 return false;
4264 }
4265
4266 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4267
4268 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4269 if (alphaTag == null) {
4270 editor.remove(alphaTagPrefKey);
4271 } else {
4272 editor.putString(alphaTagPrefKey, alphaTag);
4273 }
4274
4275 // Record both the line number and IMSI for this ICCID, since we need to
4276 // track all merged IMSIs based on line number
4277 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4278 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4279 if (number == null) {
4280 editor.remove(numberPrefKey);
4281 editor.remove(subscriberPrefKey);
4282 } else {
4283 editor.putString(numberPrefKey, number);
4284 editor.putString(subscriberPrefKey, subscriberId);
4285 }
4286
4287 editor.commit();
4288 return true;
4289 } finally {
4290 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004291 }
Derek Tan7226c842014-07-02 17:42:23 -07004292 }
4293
4294 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004295 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004296 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004297 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004298 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004299 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004300 return null;
4301 }
Derek Tan97ebb422014-09-05 16:55:38 -07004302
Malcolm Chend965c8b2018-02-28 15:00:40 -08004303 final long identity = Binder.clearCallingIdentity();
4304 try {
4305 String iccId = getIccId(subId);
4306 if (iccId != null) {
4307 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4308 if (DBG_MERGE) {
4309 log("getLine1NumberForDisplay returning "
4310 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4311 }
4312 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004313 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004314 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4315 return null;
4316 } finally {
4317 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004318 }
Derek Tan7226c842014-07-02 17:42:23 -07004319 }
4320
4321 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004322 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004324 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004325 return null;
4326 }
Derek Tan97ebb422014-09-05 16:55:38 -07004327
Malcolm Chend965c8b2018-02-28 15:00:40 -08004328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 String iccId = getIccId(subId);
4331 if (iccId != null) {
4332 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4333 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4334 }
4335 return null;
4336 } finally {
4337 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004338 }
Derek Tan7226c842014-07-02 17:42:23 -07004339 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004340
4341 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004342 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004343 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4344 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004346 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4347 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004348 return null;
4349 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004350
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004351 final long identity = Binder.clearCallingIdentity();
4352 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004353 final Context context = mPhone.getContext();
4354 final TelephonyManager tele = TelephonyManager.from(context);
4355 final SubscriptionManager sub = SubscriptionManager.from(context);
4356
4357 // Figure out what subscribers are currently active
4358 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4359 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4360 // the process, where TelephonyManager was instantiated.
4361 // Otherwise AppOps check will fail.
4362
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004363 final int[] subIds = sub.getActiveSubscriptionIdList();
4364 for (int subId : subIds) {
4365 activeSubscriberIds.add(tele.getSubscriberId(subId));
4366 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004367
4368 // First pass, find a number override for an active subscriber
4369 String mergeNumber = null;
4370 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4371 for (String key : prefs.keySet()) {
4372 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4373 final String subscriberId = (String) prefs.get(key);
4374 if (activeSubscriberIds.contains(subscriberId)) {
4375 final String iccId = key.substring(
4376 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4377 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4378 mergeNumber = (String) prefs.get(numberKey);
4379 if (DBG_MERGE) {
4380 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4381 + " for active subscriber " + subscriberId);
4382 }
4383 if (!TextUtils.isEmpty(mergeNumber)) {
4384 break;
4385 }
4386 }
4387 }
4388 }
4389
4390 // Shortcut when no active merged subscribers
4391 if (TextUtils.isEmpty(mergeNumber)) {
4392 return null;
4393 }
4394
4395 // Second pass, find all subscribers under that line override
4396 final ArraySet<String> result = new ArraySet<>();
4397 for (String key : prefs.keySet()) {
4398 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4399 final String number = (String) prefs.get(key);
4400 if (mergeNumber.equals(number)) {
4401 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4402 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4403 final String subscriberId = (String) prefs.get(subscriberKey);
4404 if (!TextUtils.isEmpty(subscriberId)) {
4405 result.add(subscriberId);
4406 }
4407 }
4408 }
4409 }
4410
4411 final String[] resultArray = result.toArray(new String[result.size()]);
4412 Arrays.sort(resultArray);
4413 if (DBG_MERGE) {
4414 Slog.d(LOG_TAG,
4415 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4416 }
4417 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004418 } finally {
4419 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004420 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004421 }
4422
4423 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004424 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004425 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4426 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004427
4428 final long identity = Binder.clearCallingIdentity();
4429 try {
4430 final Phone phone = getPhone(subId);
4431 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4432 } finally {
4433 Binder.restoreCallingIdentity(identity);
4434 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004435 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004436
4437 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004438 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004439 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4440 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004441 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004442
4443 final long identity = Binder.clearCallingIdentity();
4444 try {
4445 final Phone phone = getPhone(subId);
4446 if (phone == null) {
4447 return false;
4448 }
4449 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4450 cdmaNonRoamingList);
4451 } finally {
4452 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004453 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004454 }
4455
4456 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004457 @Deprecated
4458 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4459 enforceModifyPermission();
4460
4461 int returnValue = 0;
4462 try {
vagdevie435a3e2018-08-15 16:01:53 -07004463 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004464 if(result.exception == null) {
4465 if (result.result != null) {
4466 byte[] responseData = (byte[])(result.result);
4467 if(responseData.length > oemResp.length) {
4468 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4469 responseData.length + "bytes. Buffer Size is " +
4470 oemResp.length + "bytes.");
4471 }
4472 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4473 returnValue = responseData.length;
4474 }
4475 } else {
4476 CommandException ex = (CommandException) result.exception;
4477 returnValue = ex.getCommandError().ordinal();
4478 if(returnValue > 0) returnValue *= -1;
4479 }
4480 } catch (RuntimeException e) {
4481 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4482 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4483 if(returnValue > 0) returnValue *= -1;
4484 }
4485
4486 return returnValue;
4487 }
4488
4489 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004490 public void setRadioCapability(RadioAccessFamily[] rafs) {
4491 try {
4492 ProxyController.getInstance().setRadioCapability(rafs);
4493 } catch (RuntimeException e) {
4494 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4495 }
4496 }
4497
4498 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004499 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004500 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004501 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004502 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004503 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004504 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004505 final long identity = Binder.clearCallingIdentity();
4506 try {
chen xufeeed752018-10-26 14:17:57 -07004507 TelephonyPermissions
4508 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4509 mApp, phone.getSubId(), "getRadioAccessFamily");
4510 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
chen xufeeed752018-10-26 14:17:57 -07004514 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004515 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004516
4517 @Override
4518 public void enableVideoCalling(boolean enable) {
4519 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004520
4521 final long identity = Binder.clearCallingIdentity();
4522 try {
4523 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4524 } finally {
4525 Binder.restoreCallingIdentity(identity);
4526 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004527 }
4528
4529 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004530 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4532 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4533 return false;
4534 }
Svet Ganovb320e182015-04-16 12:30:10 -07004535
Malcolm Chend965c8b2018-02-28 15:00:40 -08004536 final long identity = Binder.clearCallingIdentity();
4537 try {
4538 // Check the user preference and the system-level IMS setting. Even if the user has
4539 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4540 // In the long run, we may instead need to check if there exists a connection service
4541 // which can support video calling.
4542 ImsManager imsManager =
4543 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4544 return imsManager.isVtEnabledByPlatform()
4545 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4546 && imsManager.isVtEnabledByUser();
4547 } finally {
4548 Binder.restoreCallingIdentity(identity);
4549 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004550 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004551
Andrew Leea1239f22015-03-02 17:44:07 -08004552 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004553 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4554 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4555 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4556 return false;
4557 }
4558
4559 final long identity = Binder.clearCallingIdentity();
4560 try {
4561 CarrierConfigManager configManager =
4562 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4563 return configManager.getConfigForSubId(mPhone.getSubId())
4564 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4565 } finally {
4566 Binder.restoreCallingIdentity(identity);
4567 }
Andrew Leea1239f22015-03-02 17:44:07 -08004568 }
4569
4570 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004571 public boolean isWorldPhone(int subId, String callingPackage) {
4572 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4573 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4574 return false;
4575 }
4576
4577 final long identity = Binder.clearCallingIdentity();
4578 try {
4579 CarrierConfigManager configManager =
4580 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4581 return configManager.getConfigForSubId(mPhone.getSubId())
4582 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4583 } finally {
4584 Binder.restoreCallingIdentity(identity);
4585 }
Andrew Leea1239f22015-03-02 17:44:07 -08004586 }
4587
Andrew Lee9431b832015-03-09 18:46:45 -07004588 @Override
4589 public boolean isTtyModeSupported() {
4590 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004591 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004592 }
4593
4594 @Override
4595 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004596 final long identity = Binder.clearCallingIdentity();
4597 try {
4598 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4599 } finally {
4600 Binder.restoreCallingIdentity(identity);
4601 }
Andrew Lee9431b832015-03-09 18:46:45 -07004602 }
4603
Hall Liuf6668912018-10-31 17:05:23 -07004604 /**
4605 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4606 * support for the feature and device firmware support.
4607 *
4608 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4609 */
4610 @Override
4611 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004612 final long identity = Binder.clearCallingIdentity();
4613 try {
4614 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4615 mPhone.getSubId()).getBoolean(
4616 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4617 boolean isDeviceSupported =
4618 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4619 return isCarrierSupported && isDeviceSupported;
4620 } finally {
4621 Binder.restoreCallingIdentity(identity);
4622 }
Hall Liu98187582018-01-22 19:15:32 -08004623 }
4624
Hall Liuf6668912018-10-31 17:05:23 -07004625 /**
4626 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4627 * both also support RTT.
4628 */
4629 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004630 final long identity = Binder.clearCallingIdentity();
4631 try {
Hall Liuf6668912018-10-31 17:05:23 -07004632 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004633 mPhone.getContext().getContentResolver(),
4634 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004638 }
4639
Sanket Padawe7310cc72015-01-14 09:53:20 -08004640 /**
4641 * Returns the unique device ID of phone, for example, the IMEI for
4642 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4643 *
4644 * <p>Requires Permission:
4645 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4646 */
4647 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004648 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004649 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004650 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004651 return null;
4652 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004653 int subId = phone.getSubId();
4654 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4655 mApp, subId, callingPackage, "getDeviceId")) {
4656 return null;
4657 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004658
4659 final long identity = Binder.clearCallingIdentity();
4660 try {
4661 return phone.getDeviceId();
4662 } finally {
4663 Binder.restoreCallingIdentity(identity);
4664 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004665 }
4666
Ping Sunc67b7c22016-03-02 19:16:45 +08004667 /**
4668 * {@hide}
4669 * Returns the IMS Registration Status on a particular subid
4670 *
4671 * @param subId
4672 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004673 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004674 Phone phone = getPhone(subId);
4675 if (phone != null) {
4676 return phone.isImsRegistered();
4677 } else {
4678 return false;
4679 }
4680 }
4681
Santos Cordon7a1885b2015-02-03 11:15:19 -08004682 @Override
4683 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004684 final long identity = Binder.clearCallingIdentity();
4685 try {
4686 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4687 } finally {
4688 Binder.restoreCallingIdentity(identity);
4689 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004690 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004691
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004692 /**
4693 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004694 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004695 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004696 final long identity = Binder.clearCallingIdentity();
4697 try {
4698 Phone phone = getPhone(subId);
4699 if (phone != null) {
4700 return phone.isWifiCallingEnabled();
4701 } else {
4702 return false;
4703 }
4704 } finally {
4705 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004706 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004707 }
4708
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004709 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004710 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004711 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004712 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004713 final long identity = Binder.clearCallingIdentity();
4714 try {
4715 Phone phone = getPhone(subId);
4716 if (phone != null) {
4717 return phone.isVideoEnabled();
4718 } else {
4719 return false;
4720 }
4721 } finally {
4722 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004723 }
4724 }
4725
4726 /**
4727 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4728 * defined in {@link ImsRegistrationImplBase}.
4729 */
4730 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004731 final long identity = Binder.clearCallingIdentity();
4732 try {
4733 Phone phone = getPhone(subId);
4734 if (phone != null) {
4735 return phone.getImsRegistrationTech();
4736 } else {
4737 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4738 }
4739 } finally {
4740 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004741 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004742 }
4743
Stuart Scott8eef64f2015-04-08 15:13:54 -07004744 @Override
4745 public void factoryReset(int subId) {
4746 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004747 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4748 return;
4749 }
4750
Svet Ganovcc087f82015-05-12 20:35:54 -07004751 final long identity = Binder.clearCallingIdentity();
4752 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004753 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4754 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004755 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004756 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004757 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4758 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004759 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004760 }
4761 } finally {
4762 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004763 }
4764 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004765
4766 @Override
4767 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004768 final long identity = Binder.clearCallingIdentity();
4769 try {
4770 // We query all subscriptions instead of just the active ones, because
4771 // this might be called early on in the provisioning flow when the
4772 // subscriptions potentially aren't active yet.
4773 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4774 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004775 return null;
4776 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004777
Malcolm Chend965c8b2018-02-28 15:00:40 -08004778 // This function may be called very early, say, from the setup wizard, at
4779 // which point we won't have a default subscription set. If that's the case
4780 // we just choose the first, which will be valid in "most cases".
4781 final int defaultSubId = getDefaultSubscription();
4782 SubscriptionInfo info = null;
4783 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4784 info = slist.get(0);
4785 } else {
4786 for (SubscriptionInfo item : slist) {
4787 if (item.getSubscriptionId() == defaultSubId) {
4788 info = item;
4789 break;
4790 }
4791 }
4792
4793 if (info == null) {
4794 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004795 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004796 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004797
Malcolm Chend965c8b2018-02-28 15:00:40 -08004798 // Try and fetch the locale from the carrier properties or from the SIM language
4799 // preferences (EF-PL and EF-LI)...
4800 final int mcc = info.getMcc();
4801 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4802 String simLanguage = null;
4803 if (defaultPhone != null) {
4804 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4805 if (localeFromDefaultSim != null) {
4806 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4807 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4808 return localeFromDefaultSim.toLanguageTag();
4809 } else {
4810 simLanguage = localeFromDefaultSim.getLanguage();
4811 }
4812 }
4813 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004814
Malcolm Chend965c8b2018-02-28 15:00:40 -08004815 // The SIM language preferences only store a language (e.g. fr = French), not an
4816 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4817 // the SIM and carrier preferences does not include a country we add the country
4818 // determined from the SIM MCC to provide an exact locale.
4819 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4820 simLanguage);
4821 if (mccLocale != null) {
4822 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4823 return mccLocale.toLanguageTag();
4824 }
4825
4826 if (DBG) log("No locale found - returning null");
4827 return null;
4828 } finally {
4829 Binder.restoreCallingIdentity(identity);
4830 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004831 }
4832
4833 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004834 return mSubscriptionController.getAllSubInfoList(
4835 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004836 }
4837
Malcolm Chend965c8b2018-02-28 15:00:40 -08004838 /**
4839 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4840 */
4841 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4842 return mSubscriptionController.getActiveSubscriptionInfoList(
4843 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004844 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004845
Chenjie Yu1ba97252018-01-11 18:16:20 -08004846 private final ModemActivityInfo mLastModemActivityInfo =
4847 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4848
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004849 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004850 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4851 * representing the state of the modem.
4852 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004853 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4854 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004855 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004856 */
4857 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004858 public void requestModemActivityInfo(ResultReceiver result) {
4859 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004860 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004861
4862 final long identity = Binder.clearCallingIdentity();
4863 try {
4864 ModemActivityInfo ret = null;
4865 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004866 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4867 CMD_GET_MODEM_ACTIVITY_INFO,
4868 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004869 if (isModemActivityInfoValid(info)) {
4870 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4871 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4872 mergedTxTimeMs[i] =
4873 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4874 }
4875 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4876 mLastModemActivityInfo.setSleepTimeMillis(
4877 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4878 mLastModemActivityInfo.setIdleTimeMillis(
4879 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4880 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4881 mLastModemActivityInfo.setRxTimeMillis(
4882 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4883 mLastModemActivityInfo.setEnergyUsed(
4884 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004885 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004886 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4887 mLastModemActivityInfo.getSleepTimeMillis(),
4888 mLastModemActivityInfo.getIdleTimeMillis(),
4889 mLastModemActivityInfo.getTxTimeMillis(),
4890 mLastModemActivityInfo.getRxTimeMillis(),
4891 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004892 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004893 Bundle bundle = new Bundle();
4894 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4895 result.send(0, bundle);
4896 } finally {
4897 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004898 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004899 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004900
Siddharth Rayf5d29552018-06-17 15:02:38 -07004901 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4902 // less than total activity duration.
4903 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4904 if (info == null) {
4905 return false;
4906 }
4907 int activityDurationMs =
4908 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4909 int totalTxTimeMs = 0;
4910 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4911 totalTxTimeMs += info.getTxTimeMillis()[i];
4912 }
4913 return (info.isValid()
4914 && (info.getSleepTimeMillis() <= activityDurationMs)
4915 && (info.getIdleTimeMillis() <= activityDurationMs)
4916 && (info.getRxTimeMillis() <= activityDurationMs)
4917 && (totalTxTimeMs <= activityDurationMs));
4918 }
4919
Jack Yu85bd38a2015-11-09 11:34:32 -08004920 /**
4921 * {@hide}
4922 * Returns the service state information on specified subscription.
4923 */
4924 @Override
4925 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004927 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004928 return null;
4929 }
4930
Malcolm Chend965c8b2018-02-28 15:00:40 -08004931 final long identity = Binder.clearCallingIdentity();
4932 try {
4933 final Phone phone = getPhone(subId);
4934 if (phone == null) {
4935 return null;
4936 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004937
Malcolm Chend965c8b2018-02-28 15:00:40 -08004938 return phone.getServiceState();
4939 } finally {
4940 Binder.restoreCallingIdentity(identity);
4941 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004942 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004943
4944 /**
4945 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4946 *
4947 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4948 * voicemail ringtone.
4949 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4950 * PhoneAccount.
4951 */
4952 @Override
4953 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004954 final long identity = Binder.clearCallingIdentity();
4955 try {
4956 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4957 if (phone == null) {
4958 phone = mPhone;
4959 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004960
Malcolm Chend965c8b2018-02-28 15:00:40 -08004961 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4962 } finally {
4963 Binder.restoreCallingIdentity(identity);
4964 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004965 }
4966
4967 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004968 * Sets the per-account voicemail ringtone.
4969 *
4970 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4971 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4972 *
4973 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4974 * voicemail ringtone.
4975 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4976 * PhoneAccount.
4977 */
4978 @Override
4979 public void setVoicemailRingtoneUri(String callingPackage,
4980 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4981 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4982 if (!TextUtils.equals(callingPackage,
4983 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004984 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4985 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4986 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004987 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004988
4989 final long identity = Binder.clearCallingIdentity();
4990 try {
4991 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4992 if (phone == null) {
4993 phone = mPhone;
4994 }
4995 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4996 } finally {
4997 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004998 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004999 }
5000
5001 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005002 * Returns whether vibration is set for voicemail notification in Phone settings.
5003 *
5004 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5005 * voicemail vibration setting.
5006 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5007 */
5008 @Override
5009 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005010 final long identity = Binder.clearCallingIdentity();
5011 try {
5012 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5013 if (phone == null) {
5014 phone = mPhone;
5015 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005016
Malcolm Chend965c8b2018-02-28 15:00:40 -08005017 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5018 } finally {
5019 Binder.restoreCallingIdentity(identity);
5020 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005021 }
5022
Youhan Wange64578a2016-05-02 15:32:42 -07005023 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005024 * Sets the per-account voicemail vibration.
5025 *
5026 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5027 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5028 *
5029 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5030 * voicemail vibration setting.
5031 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5032 * specific PhoneAccount.
5033 */
5034 @Override
5035 public void setVoicemailVibrationEnabled(String callingPackage,
5036 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
5037 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5038 if (!TextUtils.equals(callingPackage,
5039 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5041 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5042 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005043 }
5044
Malcolm Chend965c8b2018-02-28 15:00:40 -08005045 final long identity = Binder.clearCallingIdentity();
5046 try {
5047 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5048 if (phone == null) {
5049 phone = mPhone;
5050 }
5051 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5052 } finally {
5053 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005054 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005055 }
5056
5057 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005058 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5059 *
5060 * @throws SecurityException if the caller does not have the required permission
5061 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005062 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005063 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005064 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005065 }
5066
5067 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005068 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5069 * permission.
5070 *
5071 * @throws SecurityException if the caller does not have the required permission
5072 */
5073 private void enforceSendSmsPermission() {
5074 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5075 }
5076
5077 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005078 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005079 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005080 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005081 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005082 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005083 final long identity = Binder.clearCallingIdentity();
5084 try {
5085 ComponentName componentName =
5086 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
5087 if (componentName == null) {
5088 throw new SecurityException(
5089 "Caller not current active visual voicemail package[null]");
5090 }
5091 String vvmPackage = componentName.getPackageName();
5092 if (!callingPackage.equals(vvmPackage)) {
5093 throw new SecurityException("Caller not current active visual voicemail package["
5094 + vvmPackage + "]");
5095 }
5096 } finally {
5097 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005098 }
5099 }
5100
5101 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005102 * Return the application ID for the app type.
5103 *
5104 * @param subId the subscription ID that this request applies to.
5105 * @param appType the uicc app type.
5106 * @return Application ID for specificied app type, or null if no uicc.
5107 */
5108 @Override
5109 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005110 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005111 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005112
5113 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005114 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005115 if (phone == null) {
5116 return null;
5117 }
5118 String aid = null;
5119 try {
5120 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5121 .getApplicationByType(appType).getAid();
5122 } catch (Exception e) {
5123 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5124 }
5125 return aid;
5126 } finally {
5127 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005128 }
Youhan Wange64578a2016-05-02 15:32:42 -07005129 }
5130
Youhan Wang4001d252016-05-11 10:29:41 -07005131 /**
5132 * Return the Electronic Serial Number.
5133 *
5134 * @param subId the subscription ID that this request applies to.
5135 * @return ESN or null if error.
5136 */
5137 @Override
5138 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005139 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005140 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005141
5142 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005143 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005144 if (phone == null) {
5145 return null;
5146 }
5147 String esn = null;
5148 try {
5149 esn = phone.getEsn();
5150 } catch (Exception e) {
5151 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5152 }
5153 return esn;
5154 } finally {
5155 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005156 }
Youhan Wang4001d252016-05-11 10:29:41 -07005157 }
5158
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005159 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005160 * Return the Preferred Roaming List Version.
5161 *
5162 * @param subId the subscription ID that this request applies to.
5163 * @return PRLVersion or null if error.
5164 */
5165 @Override
5166 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005167 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005168 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005169
5170 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005171 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005172 if (phone == null) {
5173 return null;
5174 }
5175 String cdmaPrlVersion = null;
5176 try {
5177 cdmaPrlVersion = phone.getCdmaPrlVersion();
5178 } catch (Exception e) {
5179 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5180 }
5181 return cdmaPrlVersion;
5182 } finally {
5183 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005184 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005185 }
5186
5187 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005188 * Get snapshot of Telephony histograms
5189 * @return List of Telephony histograms
5190 * @hide
5191 */
5192 @Override
5193 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005194 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5195 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005196
5197 final long identity = Binder.clearCallingIdentity();
5198 try {
5199 return RIL.getTelephonyRILTimingHistograms();
5200 } finally {
5201 Binder.restoreCallingIdentity(identity);
5202 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005203 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005204
5205 /**
5206 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005207 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005208 * Require system privileges. In the future we may add this to carrier APIs.
5209 *
5210 * @return The number of carriers set successfully, should match length of carriers
5211 */
5212 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005213 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005214 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005215 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005216
Meng Wang9b7c4e92017-02-17 11:41:27 -08005217 if (carriers == null) {
5218 throw new NullPointerException("carriers cannot be null");
5219 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005220
Malcolm Chend965c8b2018-02-28 15:00:40 -08005221 final long identity = Binder.clearCallingIdentity();
5222 try {
5223 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005224 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5225 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005226 return retVal[0];
5227 } finally {
5228 Binder.restoreCallingIdentity(identity);
5229 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005230 }
5231
5232 /**
5233 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005234 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005235 * Require system privileges. In the future we may add this to carrier APIs.
5236 *
5237 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5238 * means all carriers are allowed.
5239 */
5240 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005241 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005242 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005243 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005244
5245 final long identity = Binder.clearCallingIdentity();
5246 try {
5247 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005248 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5249 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005250 } finally {
5251 Binder.restoreCallingIdentity(identity);
5252 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005253 }
5254
fionaxu59545b42016-05-25 15:53:37 -07005255 /**
5256 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5257 * @param subId the subscription ID that this action applies to.
5258 * @param enabled control enable or disable metered apns.
5259 * {@hide}
5260 */
5261 @Override
5262 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5263 enforceModifyPermission();
5264 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005265
5266 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005267 if (phone == null) {
5268 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5269 return;
5270 }
5271 try {
5272 phone.carrierActionSetMeteredApnsEnabled(enabled);
5273 } catch (Exception e) {
5274 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005275 } finally {
5276 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005277 }
5278 }
5279
5280 /**
5281 * Action set from carrier signalling broadcast receivers to enable/disable radio
5282 * @param subId the subscription ID that this action applies to.
5283 * @param enabled control enable or disable radio.
5284 * {@hide}
5285 */
5286 @Override
5287 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5288 enforceModifyPermission();
5289 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005290
5291 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005292 if (phone == null) {
5293 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5294 return;
5295 }
5296 try {
5297 phone.carrierActionSetRadioEnabled(enabled);
5298 } catch (Exception e) {
5299 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005300 } finally {
5301 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005302 }
5303 }
5304
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005305 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005306 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5307 * network status based on which carrier apps could apply actions accordingly,
5308 * enable/disable default url handler for example.
5309 *
5310 * @param subId the subscription ID that this action applies to.
5311 * @param report control start/stop reporting the default network status.
5312 * {@hide}
5313 */
5314 @Override
5315 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5316 enforceModifyPermission();
5317 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005318
5319 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005320 if (phone == null) {
5321 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5322 return;
5323 }
5324 try {
5325 phone.carrierActionReportDefaultNetworkStatus(report);
5326 } catch (Exception e) {
5327 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005328 } finally {
5329 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005330 }
5331 }
5332
5333 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005334 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5335 * bug report is being generated.
5336 */
5337 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005338 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005339 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5340 != PackageManager.PERMISSION_GRANTED) {
5341 writer.println("Permission Denial: can't dump Phone from pid="
5342 + Binder.getCallingPid()
5343 + ", uid=" + Binder.getCallingUid()
5344 + "without permission "
5345 + android.Manifest.permission.DUMP);
5346 return;
5347 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005348 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005349 }
Jack Yueb89b242016-06-22 13:27:47 -07005350
Brad Ebingerdac2f002018-04-03 15:17:52 -07005351 @Override
5352 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5353 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5354 throws RemoteException {
5355 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5356 }
5357
Jack Yueb89b242016-06-22 13:27:47 -07005358 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005359 * Get aggregated video call data usage since boot.
5360 *
5361 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5362 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005363 * {@hide}
5364 */
5365 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005366 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005367 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5368 null);
5369
Malcolm Chend965c8b2018-02-28 15:00:40 -08005370 final long identity = Binder.clearCallingIdentity();
5371 try {
5372 // NetworkStatsService keeps tracking the active network interface and identity. It
5373 // records the delta with the corresponding network identity.
5374 // We just return the total video call data usage snapshot since boot.
5375 Phone phone = getPhone(subId);
5376 if (phone != null) {
5377 return phone.getVtDataUsage(perUidStats);
5378 }
5379 return null;
5380 } finally {
5381 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005382 }
Jack Yueb89b242016-06-22 13:27:47 -07005383 }
Jack Yu75ab2952016-07-08 14:29:33 -07005384
5385 /**
5386 * Policy control of data connection. Usually used when data limit is passed.
5387 * @param enabled True if enabling the data, otherwise disabling.
5388 * @param subId Subscription index
5389 * {@hide}
5390 */
5391 @Override
5392 public void setPolicyDataEnabled(boolean enabled, int subId) {
5393 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005394
5395 final long identity = Binder.clearCallingIdentity();
5396 try {
5397 Phone phone = getPhone(subId);
5398 if (phone != null) {
5399 phone.setPolicyDataEnabled(enabled);
5400 }
5401 } finally {
5402 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005403 }
5404 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005405
5406 /**
5407 * Get Client request stats
5408 * @return List of Client Request Stats
5409 * @hide
5410 */
5411 @Override
5412 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005413 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005414 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005415 return null;
5416 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005417 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005418
Malcolm Chend965c8b2018-02-28 15:00:40 -08005419 final long identity = Binder.clearCallingIdentity();
5420 try {
5421 if (phone != null) {
5422 return phone.getClientRequestStats();
5423 }
5424
5425 return null;
5426 } finally {
5427 Binder.restoreCallingIdentity(identity);
5428 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005429 }
5430
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005431 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005432 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005433 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005434 }
Jack Yueb4124c2017-02-16 15:32:43 -08005435
5436 /**
Grace Chen70990072017-03-24 17:21:30 -07005437 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005438 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005439 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005440 * @param state State of SIM (power down, power up, pass through)
5441 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5442 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5443 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005444 *
5445 **/
5446 @Override
Grace Chen70990072017-03-24 17:21:30 -07005447 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005448 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005449 Phone phone = PhoneFactory.getPhone(slotIndex);
5450
vagdevie435a3e2018-08-15 16:01:53 -07005451 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5452
Malcolm Chend965c8b2018-02-28 15:00:40 -08005453 final long identity = Binder.clearCallingIdentity();
5454 try {
5455 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005456 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005457 }
5458 } finally {
5459 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005460 }
5461 }
Shuo Qiandd210312017-04-12 22:11:33 +00005462
Tyler Gunn65d45c22017-06-05 11:22:26 -07005463 private boolean isUssdApiAllowed(int subId) {
5464 CarrierConfigManager configManager =
5465 (CarrierConfigManager) mPhone.getContext().getSystemService(
5466 Context.CARRIER_CONFIG_SERVICE);
5467 if (configManager == null) {
5468 return false;
5469 }
5470 PersistableBundle pb = configManager.getConfigForSubId(subId);
5471 if (pb == null) {
5472 return false;
5473 }
5474 return pb.getBoolean(
5475 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5476 }
5477
Shuo Qiandd210312017-04-12 22:11:33 +00005478 /**
5479 * Check if phone is in emergency callback mode
5480 * @return true if phone is in emergency callback mode
5481 * @param subId sub id
5482 */
goneil9c5f4872017-12-05 14:07:56 -08005483 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005484 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005485 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005486 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005487
5488 final long identity = Binder.clearCallingIdentity();
5489 try {
5490 if (phone != null) {
5491 return phone.isInEcm();
5492 } else {
5493 return false;
5494 }
5495 } finally {
5496 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005497 }
5498 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005499
5500 /**
5501 * Get the current signal strength information for the given subscription.
5502 * Because this information is not updated when the device is in a low power state
5503 * it should not be relied-upon to be current.
5504 * @param subId Subscription index
5505 * @return the most recent cached signal strength info from the modem
5506 */
5507 @Override
5508 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005509 final long identity = Binder.clearCallingIdentity();
5510 try {
5511 Phone p = getPhone(subId);
5512 if (p == null) {
5513 return null;
5514 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005515
Malcolm Chend965c8b2018-02-28 15:00:40 -08005516 return p.getSignalStrength();
5517 } finally {
5518 Binder.restoreCallingIdentity(identity);
5519 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005520 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005521
Pengquan Meng9140aec2018-08-22 14:49:57 -07005522 /**
chen xu907e5a22018-10-11 13:21:04 -07005523 * Get the current modem radio state for the given slot.
5524 * @param slotIndex slot index.
5525 * @param callingPackage the name of the package making the call.
5526 * @return the current radio power state from the modem
5527 */
5528 @Override
5529 public int getRadioPowerState(int slotIndex, String callingPackage) {
5530 Phone phone = PhoneFactory.getPhone(slotIndex);
5531 if (phone != null) {
5532 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5533 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5534 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5535 }
5536
5537 final long identity = Binder.clearCallingIdentity();
5538 try {
5539 return phone.getRadioPowerState();
5540 } finally {
5541 Binder.restoreCallingIdentity(identity);
5542 }
5543 }
5544 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5545 }
5546
5547 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005548 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5549 *
5550 * <p>Requires one of the following permissions:
5551 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5552 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5553 * privileges.
5554 *
5555 * @param subId subscription id
5556 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5557 * {@code false}.
5558 */
5559 @Override
5560 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005561 boolean isEnabled = false;
5562 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005563 try {
5564 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005565 null /* message */);
5566 Phone phone = getPhone(subId);
5567 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005568 } catch (Exception e) {
5569 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5570 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005571 } finally {
5572 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005573 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005574 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005575 }
5576
5577
5578 /**
5579 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5580 *
5581 * <p> Requires permission:
5582 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5583 * privileges.
5584 *
5585 * @param subId subscription id
5586 * @param isEnabled {@code true} means enable, {@code false} means disable.
5587 */
5588 @Override
5589 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005590 final long identity = Binder.clearCallingIdentity();
5591 try {
5592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5593 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005594
Pengquan Meng0c05b502018-09-06 09:59:22 -07005595 Phone phone = getPhone(subId);
5596 if (phone != null) {
5597 phone.setDataRoamingEnabled(isEnabled);
5598 }
5599 } finally {
5600 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005601 }
5602 }
5603
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005604 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005605 public boolean isManualNetworkSelectionAllowed(int subId) {
5606 boolean isAllowed = true;
5607 final long identity = Binder.clearCallingIdentity();
5608 try {
5609 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5610 mApp, subId, "isManualNetworkSelectionAllowed");
5611 Phone phone = getPhone(subId);
5612 if (phone != null) {
5613 isAllowed = phone.isCspPlmnEnabled();
5614 }
5615 } finally {
5616 Binder.restoreCallingIdentity(identity);
5617 }
5618 return isAllowed;
5619 }
5620
5621 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005622 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005623 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005624
Malcolm Chend965c8b2018-02-28 15:00:40 -08005625 final long identity = Binder.clearCallingIdentity();
5626 try {
5627 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5628 if (slots == null) {
5629 Rlog.i(LOG_TAG, "slots is null.");
5630 return null;
5631 }
5632
5633 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5634 for (int i = 0; i < slots.length; i++) {
5635 UiccSlot slot = slots[i];
5636 if (slot == null) {
5637 continue;
5638 }
5639
5640 String cardId;
5641 UiccCard card = slot.getUiccCard();
5642 if (card != null) {
5643 cardId = card.getCardId();
5644 } else {
5645 cardId = slot.getIccId();
5646 }
5647
5648 int cardState = 0;
5649 switch (slot.getCardState()) {
5650 case CARDSTATE_ABSENT:
5651 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5652 break;
5653 case CARDSTATE_PRESENT:
5654 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5655 break;
5656 case CARDSTATE_ERROR:
5657 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5658 break;
5659 case CARDSTATE_RESTRICTED:
5660 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5661 break;
5662 default:
5663 break;
5664
5665 }
5666
5667 infos[i] = new UiccSlotInfo(
5668 slot.isActive(),
5669 slot.isEuicc(),
5670 cardId,
5671 cardState,
5672 slot.getPhoneId(),
5673 slot.isExtendedApduSupported());
5674 }
5675 return infos;
5676 } finally {
5677 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005678 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005679 }
5680
5681 @Override
5682 public boolean switchSlots(int[] physicalSlots) {
5683 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005684
5685 final long identity = Binder.clearCallingIdentity();
5686 try {
5687 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5688 } finally {
5689 Binder.restoreCallingIdentity(identity);
5690 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005691 }
Jack Yu4c988042018-02-27 15:30:01 -08005692
5693 @Override
5694 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5695 enforceModifyPermission();
5696 final Phone phone = getPhone(subId);
5697 if (phone == null) {
5698 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5699 return;
5700 }
5701
Malcolm Chend965c8b2018-02-28 15:00:40 -08005702 final long identity = Binder.clearCallingIdentity();
5703 try {
5704 phone.setRadioIndicationUpdateMode(filters, mode);
5705 } finally {
5706 Binder.restoreCallingIdentity(identity);
5707 }
Jack Yu4c988042018-02-27 15:30:01 -08005708 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005709
5710 /**
goneil47ffb6e2018-04-06 15:40:58 -07005711 * A test API to reload the UICC profile.
5712 *
5713 * <p>Requires that the calling app has permission
5714 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5715 * @hide
5716 */
5717 @Override
5718 public void refreshUiccProfile(int subId) {
5719 enforceModifyPermission();
5720
5721 final long identity = Binder.clearCallingIdentity();
5722 try {
5723 Phone phone = getPhone(subId);
5724 if (phone == null) {
5725 return;
5726 }
5727 UiccCard uiccCard = phone.getUiccCard();
5728 if (uiccCard == null) {
5729 return;
5730 }
5731 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5732 if (uiccProfile == null) {
5733 return;
5734 }
5735 uiccProfile.refresh();
5736 } finally {
5737 Binder.restoreCallingIdentity(identity);
5738 }
5739 }
5740
5741 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005742 * Returns false if the mobile data is disabled by default, otherwise return true.
5743 */
5744 private boolean getDefaultDataEnabled() {
5745 return "true".equalsIgnoreCase(
5746 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5747 }
5748
5749 /**
5750 * Returns true if the data roaming is enabled by default, i.e the system property
5751 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5752 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5753 */
5754 private boolean getDefaultDataRoamingEnabled(int subId) {
5755 final CarrierConfigManager configMgr = (CarrierConfigManager)
5756 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5757 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5758 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5759 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5760 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5761 return isDataRoamingEnabled;
5762 }
5763
5764 /**
5765 * Returns the default network type for the given {@code subId}, if the default network type is
5766 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5767 */
5768 private int getDefaultNetworkType(int subId) {
5769 return Integer.parseInt(
5770 TelephonyManager.getTelephonyProperty(
5771 mSubscriptionController.getPhoneId(subId),
5772 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5773 String.valueOf(Phone.PREFERRED_NT_MODE)));
5774 }
fionaxua13278b2018-03-21 00:08:13 -07005775
5776 @Override
5777 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5778 gid1, String gid2, String plmn, String spn) {
5779 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005780
5781 final long identity = Binder.clearCallingIdentity();
5782 try {
5783 final Phone phone = getPhone(subId);
5784 if (phone == null) {
5785 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5786 return;
5787 }
5788 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5789 } finally {
5790 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005791 }
fionaxua13278b2018-03-21 00:08:13 -07005792 }
5793
5794 @Override
5795 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005796 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005797
5798 final long identity = Binder.clearCallingIdentity();
5799 try {
5800 final Phone phone = getPhone(subId);
5801 if (phone == null) {
5802 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5803 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5804 }
5805 return phone.getCarrierIdListVersion();
5806 } finally {
5807 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005808 }
fionaxua13278b2018-03-21 00:08:13 -07005809 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005810
5811 @Override
5812 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5813 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5814 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5815 return -1;
5816 }
5817
5818 final long identity = Binder.clearCallingIdentity();
5819 try {
5820 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5821 } finally {
5822 Binder.restoreCallingIdentity(identity);
5823 }
5824 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005825
5826 @Override
5827 public int getCdmaRoamingMode(int subId) {
5828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5829 mApp, subId, "getCdmaRoamingMode");
5830
5831 final long identity = Binder.clearCallingIdentity();
5832 try {
5833 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5834 } finally {
5835 Binder.restoreCallingIdentity(identity);
5836 }
5837 }
5838
5839 @Override
5840 public boolean setCdmaRoamingMode(int subId, int mode) {
5841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5842 mApp, subId, "setCdmaRoamingMode");
5843
5844 final long identity = Binder.clearCallingIdentity();
5845 try {
5846 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5847 } finally {
5848 Binder.restoreCallingIdentity(identity);
5849 }
5850 }
5851
5852 @Override
5853 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5855 mApp, subId, "setCdmaSubscriptionMode");
5856
5857 final long identity = Binder.clearCallingIdentity();
5858 try {
5859 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5860 } finally {
5861 Binder.restoreCallingIdentity(identity);
5862 }
5863 }
chen xu7ee67862018-10-30 22:27:10 -07005864
sqian2fff4a32018-11-05 14:18:37 -08005865 private void ensureUserRunning(int userId) {
5866 if (!mUserManager.isUserRunning(userId)) {
5867 throw new IllegalStateException("User " + userId + " does not exist or not running");
5868 }
5869 }
5870
5871 /**
5872 * Returns a list of SMS apps on a given user.
5873 *
5874 * Only the shell user (UID 2000 or 0) can call it.
5875 * Target user must be running.
5876 */
5877 @Override
5878 public String[] getSmsApps(int userId) {
5879 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5880 ensureUserRunning(userId);
5881
5882 final Collection<SmsApplicationData> apps =
5883 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5884
5885 String[] ret = new String[apps.size()];
5886 int i = 0;
5887 for (SmsApplicationData app : apps) {
5888 ret[i++] = app.mPackageName;
5889 }
5890 return ret;
5891 }
5892
5893 /**
5894 * Returns the default SMS app package name on a given user.
5895 *
5896 * Only the shell user (UID 2000 or 0) can call it.
5897 * Target user must be running.
5898 */
5899 @Override
5900 public String getDefaultSmsApp(int userId) {
5901 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5902 ensureUserRunning(userId);
5903
5904 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5905 /* updateIfNeeded= */ true, userId);
5906 return cn == null ? null : cn.getPackageName();
5907 }
5908
5909 /**
5910 * Set a package as the default SMS app on a given user.
5911 *
5912 * Only the shell user (UID 2000 or 0) can call it.
5913 * Target user must be running.
5914 */
5915 @Override
5916 public void setDefaultSmsApp(int userId, String packageName) {
5917 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5918 ensureUserRunning(userId);
5919
5920 boolean found = false;
5921 for (String pkg : getSmsApps(userId)) {
5922 if (TextUtils.equals(packageName, pkg)) {
5923 found = true;
5924 break;
5925 }
5926 }
5927 if (!found) {
5928 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5929 }
5930
5931 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5932 }
5933
chen xu7ee67862018-10-30 22:27:10 -07005934 @Override
sqian04b86072018-11-07 14:02:21 -08005935 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5936 String callingPackage) {
5937 // TODO connect with internal content
5938 return null;
5939 }
5940
5941 @Override
5942 public boolean isCurrentEmergencyNumber(String number) {
5943 // TODO connect with internal content
5944 return false;
5945 }
5946
5947 @Override
chen xu7ee67862018-10-30 22:27:10 -07005948 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5949 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5950 Phone phone = getPhone(subId);
5951 if (phone == null) {
5952 return null;
5953 }
5954 final long identity = Binder.clearCallingIdentity();
5955 try {
5956 UiccProfile profile = UiccController.getInstance()
5957 .getUiccProfileForPhone(phone.getPhoneId());
5958 if (profile != null) {
5959 return profile.getCertsFromCarrierPrivilegeAccessRules();
5960 }
5961 } finally {
5962 Binder.restoreCallingIdentity(identity);
5963 }
5964 return null;
5965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005966}