blob: cb5958345be03d8f84158597a3562a1b14c8360a [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;
calvinpaneed9ae82018-11-01 19:43:06 +080082import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070083import android.telephony.gsm.GsmCellLocation;
Brad Ebinger4c460712018-10-01 10:40:55 -070084import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080085import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070086import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080087import android.telephony.ims.aidl.IImsMmTelFeature;
88import android.telephony.ims.aidl.IImsRcsFeature;
89import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070090import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080091import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080093import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080095import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080096import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080097
Brad Ebinger4c460712018-10-01 10:40:55 -070098import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070099import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800100import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700101import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700102import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700103import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800104import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700105import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700106import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800109import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700110import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100111import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700112import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700113import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700115import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800116import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700117import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700118import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700119import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700120import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700121import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700122import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800123import com.android.internal.telephony.SmsApplication;
124import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800125import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800126import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700127import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.uicc.IccIoResult;
129import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800130import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700131import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800132import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700133import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800134import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000135import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700136import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800137import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700138import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800139import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700140import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700141import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800142
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700143import java.io.FileDescriptor;
144import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800145import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800147import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800148import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800149import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100150import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800151import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152
153/**
154 * Implementation of the ITelephony interface.
155 */
Santos Cordon117fee72014-05-16 17:56:12 -0700156public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157 private static final String LOG_TAG = "PhoneInterfaceManager";
158 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
159 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800160 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161
162 // Message codes used with mMainThreadHandler
163 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700164 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
165 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166 private static final int CMD_OPEN_CHANNEL = 9;
167 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
168 private static final int CMD_CLOSE_CHANNEL = 11;
169 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800170 private static final int CMD_NV_READ_ITEM = 13;
171 private static final int EVENT_NV_READ_ITEM_DONE = 14;
172 private static final int CMD_NV_WRITE_ITEM = 15;
173 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
174 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
175 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700176 private static final int CMD_RESET_MODEM_CONFIG = 19;
177 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800178 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
179 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
180 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
181 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800182 private static final int CMD_SEND_ENVELOPE = 25;
183 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000184 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
185 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700186 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
187 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
188 private static final int CMD_EXCHANGE_SIM_IO = 31;
189 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800190 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
191 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700192 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
193 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700194 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
195 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700196 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
197 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
198 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
199 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700200 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
201 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
202 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
203 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700204 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800205 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
206 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000207 private static final int CMD_SWITCH_SLOTS = 50;
208 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700209 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
210 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
211 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
212 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
213 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
214 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
215 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
216 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700217 private static final int CMD_GET_ALL_CELL_INFO = 60;
218 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
219 private static final int CMD_GET_CELL_LOCATION = 62;
220 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700221 private static final int CMD_MODEM_REBOOT = 64;
222 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700223 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
224 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800226 // Parameters of select command.
227 private static final int SELECT_COMMAND = 0xA4;
228 private static final int SELECT_P1 = 0x04;
229 private static final int SELECT_P2 = 0;
230 private static final int SELECT_P3 = 0x10;
231
Pengquan Meng85728fb2018-03-12 16:31:21 -0700232 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
233 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
234 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
235
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236 /** The singleton instance. */
237 private static PhoneInterfaceManager sInstance;
238
Wink Saville3ab207e2014-11-20 13:07:20 -0800239 private PhoneGlobals mApp;
240 private Phone mPhone;
241 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700242 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800243 private AppOpsManager mAppOps;
244 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800245 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800246 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700247 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248
Derek Tan97ebb422014-09-05 16:55:38 -0700249 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
250 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800251 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700252
Derek Tan740e1672017-06-27 14:56:27 -0700253 // The AID of ISD-R.
254 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
255
yinxub1bed742017-04-17 11:45:04 -0700256 private NetworkScanRequestTracker mNetworkScanRequestTracker;
257
David Kelly5e06a7f2018-03-12 14:10:59 +0000258 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
259 private static final int MANUFACTURER_CODE_LENGTH = 8;
260
Derek Tan89e89d42014-07-08 17:00:10 -0700261 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700262 * A request object to use for transmitting data to an ICC.
263 */
264 private static final class IccAPDUArgument {
265 public int channel, cla, command, p1, p2, p3;
266 public String data;
267
268 public IccAPDUArgument(int channel, int cla, int command,
269 int p1, int p2, int p3, String data) {
270 this.channel = channel;
271 this.cla = cla;
272 this.command = command;
273 this.p1 = p1;
274 this.p2 = p2;
275 this.p3 = p3;
276 this.data = data;
277 }
278 }
279
280 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700281 * A request object to use for transmitting data to an ICC.
282 */
283 private static final class ManualNetworkSelectionArgument {
284 public OperatorInfo operatorInfo;
285 public boolean persistSelection;
286
287 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
288 this.operatorInfo = operatorInfo;
289 this.persistSelection = persistSelection;
290 }
291 }
292
293 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700294 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
295 * request after sending. The main thread will notify the request when it is complete.
296 */
297 private static final class MainThreadRequest {
298 /** The argument to use for the request */
299 public Object argument;
300 /** The result of the request that is run on the main thread */
301 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800302 // The subscriber id that this request applies to. Defaults to
303 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
304 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700305
Nathan Harold92bed182018-10-12 18:16:49 -0700306 // In cases where subId is unavailable, the caller needs to specify the phone.
307 public Phone phone;
308
vagdevie435a3e2018-08-15 16:01:53 -0700309 public WorkSource workSource;
310
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311 public MainThreadRequest(Object argument) {
312 this.argument = argument;
313 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800314
Nathan Harold92bed182018-10-12 18:16:49 -0700315 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
316 this.argument = argument;
317 if (phone != null) {
318 this.phone = phone;
319 }
320 this.workSource = workSource;
321 }
322
vagdevie435a3e2018-08-15 16:01:53 -0700323 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800324 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800325 if (subId != null) {
326 this.subId = subId;
327 }
vagdevie435a3e2018-08-15 16:01:53 -0700328 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 }
331
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800332 private static final class IncomingThirdPartyCallArgs {
333 public final ComponentName component;
334 public final String callId;
335 public final String callerDisplayName;
336
337 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
338 String callerDisplayName) {
339 this.component = component;
340 this.callId = callId;
341 this.callerDisplayName = callerDisplayName;
342 }
343 }
344
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 /**
346 * A handler that processes messages on the main thread in the phone process. Since many
347 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
348 * inbound binder threads to the main thread in the phone process. The Binder thread
349 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
350 * on, which will be notified when the operation completes and will contain the result of the
351 * request.
352 *
353 * <p>If a MainThreadRequest object is provided in the msg.obj field,
354 * note that request.result must be set to something non-null for the calling thread to
355 * unblock.
356 */
357 private final class MainThreadHandler extends Handler {
358 @Override
359 public void handleMessage(Message msg) {
360 MainThreadRequest request;
361 Message onCompleted;
362 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800363 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700364 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365
366 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700367 case CMD_HANDLE_USSD_REQUEST: {
368 request = (MainThreadRequest) msg.obj;
369 final Phone phone = getPhoneFromRequest(request);
370 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
371 String ussdRequest = ussdObject.first;
372 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700373
Pengquan Meng0c05b502018-09-06 09:59:22 -0700374 if (!isUssdApiAllowed(request.subId)) {
375 // Carrier does not support use of this API, return failure.
376 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
377 UssdResponse response = new UssdResponse(ussdRequest, null);
378 Bundle returnData = new Bundle();
379 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
380 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700381
Pengquan Meng0c05b502018-09-06 09:59:22 -0700382 request.result = true;
383 notifyRequester(request);
384 return;
385 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700386
Pengquan Meng0c05b502018-09-06 09:59:22 -0700387 try {
388 request.result = phone != null
389 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
390 } catch (CallStateException cse) {
391 request.result = false;
392 }
393 // Wake up the requesting thread
394 notifyRequester(request);
395 break;
pkanwar32d516d2016-10-14 19:37:38 -0700396 }
397
Yorke Lee716f67e2015-06-17 15:39:16 -0700398 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700400 final Phone phone = getPhoneFromRequest(request);
401 request.result = phone != null ?
402 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
403 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700405 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700409 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700410 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700411 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800412 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700413 if (uiccCard == null) {
414 loge("iccTransmitApduLogicalChannel: No UICC");
415 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700416 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700417 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700418 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
419 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700420 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700421 iccArgument.channel, iccArgument.cla, iccArgument.command,
422 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700423 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700424 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700425 break;
426
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700428 ar = (AsyncResult) msg.obj;
429 request = (MainThreadRequest) ar.userObj;
430 if (ar.exception == null && ar.result != null) {
431 request.result = ar.result;
432 } else {
433 request.result = new IccIoResult(0x6F, 0, (byte[])null);
434 if (ar.result == null) {
435 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800436 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800438 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700439 } else {
440 loge("iccTransmitApduLogicalChannel: Unknown exception");
441 }
442 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700443 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 break;
445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
447 request = (MainThreadRequest) msg.obj;
448 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800449 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700450 if (uiccCard == null) {
451 loge("iccTransmitApduBasicChannel: No UICC");
452 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700453 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 } else {
455 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
456 request);
457 uiccCard.iccTransmitApduBasicChannel(
458 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
459 iccArgument.p3, iccArgument.data, onCompleted);
460 }
461 break;
462
463 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
464 ar = (AsyncResult) msg.obj;
465 request = (MainThreadRequest) ar.userObj;
466 if (ar.exception == null && ar.result != null) {
467 request.result = ar.result;
468 } else {
469 request.result = new IccIoResult(0x6F, 0, (byte[])null);
470 if (ar.result == null) {
471 loge("iccTransmitApduBasicChannel: Empty response");
472 } else if (ar.exception instanceof CommandException) {
473 loge("iccTransmitApduBasicChannel: CommandException: " +
474 ar.exception);
475 } else {
476 loge("iccTransmitApduBasicChannel: Unknown exception");
477 }
478 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700479 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 break;
481
482 case CMD_EXCHANGE_SIM_IO:
483 request = (MainThreadRequest) msg.obj;
484 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800485 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 if (uiccCard == null) {
487 loge("iccExchangeSimIO: No UICC");
488 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700489 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 } else {
491 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
492 request);
493 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
494 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
495 iccArgument.data, onCompleted);
496 }
497 break;
498
499 case EVENT_EXCHANGE_SIM_IO_DONE:
500 ar = (AsyncResult) msg.obj;
501 request = (MainThreadRequest) ar.userObj;
502 if (ar.exception == null && ar.result != null) {
503 request.result = ar.result;
504 } else {
505 request.result = new IccIoResult(0x6f, 0, (byte[])null);
506 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700507 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 break;
509
Derek Tan4d5e5c12014-02-04 11:54:58 -0800510 case CMD_SEND_ENVELOPE:
511 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800512 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700513 if (uiccCard == null) {
514 loge("sendEnvelopeWithStatus: No UICC");
515 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700516 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700517 } else {
518 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
519 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
520 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800521 break;
522
523 case EVENT_SEND_ENVELOPE_DONE:
524 ar = (AsyncResult) msg.obj;
525 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700526 if (ar.exception == null && ar.result != null) {
527 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800528 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700529 request.result = new IccIoResult(0x6F, 0, (byte[])null);
530 if (ar.result == null) {
531 loge("sendEnvelopeWithStatus: Empty response");
532 } else if (ar.exception instanceof CommandException) {
533 loge("sendEnvelopeWithStatus: CommandException: " +
534 ar.exception);
535 } else {
536 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
537 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800538 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700539 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800540 break;
541
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 case CMD_OPEN_CHANNEL:
543 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800544 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800545 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700546 if (uiccCard == null) {
547 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800548 request.result = new IccOpenLogicalChannelResponse(-1,
549 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700550 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 } else {
552 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800553 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
554 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 break;
557
558 case EVENT_OPEN_CHANNEL_DONE:
559 ar = (AsyncResult) msg.obj;
560 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 int[] result = (int[]) ar.result;
564 int channelId = result[0];
565 byte[] selectResponse = null;
566 if (result.length > 1) {
567 selectResponse = new byte[result.length - 1];
568 for (int i = 1; i < result.length; ++i) {
569 selectResponse[i - 1] = (byte) result[i];
570 }
571 }
572 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700573 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 if (ar.result == null) {
576 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700578 if (ar.exception != null) {
579 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
580 }
581
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700582 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700583 if (ar.exception instanceof CommandException) {
584 CommandException.Error error =
585 ((CommandException) (ar.exception)).getCommandError();
586 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700587 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700588 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700589 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 }
591 }
592 openChannelResp = new IccOpenLogicalChannelResponse(
593 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700595 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700596 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 break;
598
599 case CMD_CLOSE_CHANNEL:
600 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800601 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700602 if (uiccCard == null) {
603 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900604 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700605 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700606 } else {
607 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
608 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
609 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 break;
611
612 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800613 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
614 break;
615
616 case CMD_NV_READ_ITEM:
617 request = (MainThreadRequest) msg.obj;
618 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700619 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800620 break;
621
622 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 ar = (AsyncResult) msg.obj;
624 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800625 if (ar.exception == null && ar.result != null) {
626 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800628 request.result = "";
629 if (ar.result == null) {
630 loge("nvReadItem: Empty response");
631 } else if (ar.exception instanceof CommandException) {
632 loge("nvReadItem: CommandException: " +
633 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800635 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 }
637 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700638 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 break;
640
Jake Hambye994d462014-02-03 13:10:13 -0800641 case CMD_NV_WRITE_ITEM:
642 request = (MainThreadRequest) msg.obj;
643 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
644 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdevie435a3e2018-08-15 16:01:53 -0700645 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
646 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800647 break;
648
649 case EVENT_NV_WRITE_ITEM_DONE:
650 handleNullReturnEvent(msg, "nvWriteItem");
651 break;
652
653 case CMD_NV_WRITE_CDMA_PRL:
654 request = (MainThreadRequest) msg.obj;
655 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
656 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
657 break;
658
659 case EVENT_NV_WRITE_CDMA_PRL_DONE:
660 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
661 break;
662
chen xu1cc0abe2018-10-26 17:39:23 -0700663 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800664 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700665 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
666 mPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800667 break;
668
chen xu1cc0abe2018-10-26 17:39:23 -0700669 case EVENT_RESET_MODEM_CONFIG_DONE:
670 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800671 break;
672
Jake Hamby7c27be32014-03-03 13:25:59 -0800673 case CMD_GET_PREFERRED_NETWORK_TYPE:
674 request = (MainThreadRequest) msg.obj;
675 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700676 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800677 break;
678
679 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
680 ar = (AsyncResult) msg.obj;
681 request = (MainThreadRequest) ar.userObj;
682 if (ar.exception == null && ar.result != null) {
683 request.result = ar.result; // Integer
684 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800685 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800686 if (ar.result == null) {
687 loge("getPreferredNetworkType: Empty response");
688 } else if (ar.exception instanceof CommandException) {
689 loge("getPreferredNetworkType: CommandException: " +
690 ar.exception);
691 } else {
692 loge("getPreferredNetworkType: Unknown exception");
693 }
694 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700695 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800696 break;
697
698 case CMD_SET_PREFERRED_NETWORK_TYPE:
699 request = (MainThreadRequest) msg.obj;
700 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
701 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700702 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800703 break;
704
705 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
706 handleNullReturnEvent(msg, "setPreferredNetworkType");
707 break;
708
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000709 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
710 request = (MainThreadRequest)msg.obj;
711 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700712 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000713 break;
714
715 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
716 ar = (AsyncResult)msg.obj;
717 request = (MainThreadRequest)ar.userObj;
718 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700719 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000720 break;
721
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800722 case CMD_SET_VOICEMAIL_NUMBER:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
725 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800726 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
727 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800728 break;
729
730 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
731 handleNullReturnEvent(msg, "setVoicemailNumber");
732 break;
733
Stuart Scott54788802015-03-30 13:18:01 -0700734 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
735 request = (MainThreadRequest) msg.obj;
736 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
737 request);
738 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
739 break;
740
741 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
742 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
743 break;
744
Shishir Agrawal302c8692015-06-19 13:49:39 -0700745 case CMD_PERFORM_NETWORK_SCAN:
746 request = (MainThreadRequest) msg.obj;
747 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
748 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
749 break;
750
751 case EVENT_PERFORM_NETWORK_SCAN_DONE:
752 ar = (AsyncResult) msg.obj;
753 request = (MainThreadRequest) ar.userObj;
754 CellNetworkScanResult cellScanResult;
755 if (ar.exception == null && ar.result != null) {
756 cellScanResult = new CellNetworkScanResult(
757 CellNetworkScanResult.STATUS_SUCCESS,
758 (List<OperatorInfo>) ar.result);
759 } else {
760 if (ar.result == null) {
761 loge("getCellNetworkScanResults: Empty response");
762 }
763 if (ar.exception != null) {
764 loge("getCellNetworkScanResults: Exception: " + ar.exception);
765 }
766 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
767 if (ar.exception instanceof CommandException) {
768 CommandException.Error error =
769 ((CommandException) (ar.exception)).getCommandError();
770 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
771 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
772 } else if (error == CommandException.Error.GENERIC_FAILURE) {
773 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
774 }
775 }
776 cellScanResult = new CellNetworkScanResult(errorCode, null);
777 }
778 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700779 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700780 break;
781
782 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
783 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700784 ManualNetworkSelectionArgument selArg =
785 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700786 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
787 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700788 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
789 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700790 break;
791
792 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700793 ar = (AsyncResult) msg.obj;
794 request = (MainThreadRequest) ar.userObj;
795 if (ar.exception == null) {
796 request.result = true;
797 } else {
798 request.result = false;
799 loge("setNetworkSelectionModeManual " + ar.exception);
800 }
801 notifyRequester(request);
802 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700803 break;
804
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700805 case CMD_GET_MODEM_ACTIVITY_INFO:
806 request = (MainThreadRequest) msg.obj;
807 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700808 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700809 break;
810
811 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
812 ar = (AsyncResult) msg.obj;
813 request = (MainThreadRequest) ar.userObj;
814 if (ar.exception == null && ar.result != null) {
815 request.result = ar.result;
816 } else {
817 if (ar.result == null) {
818 loge("queryModemActivityInfo: Empty response");
819 } else if (ar.exception instanceof CommandException) {
820 loge("queryModemActivityInfo: CommandException: " +
821 ar.exception);
822 } else {
823 loge("queryModemActivityInfo: Unknown exception");
824 }
825 }
Amit Mahajand4766222016-01-28 15:28:28 -0800826 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
827 if (request.result == null) {
828 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
829 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700830 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700831 break;
832
Meng Wang1a7c35a2016-05-05 20:56:15 -0700833 case CMD_SET_ALLOWED_CARRIERS:
834 request = (MainThreadRequest) msg.obj;
835 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
836 mPhone.setAllowedCarriers(
837 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700838 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700839 break;
840
841 case EVENT_SET_ALLOWED_CARRIERS_DONE:
842 ar = (AsyncResult) msg.obj;
843 request = (MainThreadRequest) ar.userObj;
844 if (ar.exception == null && ar.result != null) {
845 request.result = ar.result;
846 } else {
847 if (ar.result == null) {
848 loge("setAllowedCarriers: Empty response");
849 } else if (ar.exception instanceof CommandException) {
850 loge("setAllowedCarriers: CommandException: " +
851 ar.exception);
852 } else {
853 loge("setAllowedCarriers: Unknown exception");
854 }
855 }
856 // Result cannot be null. Return -1 on error.
857 if (request.result == null) {
858 request.result = new int[]{-1};
859 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700860 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700861 break;
862
863 case CMD_GET_ALLOWED_CARRIERS:
864 request = (MainThreadRequest) msg.obj;
865 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700866 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700867 break;
868
869 case EVENT_GET_ALLOWED_CARRIERS_DONE:
870 ar = (AsyncResult) msg.obj;
871 request = (MainThreadRequest) ar.userObj;
872 if (ar.exception == null && ar.result != null) {
873 request.result = ar.result;
874 } else {
875 if (ar.result == null) {
876 loge("getAllowedCarriers: Empty response");
877 } else if (ar.exception instanceof CommandException) {
878 loge("getAllowedCarriers: CommandException: " +
879 ar.exception);
880 } else {
881 loge("getAllowedCarriers: Unknown exception");
882 }
883 }
884 // Result cannot be null. Return empty list of CarrierIdentifier.
885 if (request.result == null) {
886 request.result = new ArrayList<CarrierIdentifier>(0);
887 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700888 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 break;
890
Nathan Haroldb3014052017-01-25 15:57:32 -0800891 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
892 ar = (AsyncResult) msg.obj;
893 request = (MainThreadRequest) ar.userObj;
894 if (ar.exception == null && ar.result != null) {
895 request.result = ar.result;
896 } else {
897 request.result = new IllegalArgumentException(
898 "Failed to retrieve Forbidden Plmns");
899 if (ar.result == null) {
900 loge("getForbiddenPlmns: Empty response");
901 } else {
902 loge("getForbiddenPlmns: Unknown exception");
903 }
904 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700905 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800906 break;
907
908 case CMD_GET_FORBIDDEN_PLMNS:
909 request = (MainThreadRequest) msg.obj;
910 uiccCard = getUiccCardFromRequest(request);
911 if (uiccCard == null) {
912 loge("getForbiddenPlmns() UiccCard is null");
913 request.result = new IllegalArgumentException(
914 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700915 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800916 break;
917 }
918 Integer appType = (Integer) request.argument;
919 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
920 if (uiccApp == null) {
921 loge("getForbiddenPlmns() no app with specified type -- "
922 + appType);
923 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700924 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800925 break;
926 } else {
927 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
928 + " specified type -- " + appType);
929 }
930 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
931 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
932 onCompleted);
933 break;
934
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000935 case CMD_SWITCH_SLOTS:
936 request = (MainThreadRequest) msg.obj;
937 int[] physicalSlots = (int[]) request.argument;
938 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
939 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
940 break;
941
942 case EVENT_SWITCH_SLOTS_DONE:
943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
945 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700946 notifyRequester(request);
947 break;
948 case CMD_GET_NETWORK_SELECTION_MODE:
949 request = (MainThreadRequest) msg.obj;
950 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
951 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
952 break;
953
954 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
955 ar = (AsyncResult) msg.obj;
956 request = (MainThreadRequest) ar.userObj;
957 if (ar.exception != null) {
958 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
959 } else {
960 int mode = ((int[]) ar.result)[0];
961 if (mode == 0) {
962 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
963 } else {
964 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
965 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000966 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700967 notifyRequester(request);
968 break;
969 case CMD_GET_CDMA_ROAMING_MODE:
970 request = (MainThreadRequest) msg.obj;
971 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
972 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
973 break;
974 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
975 ar = (AsyncResult) msg.obj;
976 request = (MainThreadRequest) ar.userObj;
977 if (ar.exception != null) {
978 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
979 } else {
980 request.result = ((int[]) ar.result)[0];
981 }
982 notifyRequester(request);
983 break;
984 case CMD_SET_CDMA_ROAMING_MODE:
985 request = (MainThreadRequest) msg.obj;
986 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
987 int mode = (int) request.argument;
988 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
989 break;
990 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
991 ar = (AsyncResult) msg.obj;
992 request = (MainThreadRequest) ar.userObj;
993 request.result = ar.exception == null;
994 notifyRequester(request);
995 break;
996 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
997 request = (MainThreadRequest) msg.obj;
998 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
999 int subscriptionMode = (int) request.argument;
1000 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1001 break;
1002 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1003 ar = (AsyncResult) msg.obj;
1004 request = (MainThreadRequest) ar.userObj;
1005 request.result = ar.exception == null;
1006 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001007 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001008 case CMD_GET_ALL_CELL_INFO:
1009 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001010 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001011 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001012 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001013 case EVENT_GET_ALL_CELL_INFO_DONE:
1014 ar = (AsyncResult) msg.obj;
1015 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001016 // If a timeout occurs, the response will be null
1017 request.result = (ar.exception == null && ar.result != null)
1018 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001019 synchronized (request) {
1020 request.notifyAll();
1021 }
1022 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001023 case CMD_REQUEST_CELL_INFO_UPDATE:
1024 request = (MainThreadRequest) msg.obj;
1025 request.phone.requestCellInfoUpdate(request.workSource,
1026 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1027 break;
1028 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1032 try {
1033 if (ar.exception != null) {
1034 // something went wrong... the response is null
1035 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1036 cb.onCellInfo(null);
1037 } else if (ar.result == null) {
1038 // timeout occurred, so force the result to non-null "empty"
1039 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1040 cb.onCellInfo(new ArrayList<CellInfo>());
1041 } else {
1042 // use the result as returned
1043 cb.onCellInfo((List<CellInfo>) ar.result);
1044 }
1045 } catch (RemoteException re) {
1046 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1047 }
1048 break;
1049 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001050 request = (MainThreadRequest) msg.obj;
1051 WorkSource ws = (WorkSource) request.argument;
1052 Phone phone = getPhoneFromRequest(request);
1053 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1054 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001055 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001056 ar = (AsyncResult) msg.obj;
1057 request = (MainThreadRequest) ar.userObj;
1058 if (ar.exception == null) {
1059 request.result = ar.result;
1060 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1063 ? new CdmaCellLocation() : new GsmCellLocation();
1064 }
1065
1066 synchronized (request) {
1067 request.notifyAll();
1068 }
1069 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001070 case CMD_MODEM_REBOOT:
1071 request = (MainThreadRequest) msg.obj;
1072 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
1073 mPhone.rebootModem(onCompleted);
1074 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001075 case EVENT_CMD_MODEM_REBOOT_DONE:
1076 handleNullReturnEvent(msg, "rebootModem");
1077 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001078 default:
1079 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1080 break;
1081 }
1082 }
Jake Hambye994d462014-02-03 13:10:13 -08001083
Pengquan Meng0c05b502018-09-06 09:59:22 -07001084 private void notifyRequester(MainThreadRequest request) {
1085 synchronized (request) {
1086 request.notifyAll();
1087 }
1088 }
1089
Jake Hambye994d462014-02-03 13:10:13 -08001090 private void handleNullReturnEvent(Message msg, String command) {
1091 AsyncResult ar = (AsyncResult) msg.obj;
1092 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1093 if (ar.exception == null) {
1094 request.result = true;
1095 } else {
1096 request.result = false;
1097 if (ar.exception instanceof CommandException) {
1098 loge(command + ": CommandException: " + ar.exception);
1099 } else {
1100 loge(command + ": Unknown exception");
1101 }
1102 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001103 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001105 }
1106
1107 /**
1108 * Posts the specified command to be executed on the main thread,
1109 * waits for the request to complete, and returns the result.
1110 * @see #sendRequestAsync
1111 */
1112 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001113 return sendRequest(
1114 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001115 }
1116
1117 /**
1118 * Posts the specified command to be executed on the main thread,
1119 * waits for the request to complete, and returns the result.
1120 * @see #sendRequestAsync
1121 */
1122 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1123 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001124 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001125 }
1126
1127 /**
1128 * Posts the specified command to be executed on the main thread,
1129 * waits for the request to complete, and returns the result.
1130 * @see #sendRequestAsync
1131 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001132 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001133 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001134 }
1135
1136 /**
1137 * Posts the specified command to be executed on the main thread,
1138 * waits for the request to complete, and returns the result.
1139 * @see #sendRequestAsync
1140 */
Nathan Harold92bed182018-10-12 18:16:49 -07001141 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1142 return sendRequest(command, argument, subId, null, workSource);
1143 }
1144
1145 /**
1146 * Posts the specified command to be executed on the main thread,
1147 * waits for the request to complete, and returns the result.
1148 * @see #sendRequestAsync
1149 */
1150 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1151 return sendRequest(
1152 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1153 }
1154
1155 /**
1156 * Posts the specified command to be executed on the main thread,
1157 * waits for the request to complete, and returns the result.
1158 * @see #sendRequestAsync
1159 */
1160 private Object sendRequest(
1161 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001162 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1163 throw new RuntimeException("This method will deadlock if called from the main thread.");
1164 }
1165
Nathan Harold92bed182018-10-12 18:16:49 -07001166 MainThreadRequest request = null;
1167 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1168 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1169 } else if (phone != null) {
1170 request = new MainThreadRequest(argument, phone, workSource);
1171 } else {
1172 request = new MainThreadRequest(argument, subId, workSource);
1173 }
1174
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001175 Message msg = mMainThreadHandler.obtainMessage(command, request);
1176 msg.sendToTarget();
1177
1178 // Wait for the request to complete
1179 synchronized (request) {
1180 while (request.result == null) {
1181 try {
1182 request.wait();
1183 } catch (InterruptedException e) {
1184 // Do nothing, go back and wait until the request is complete
1185 }
1186 }
1187 }
1188 return request.result;
1189 }
1190
1191 /**
1192 * Asynchronous ("fire and forget") version of sendRequest():
1193 * Posts the specified command to be executed on the main thread, and
1194 * returns immediately.
1195 * @see #sendRequest
1196 */
1197 private void sendRequestAsync(int command) {
1198 mMainThreadHandler.sendEmptyMessage(command);
1199 }
1200
1201 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001202 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001203 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001204 */
1205 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001206 sendRequestAsync(command, argument, null, null);
1207 }
1208
1209 /**
1210 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1211 * @see {@link #sendRequest(int,Object)}
1212 */
1213 private void sendRequestAsync(
1214 int command, Object argument, Phone phone, WorkSource workSource) {
1215 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001216 Message msg = mMainThreadHandler.obtainMessage(command, request);
1217 msg.sendToTarget();
1218 }
1219
1220 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001221 * Initialize the singleton PhoneInterfaceManager instance.
1222 * This is only done once, at startup, from PhoneApp.onCreate().
1223 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001224 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001225 synchronized (PhoneInterfaceManager.class) {
1226 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001227 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228 } else {
1229 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1230 }
1231 return sInstance;
1232 }
1233 }
1234
1235 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001236 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001237 mApp = app;
1238 mPhone = phone;
1239 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001240 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001241 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1242 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001243 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001244 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001245 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001246 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001247 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001248
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 publish();
1250 }
1251
1252 private void publish() {
1253 if (DBG) log("publish: " + this);
1254
1255 ServiceManager.addService("phone", this);
1256 }
1257
Stuart Scott584921c2015-01-15 17:10:34 -08001258 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001259 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1260 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001261 }
1262
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001263 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1264 Phone phone = getPhoneFromRequest(request);
1265 return phone == null ? null :
1266 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1267 }
1268
Wink Saville36469e72014-06-11 15:17:00 -07001269 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001270 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001271 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001273
1274 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001275 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001276 }
1277
Wink Savilleb564aae2014-10-23 10:18:09 -07001278 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001279 if (DBG) log("dial: " + number);
1280 // No permission check needed here: This is just a wrapper around the
1281 // ACTION_DIAL intent, which is available to any app since it puts up
1282 // the UI before it does anything.
1283
Malcolm Chend965c8b2018-02-28 15:00:40 -08001284 final long identity = Binder.clearCallingIdentity();
1285 try {
1286 String url = createTelUrl(number);
1287 if (url == null) {
1288 return;
1289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290
Malcolm Chend965c8b2018-02-28 15:00:40 -08001291 // PENDING: should we just silently fail if phone is offhook or ringing?
1292 PhoneConstants.State state = mCM.getState(subId);
1293 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1294 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1295 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1296 mApp.startActivity(intent);
1297 }
1298 } finally {
1299 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300 }
1301 }
1302
1303 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001304 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001305 }
1306
Wink Savilleb564aae2014-10-23 10:18:09 -07001307 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 if (DBG) log("call: " + number);
1309
1310 // This is just a wrapper around the ACTION_CALL intent, but we still
1311 // need to do a permission check since we're calling startActivity()
1312 // from the context of the phone app.
1313 enforceCallPermission();
1314
1315 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1316 != AppOpsManager.MODE_ALLOWED) {
1317 return;
1318 }
1319
Malcolm Chend965c8b2018-02-28 15:00:40 -08001320 final long identity = Binder.clearCallingIdentity();
1321 try {
1322 String url = createTelUrl(number);
1323 if (url == null) {
1324 return;
1325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326
Malcolm Chend965c8b2018-02-28 15:00:40 -08001327 boolean isValid = false;
1328 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1329 if (slist != null) {
1330 for (SubscriptionInfo subInfoRecord : slist) {
1331 if (subInfoRecord.getSubscriptionId() == subId) {
1332 isValid = true;
1333 break;
1334 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001335 }
Wink Saville08874612014-08-31 19:19:58 -07001336 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001337 if (!isValid) {
1338 return;
1339 }
Wink Saville08874612014-08-31 19:19:58 -07001340
Malcolm Chend965c8b2018-02-28 15:00:40 -08001341 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1342 intent.putExtra(SUBSCRIPTION_KEY, subId);
1343 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1344 mApp.startActivity(intent);
1345 } finally {
1346 Binder.restoreCallingIdentity(identity);
1347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001348 }
1349
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001350 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001351 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001352 }
1353
Wink Savilleb564aae2014-10-23 10:18:09 -07001354 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001355 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001356 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1357 }
1358
1359 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001360 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001361 }
1362
Wink Savilleb564aae2014-10-23 10:18:09 -07001363 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001364 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001365 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1366 }
1367
1368 /** {@hide} */
1369 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001370 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001371 }
1372
Wink Savilleb564aae2014-10-23 10:18:09 -07001373 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001375
1376 final long identity = Binder.clearCallingIdentity();
1377 try {
1378 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1379 checkSimPin.start();
1380 return checkSimPin.unlockSim(null, pin);
1381 } finally {
1382 Binder.restoreCallingIdentity(identity);
1383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 }
1385
Wink Saville9de0f752013-10-22 19:04:03 -07001386 /** {@hide} */
1387 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001388 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001389 }
1390
Wink Savilleb564aae2014-10-23 10:18:09 -07001391 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001393
1394 final long identity = Binder.clearCallingIdentity();
1395 try {
1396 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1397 checkSimPuk.start();
1398 return checkSimPuk.unlockSim(puk, pin);
1399 } finally {
1400 Binder.restoreCallingIdentity(identity);
1401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001402 }
1403
1404 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001405 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 * a synchronous one.
1407 */
1408 private static class UnlockSim extends Thread {
1409
1410 private final IccCard mSimCard;
1411
1412 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001413 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1414 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415
1416 // For replies from SimCard interface
1417 private Handler mHandler;
1418
1419 // For async handler to identify request type
1420 private static final int SUPPLY_PIN_COMPLETE = 100;
1421
1422 public UnlockSim(IccCard simCard) {
1423 mSimCard = simCard;
1424 }
1425
1426 @Override
1427 public void run() {
1428 Looper.prepare();
1429 synchronized (UnlockSim.this) {
1430 mHandler = new Handler() {
1431 @Override
1432 public void handleMessage(Message msg) {
1433 AsyncResult ar = (AsyncResult) msg.obj;
1434 switch (msg.what) {
1435 case SUPPLY_PIN_COMPLETE:
1436 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1437 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001438 mRetryCount = msg.arg1;
1439 if (ar.exception != null) {
1440 if (ar.exception instanceof CommandException &&
1441 ((CommandException)(ar.exception)).getCommandError()
1442 == CommandException.Error.PASSWORD_INCORRECT) {
1443 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1444 } else {
1445 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1446 }
1447 } else {
1448 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 mDone = true;
1451 UnlockSim.this.notifyAll();
1452 }
1453 break;
1454 }
1455 }
1456 };
1457 UnlockSim.this.notifyAll();
1458 }
1459 Looper.loop();
1460 }
1461
1462 /*
1463 * Use PIN or PUK to unlock SIM card
1464 *
1465 * If PUK is null, unlock SIM card with PIN
1466 *
1467 * If PUK is not null, unlock SIM card with PUK and set PIN code
1468 */
Wink Saville9de0f752013-10-22 19:04:03 -07001469 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001470
1471 while (mHandler == null) {
1472 try {
1473 wait();
1474 } catch (InterruptedException e) {
1475 Thread.currentThread().interrupt();
1476 }
1477 }
1478 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1479
1480 if (puk == null) {
1481 mSimCard.supplyPin(pin, callback);
1482 } else {
1483 mSimCard.supplyPuk(puk, pin, callback);
1484 }
1485
1486 while (!mDone) {
1487 try {
1488 Log.d(LOG_TAG, "wait for done");
1489 wait();
1490 } catch (InterruptedException e) {
1491 // Restore the interrupted status
1492 Thread.currentThread().interrupt();
1493 }
1494 }
1495 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001496 int[] resultArray = new int[2];
1497 resultArray[0] = mResult;
1498 resultArray[1] = mRetryCount;
1499 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001500 }
1501 }
1502
1503 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001504 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001505
1506 }
1507
Wink Savilleb564aae2014-10-23 10:18:09 -07001508 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 // No permission check needed here: this call is harmless, and it's
1510 // needed for the ServiceState.requestStateUpdate() call (which is
1511 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001512 final long identity = Binder.clearCallingIdentity();
1513 try {
1514 final Phone phone = getPhone(subId);
1515 if (phone != null) {
1516 phone.updateServiceLocation();
1517 }
1518 } finally {
1519 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001521 }
1522
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001523 @Override
1524 public boolean isRadioOn(String callingPackage) {
1525 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001526 }
1527
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001528 @Override
1529 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001531 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001532 return false;
1533 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001534
1535 final long identity = Binder.clearCallingIdentity();
1536 try {
1537 return isRadioOnForSubscriber(subId);
1538 } finally {
1539 Binder.restoreCallingIdentity(identity);
1540 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001541 }
1542
1543 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001544 final long identity = Binder.clearCallingIdentity();
1545 try {
1546 final Phone phone = getPhone(subId);
1547 if (phone != null) {
1548 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1549 } else {
1550 return false;
1551 }
1552 } finally {
1553 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 }
1556
1557 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001558 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 }
Wink Saville36469e72014-06-11 15:17:00 -07001560
Wink Savilleb564aae2014-10-23 10:18:09 -07001561 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001562 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001563
1564 final long identity = Binder.clearCallingIdentity();
1565 try {
1566 final Phone phone = getPhone(subId);
1567 if (phone != null) {
1568 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1569 }
1570 } finally {
1571 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001572 }
Wink Saville36469e72014-06-11 15:17:00 -07001573 }
1574
1575 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001576 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001577 }
1578
Wink Savilleb564aae2014-10-23 10:18:09 -07001579 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001580 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001581
1582 final long identity = Binder.clearCallingIdentity();
1583 try {
1584 final Phone phone = getPhone(subId);
1585 if (phone == null) {
1586 return false;
1587 }
1588 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1589 toggleRadioOnOffForSubscriber(subId);
1590 }
1591 return true;
1592 } finally {
1593 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 }
Wink Saville36469e72014-06-11 15:17:00 -07001596
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001597 public boolean needMobileRadioShutdown() {
1598 /*
1599 * If any of the Radios are available, it will need to be
1600 * shutdown. So return true if any Radio is available.
1601 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001602 final long identity = Binder.clearCallingIdentity();
1603 try {
1604 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1605 Phone phone = PhoneFactory.getPhone(i);
1606 if (phone != null && phone.isRadioAvailable()) return true;
1607 }
1608 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1609 return false;
1610 } finally {
1611 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001612 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001613 }
1614
Malcolm Chend965c8b2018-02-28 15:00:40 -08001615 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001616 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001617 enforceModifyPermission();
1618
1619 final long identity = Binder.clearCallingIdentity();
1620 try {
1621 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1622 logv("Shutting down Phone " + i);
1623 shutdownRadioUsingPhoneId(i);
1624 }
1625 } finally {
1626 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001627 }
1628 }
1629
1630 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001631 Phone phone = PhoneFactory.getPhone(phoneId);
1632 if (phone != null && phone.isRadioAvailable()) {
1633 phone.shutdownRadio();
1634 }
1635 }
1636
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001637 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001638 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001639
1640 final long identity = Binder.clearCallingIdentity();
1641 try {
1642 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1643 if (defaultPhone != null) {
1644 defaultPhone.setRadioPower(turnOn);
1645 return true;
1646 } else {
1647 loge("There's no default phone.");
1648 return false;
1649 }
1650 } finally {
1651 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001652 }
Wink Saville36469e72014-06-11 15:17:00 -07001653 }
1654
Wink Savilleb564aae2014-10-23 10:18:09 -07001655 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001657
1658 final long identity = Binder.clearCallingIdentity();
1659 try {
1660 final Phone phone = getPhone(subId);
1661 if (phone != null) {
1662 phone.setRadioPower(turnOn);
1663 return true;
1664 } else {
1665 return false;
1666 }
1667 } finally {
1668 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670 }
1671
Wink Saville36469e72014-06-11 15:17:00 -07001672 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001673 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 public boolean enableDataConnectivity() {
1675 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001676
1677 final long identity = Binder.clearCallingIdentity();
1678 try {
1679 int subId = mSubscriptionController.getDefaultDataSubId();
1680 final Phone phone = getPhone(subId);
1681 if (phone != null) {
1682 phone.setUserDataEnabled(true);
1683 return true;
1684 } else {
1685 return false;
1686 }
1687 } finally {
1688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 }
1691
Wink Saville36469e72014-06-11 15:17:00 -07001692 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 public boolean disableDataConnectivity() {
1695 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001696
1697 final long identity = Binder.clearCallingIdentity();
1698 try {
1699 int subId = mSubscriptionController.getDefaultDataSubId();
1700 final Phone phone = getPhone(subId);
1701 if (phone != null) {
1702 phone.setUserDataEnabled(false);
1703 return true;
1704 } else {
1705 return false;
1706 }
1707 } finally {
1708 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001709 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 }
1711
Sanket Padawe356d7632015-06-22 14:03:32 -07001712 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001713 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
1718 return phone.isDataAllowed();
1719 } else {
1720 return false;
1721 }
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
1727 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001728 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001729 }
1730
pkanwarae03a6b2016-11-06 20:37:09 -08001731 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001732 enforceCallPermission();
1733
1734 final long identity = Binder.clearCallingIdentity();
1735 try {
1736 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1737 return;
1738 }
1739 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1740 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1741 } finally {
1742 Binder.restoreCallingIdentity(identity);
1743 }
pkanwar32d516d2016-10-14 19:37:38 -07001744 };
1745
Wink Savilleb564aae2014-10-23 10:18:09 -07001746 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001748
1749 final long identity = Binder.clearCallingIdentity();
1750 try {
1751 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1752 return false;
1753 }
1754 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1755 } finally {
1756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 }
1759
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001761 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001762 }
1763
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001764 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001765 final long identity = Binder.clearCallingIdentity();
1766 try {
1767 Phone phone = PhoneFactory.getPhone(slotIndex);
1768 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1769 PhoneConstantConversions.convertCallState(phone.getState());
1770 } finally {
1771 Binder.restoreCallingIdentity(identity);
1772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 }
1774
Sanket Padawe356d7632015-06-22 14:03:32 -07001775 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001777 final long identity = Binder.clearCallingIdentity();
1778 try {
1779 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1780 if (phone != null) {
1781 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1782 } else {
1783 return PhoneConstantConversions.convertDataState(
1784 PhoneConstants.DataState.DISCONNECTED);
1785 }
1786 } finally {
1787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
1790
Sanket Padawe356d7632015-06-22 14:03:32 -07001791 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001793 final long identity = Binder.clearCallingIdentity();
1794 try {
1795 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1796 if (phone != null) {
1797 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1798 } else {
1799 return TelephonyManager.DATA_ACTIVITY_NONE;
1800 }
1801 } finally {
1802 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001803 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 }
1805
1806 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001807 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001808 mPhone.getContext().getSystemService(AppOpsManager.class)
1809 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001810 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001811 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001812 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 }
1814
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001815 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001816 final long identity = Binder.clearCallingIdentity();
1817 try {
1818 if (DBG_LOC) log("getCellLocation: is active user");
1819 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001820 int subId = mSubscriptionController.getDefaultDataSubId();
1821 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1822 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001823 return data;
1824 } finally {
1825 Binder.restoreCallingIdentity(identity);
1826 }
Svetoslav64fad262015-04-14 14:35:21 -07001827 }
1828
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001830 public String getNetworkCountryIsoForPhone(int phoneId) {
1831 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1832 // registered cell info, so return a NULL country instead.
1833 final long identity = Binder.clearCallingIdentity();
1834 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001835 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1836 // Get default phone in this case.
1837 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1838 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001839 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001840 // Todo: fix this when we can get the actual cellular network info when the device
1841 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001842 if (TelephonyManager.NETWORK_TYPE_IWLAN
1843 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1844 return "";
1845 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001846 Phone phone = PhoneFactory.getPhone(phoneId);
1847 if (phone != null) {
1848 ServiceStateTracker sst = phone.getServiceStateTracker();
1849 if (sst != null) {
1850 LocaleTracker lt = sst.getLocaleTracker();
1851 if (lt != null) {
1852 return lt.getCurrentCountry();
1853 }
1854 }
1855 }
1856 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001857 } finally {
1858 Binder.restoreCallingIdentity(identity);
1859 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001860 }
1861
1862 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001864 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001865 }
1866
Sanket Padawe356d7632015-06-22 14:03:32 -07001867 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001868 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 mApp.enforceCallingOrSelfPermission(
1870 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001871
1872 final long identity = Binder.clearCallingIdentity();
1873 try {
1874 final Phone phone = getPhone(subId);
1875 if (phone != null) {
1876 phone.enableLocationUpdates();
1877 }
1878 } finally {
1879 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 }
1882
1883 @Override
1884 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001885 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001886 }
1887
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001889 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 mApp.enforceCallingOrSelfPermission(
1891 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001892
1893 final long identity = Binder.clearCallingIdentity();
1894 try {
1895 final Phone phone = getPhone(subId);
1896 if (phone != null) {
1897 phone.disableLocationUpdates();
1898 }
1899 } finally {
1900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 }
1903
Nathan Harold31d7ff32018-10-15 20:20:30 -07001904 /**
1905 * Returns the target SDK version number for a given package name.
1906 *
1907 * @return target SDK if the package is found or INT_MAX.
1908 */
1909 private int getTargetSdk(String packageName) {
1910 try {
1911 final ApplicationInfo ai =
1912 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1913 if (ai != null) return ai.targetSdkVersion;
1914 } catch (PackageManager.NameNotFoundException unexpected) {
1915 }
1916 return Integer.MAX_VALUE;
1917 }
1918
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 @Override
1920 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001921 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1922 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001923 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1924 throw new SecurityException(
1925 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1926 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001927
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001928 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1929 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1930 return null;
1931 }
Svetoslav64fad262015-04-14 14:35:21 -07001932
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001933 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934
Nathan Haroldf180aac2018-06-01 18:43:55 -07001935 List<CellInfo> info = getAllCellInfo(callingPackage);
1936 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937
Nathan Haroldf180aac2018-06-01 18:43:55 -07001938 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1939 for (CellInfo ci : info) {
1940 if (ci instanceof CellInfoGsm) {
1941 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1942 } else if (ci instanceof CellInfoWcdma) {
1943 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001946 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 }
1948
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001949 private List<CellInfo> getCachedCellInfo() {
1950 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1951 for (Phone phone : PhoneFactory.getPhones()) {
1952 List<CellInfo> info = phone.getAllCellInfo();
1953 if (info != null) cellInfos.addAll(info);
1954 }
1955 return cellInfos;
1956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957
1958 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001959 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001960 mPhone.getContext().getSystemService(AppOpsManager.class)
1961 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001962 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001963 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001964 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001965 }
1966
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001967 final int targetSdk = getTargetSdk(callingPackage);
1968 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1969 return getCachedCellInfo();
1970 }
1971
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001972 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001973 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001974 final long identity = Binder.clearCallingIdentity();
1975 try {
1976 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1977 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001978 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001979 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001980 if (info != null) cellInfos.addAll(info);
1981 }
1982 return cellInfos;
1983 } finally {
1984 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001985 }
1986 }
1987
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001988 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001989 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
1990 requestCellInfoUpdateInternal(
1991 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
1992 }
1993
1994 @Override
1995 public void requestCellInfoUpdateWithWorkSource(
1996 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
1997 enforceModifyPermission();
1998 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
1999 }
2000
2001 private void requestCellInfoUpdateInternal(
2002 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2003 mPhone.getContext().getSystemService(AppOpsManager.class)
2004 .checkPackage(Binder.getCallingUid(), callingPackage);
2005 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
2006 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
2007 return;
2008 }
2009
2010 final Phone phone = getPhone(subId);
2011 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2012
2013 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2014 }
2015
2016 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002018 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002019 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002020
2021 final long identity = Binder.clearCallingIdentity();
2022 try {
2023 mPhone.setCellInfoListRate(rateInMillis, workSource);
2024 } finally {
2025 Binder.restoreCallingIdentity(identity);
2026 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 }
2028
Shishir Agrawala9f32182016-04-12 12:00:16 -07002029 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002030 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002031 Phone phone = PhoneFactory.getPhone(slotIndex);
2032 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002033 return null;
2034 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002035 int subId = phone.getSubId();
2036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2037 mApp, subId, callingPackage, "getImeiForSlot")) {
2038 return null;
2039 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002040
2041 final long identity = Binder.clearCallingIdentity();
2042 try {
2043 return phone.getImei();
2044 } finally {
2045 Binder.restoreCallingIdentity(identity);
2046 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002047 }
2048
2049 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002050 public String getTypeAllocationCodeForSlot(int slotIndex) {
2051 Phone phone = PhoneFactory.getPhone(slotIndex);
2052 String tac = null;
2053 if (phone != null) {
2054 String imei = phone.getImei();
2055 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2056 }
2057 return tac;
2058 }
2059
2060 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002061 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002062 Phone phone = PhoneFactory.getPhone(slotIndex);
2063 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002064 return null;
2065 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002066 int subId = phone.getSubId();
2067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2068 mApp, subId, callingPackage, "getMeidForSlot")) {
2069 return null;
2070 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002071
2072 final long identity = Binder.clearCallingIdentity();
2073 try {
2074 return phone.getMeid();
2075 } finally {
2076 Binder.restoreCallingIdentity(identity);
2077 }
Jack Yu2af8d712017-03-15 17:14:14 -07002078 }
2079
2080 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002081 public String getManufacturerCodeForSlot(int slotIndex) {
2082 Phone phone = PhoneFactory.getPhone(slotIndex);
2083 String manufacturerCode = null;
2084 if (phone != null) {
2085 String meid = phone.getMeid();
2086 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2087 }
2088 return manufacturerCode;
2089 }
2090
2091 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002092 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002093 Phone phone = PhoneFactory.getPhone(slotIndex);
2094 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002095 return null;
2096 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002097 int subId = phone.getSubId();
2098 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2099 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2100 return null;
2101 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002102
2103 final long identity = Binder.clearCallingIdentity();
2104 try {
2105 return phone.getDeviceSvn();
2106 } finally {
2107 Binder.restoreCallingIdentity(identity);
2108 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002109 }
2110
fionaxu43304da2017-11-27 22:51:16 -08002111 @Override
2112 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002113 final long identity = Binder.clearCallingIdentity();
2114 try {
2115 final Phone phone = getPhone(subId);
2116 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2117 } finally {
2118 Binder.restoreCallingIdentity(identity);
2119 }
fionaxu43304da2017-11-27 22:51:16 -08002120 }
2121
2122 @Override
2123 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002124 final long identity = Binder.clearCallingIdentity();
2125 try {
2126 final Phone phone = getPhone(subId);
2127 return phone == null ? null : phone.getCarrierName();
2128 } finally {
2129 Binder.restoreCallingIdentity(identity);
2130 }
fionaxu43304da2017-11-27 22:51:16 -08002131 }
2132
calvinpaneed9ae82018-11-01 19:43:06 +08002133 @Override
2134 public int getSubscriptionMNOCarrierId(int subId) {
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 final Phone phone = getPhone(subId);
2138 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId();
2139 } finally {
2140 Binder.restoreCallingIdentity(identity);
2141 }
2142 }
2143
chen xuc93cc282018-11-04 17:17:00 -08002144 @Override
2145 public int getSubscriptionPreciseCarrierId(int subId) {
2146 final long identity = Binder.clearCallingIdentity();
2147 try {
2148 final Phone phone = getPhone(subId);
2149 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2150 : phone.getPreciseCarrierId();
2151 } finally {
2152 Binder.restoreCallingIdentity(identity);
2153 }
2154 }
2155
2156 @Override
2157 public String getSubscriptionPreciseCarrierName(int subId) {
2158 final long identity = Binder.clearCallingIdentity();
2159 try {
2160 final Phone phone = getPhone(subId);
2161 return phone == null ? null : phone.getPreciseCarrierName();
2162 } finally {
2163 Binder.restoreCallingIdentity(identity);
2164 }
2165 }
2166
chen xu02581692018-11-11 19:03:44 -08002167 @Override
2168 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc) {
2169 final Phone phone = PhoneFactory.getPhone(slotIndex);
2170 if (phone == null) {
2171 return TelephonyManager.UNKNOWN_CARRIER_ID;
2172 }
2173 final long identity = Binder.clearCallingIdentity();
2174 try {
2175 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2176 } finally {
2177 Binder.restoreCallingIdentity(identity);
2178 }
2179 }
2180
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 //
2182 // Internal helper methods.
2183 //
2184
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002185 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002186 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2187 *
2188 * @throws SecurityException if the caller does not have the required permission
2189 */
2190 private void enforceModifyPermission() {
2191 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2192 }
2193
2194 /**
2195 * Make sure the caller has the CALL_PHONE permission.
2196 *
2197 * @throws SecurityException if the caller does not have the required permission
2198 */
2199 private void enforceCallPermission() {
2200 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2201 }
2202
Stuart Scott8eef64f2015-04-08 15:13:54 -07002203 private void enforceConnectivityInternalPermission() {
2204 mApp.enforceCallingOrSelfPermission(
2205 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2206 "ConnectivityService");
2207 }
2208
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 private String createTelUrl(String number) {
2210 if (TextUtils.isEmpty(number)) {
2211 return null;
2212 }
2213
Jake Hambye994d462014-02-03 13:10:13 -08002214 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 }
2216
Ihab Awadf9e92732013-12-05 18:02:52 -08002217 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2219 }
2220
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002221 private static void logv(String msg) {
2222 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2223 }
2224
Ihab Awadf9e92732013-12-05 18:02:52 -08002225 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002226 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2227 }
2228
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002229 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002231 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002232 }
2233
Sanket Padawe356d7632015-06-22 14:03:32 -07002234 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002235 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002236 final long identity = Binder.clearCallingIdentity();
2237 try {
2238 final Phone phone = PhoneFactory.getPhone(slotIndex);
2239 if (phone == null) {
2240 return PhoneConstants.PHONE_TYPE_NONE;
2241 } else {
2242 return phone.getPhoneType();
2243 }
2244 } finally {
2245 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 }
2248
2249 /**
2250 * Returns the CDMA ERI icon index to display
2251 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002252 @Override
2253 public int getCdmaEriIconIndex(String callingPackage) {
2254 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002255 }
2256
Sanket Padawe356d7632015-06-22 14:03:32 -07002257 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002258 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002260 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002261 return -1;
2262 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002263
2264 final long identity = Binder.clearCallingIdentity();
2265 try {
2266 final Phone phone = getPhone(subId);
2267 if (phone != null) {
2268 return phone.getCdmaEriIconIndex();
2269 } else {
2270 return -1;
2271 }
2272 } finally {
2273 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 }
2276
2277 /**
2278 * Returns the CDMA ERI icon mode,
2279 * 0 - ON
2280 * 1 - FLASHING
2281 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002282 @Override
2283 public int getCdmaEriIconMode(String callingPackage) {
2284 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002285 }
2286
Sanket Padawe356d7632015-06-22 14:03:32 -07002287 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002288 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002290 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002291 return -1;
2292 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002293
2294 final long identity = Binder.clearCallingIdentity();
2295 try {
2296 final Phone phone = getPhone(subId);
2297 if (phone != null) {
2298 return phone.getCdmaEriIconMode();
2299 } else {
2300 return -1;
2301 }
2302 } finally {
2303 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002304 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002305 }
2306
2307 /**
2308 * Returns the CDMA ERI text,
2309 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002310 @Override
2311 public String getCdmaEriText(String callingPackage) {
2312 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002313 }
2314
Sanket Padawe356d7632015-06-22 14:03:32 -07002315 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002316 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002318 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002319 return null;
2320 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002321
2322 final long identity = Binder.clearCallingIdentity();
2323 try {
2324 final Phone phone = getPhone(subId);
2325 if (phone != null) {
2326 return phone.getCdmaEriText();
2327 } else {
2328 return null;
2329 }
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 }
2334
2335 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002336 * Returns the CDMA MDN.
2337 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002338 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002339 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2341 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002342
2343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 final Phone phone = getPhone(subId);
2346 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2347 return phone.getLine1Number();
2348 } else {
2349 return null;
2350 }
2351 } finally {
2352 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002353 }
2354 }
2355
2356 /**
2357 * Returns the CDMA MIN.
2358 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002359 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002360 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2362 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002363
2364 final long identity = Binder.clearCallingIdentity();
2365 try {
2366 final Phone phone = getPhone(subId);
2367 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2368 return phone.getCdmaMin();
2369 } else {
2370 return null;
2371 }
2372 } finally {
2373 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002374 }
2375 }
2376
2377 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 * Returns true if CDMA provisioning needs to run.
2379 */
2380 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002381 final long identity = Binder.clearCallingIdentity();
2382 try {
2383 return mPhone.needsOtaServiceProvisioning();
2384 } finally {
2385 Binder.restoreCallingIdentity(identity);
2386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 }
2388
2389 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002390 * Sets the voice mail number of a given subId.
2391 */
2392 @Override
2393 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002394 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002395
2396 final long identity = Binder.clearCallingIdentity();
2397 try {
2398 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2399 new Pair<String, String>(alphaTag, number), new Integer(subId));
2400 return success;
2401 } finally {
2402 Binder.restoreCallingIdentity(identity);
2403 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002404 }
2405
Ta-wei Yen87c49842016-05-13 21:19:52 -07002406 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002407 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2408 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2409 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2410 if (!TextUtils.equals(callingPackage, systemDialer)) {
2411 throw new SecurityException("caller must be system dialer");
2412 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002413
2414 final long identity = Binder.clearCallingIdentity();
2415 try {
2416 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2417 if (phoneAccountHandle == null) {
2418 return null;
2419 }
2420 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002423 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002424 }
2425
2426 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002427 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002428 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002430 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002431 return null;
2432 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002433
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002434 final long identity = Binder.clearCallingIdentity();
2435 try {
2436 return RemoteVvmTaskManager
2437 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2438 } finally {
2439 Binder.restoreCallingIdentity(identity);
2440 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002441 }
2442
2443 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002444 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2445 VisualVoicemailSmsFilterSettings settings) {
2446 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002447
2448 final long identity = Binder.clearCallingIdentity();
2449 try {
2450 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2451 mPhone.getContext(), callingPackage, subId, settings);
2452 } finally {
2453 Binder.restoreCallingIdentity(identity);
2454 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002455 }
2456
2457 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002458 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2459 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002460
2461 final long identity = Binder.clearCallingIdentity();
2462 try {
2463 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2464 mPhone.getContext(), callingPackage, subId);
2465 } finally {
2466 Binder.restoreCallingIdentity(identity);
2467 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002468 }
2469
2470 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002471 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2472 String callingPackage, int subId) {
2473 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002474
2475 final long identity = Binder.clearCallingIdentity();
2476 try {
2477 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2478 mPhone.getContext(), callingPackage, subId);
2479 } finally {
2480 Binder.restoreCallingIdentity(identity);
2481 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002482 }
2483
2484 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002485 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002486 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002487
2488 final long identity = Binder.clearCallingIdentity();
2489 try {
2490 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2491 mPhone.getContext(), subId);
2492 } finally {
2493 Binder.restoreCallingIdentity(identity);
2494 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002495 }
2496
2497 @Override
2498 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2499 String number, int port, String text, PendingIntent sentIntent) {
2500 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002501 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002502 enforceSendSmsPermission();
2503 // Make the calls as the phone process.
2504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2507 if (port == 0) {
2508 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2509 sentIntent, null, false);
2510 } else {
2511 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2512 smsManager.sendDataMessageWithSelfPermissions(number, null,
2513 (short) port, data, sentIntent, null);
2514 }
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
2517 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002518 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002519 /**
fionaxu0152e512016-11-14 13:36:14 -08002520 * Sets the voice activation state of a given subId.
2521 */
2522 @Override
2523 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2525 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002526
2527 final long identity = Binder.clearCallingIdentity();
2528 try {
2529 final Phone phone = getPhone(subId);
2530 if (phone != null) {
2531 phone.setVoiceActivationState(activationState);
2532 } else {
2533 loge("setVoiceActivationState fails with invalid subId: " + subId);
2534 }
2535 } finally {
2536 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002537 }
2538 }
2539
2540 /**
2541 * Sets the data activation state of a given subId.
2542 */
2543 @Override
2544 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2546 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002547
2548 final long identity = Binder.clearCallingIdentity();
2549 try {
2550 final Phone phone = getPhone(subId);
2551 if (phone != null) {
2552 phone.setDataActivationState(activationState);
2553 } else {
2554 loge("setVoiceActivationState fails with invalid subId: " + subId);
2555 }
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002558 }
2559 }
2560
2561 /**
2562 * Returns the voice activation state of a given subId.
2563 */
2564 @Override
2565 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002566 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002567
fionaxu0152e512016-11-14 13:36:14 -08002568 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 if (phone != null) {
2572 return phone.getVoiceActivationState();
2573 } else {
2574 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2575 }
2576 } finally {
2577 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002578 }
2579 }
2580
2581 /**
2582 * Returns the data activation state of a given subId.
2583 */
2584 @Override
2585 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002586 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002587
fionaxu0152e512016-11-14 13:36:14 -08002588 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002589 final long identity = Binder.clearCallingIdentity();
2590 try {
2591 if (phone != null) {
2592 return phone.getDataActivationState();
2593 } else {
2594 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2595 }
2596 } finally {
2597 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002598 }
2599 }
2600
2601 /**
Wink Saville36469e72014-06-11 15:17:00 -07002602 * Returns the unread count of voicemails for a subId
2603 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002604 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002605 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2606 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2607 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2608 return 0;
2609 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002610 final long identity = Binder.clearCallingIdentity();
2611 try {
2612 final Phone phone = getPhone(subId);
2613 if (phone != null) {
2614 return phone.getVoiceMessageCount();
2615 } else {
2616 return 0;
2617 }
2618 } finally {
2619 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002621 }
2622
2623 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002624 * returns true, if the device is in a state where both voice and data
2625 * are supported simultaneously. This can change based on location or network condition.
2626 */
2627 @Override
2628 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002629 final long identity = Binder.clearCallingIdentity();
2630 try {
2631 final Phone phone = getPhone(subId);
2632 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002636 }
2637
2638 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002639 * Send the dialer code if called from the current default dialer or the caller has
2640 * carrier privilege.
2641 * @param inputCode The dialer code to send
2642 */
2643 @Override
2644 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2645 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2646 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2647 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002648 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2649 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002650 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002651
2652 final long identity = Binder.clearCallingIdentity();
2653 try {
2654 mPhone.sendDialerSpecialCode(inputCode);
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
2657 }
fionaxu235cc5e2017-03-06 22:25:57 -08002658 }
2659
2660 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002661 * Returns the data network type.
2662 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663 *
2664 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2665 */
2666 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002667 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 final Phone phone = getPhone(getDefaultSubscription());
2671 if (phone != null) {
2672 return phone.getServiceState().getDataNetworkType();
2673 } else {
2674 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2675 }
2676 } finally {
2677 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002678 }
Wink Saville36469e72014-06-11 15:17:00 -07002679 }
2680
Pengquan Meng0c05b502018-09-06 09:59:22 -07002681 @Override
2682 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002683 if (!isActiveSubscription(subId)) {
2684 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2685 }
2686
Pengquan Meng0c05b502018-09-06 09:59:22 -07002687 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2688 }
2689
Brad Ebinger4c460712018-10-01 10:40:55 -07002690 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002691 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2692 throws RemoteException {
2693 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002694 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2695 final long token = Binder.clearCallingIdentity();
2696 try {
2697 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2698 .addRegistrationCallbackForSubscription(c, subId);
2699 } finally {
2700 Binder.restoreCallingIdentity(token);
2701 }
2702 }
2703
2704 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002705 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2706 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002707 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2708 Binder.withCleanCallingIdentity(() ->
2709 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2710 .removeRegistrationCallbackForSubscription(c, subId));
2711 }
2712
2713 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002714 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2715 throws RemoteException {
2716 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002717 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2718 final long token = Binder.clearCallingIdentity();
2719 try {
2720 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2721 .addCapabilitiesCallbackForSubscription(c, subId);
2722 } finally {
2723 Binder.restoreCallingIdentity(token);
2724 }
2725 }
2726
2727 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002728 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2729 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002730 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2731 Binder.withCleanCallingIdentity(() ->
2732 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2733 .removeCapabilitiesCallbackForSubscription(c, subId));
2734 }
2735
2736 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002737 public boolean isCapable(int subId, int capability, int regTech) {
2738 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002739 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2740 final long token = Binder.clearCallingIdentity();
2741 try {
2742 return ImsManager.getInstance(mPhone.getContext(),
2743 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2744 } catch (ImsException e) {
2745 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2746 return false;
2747 } finally {
2748 Binder.restoreCallingIdentity(token);
2749 }
2750 }
2751
2752 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002753 public boolean isAvailable(int subId, int capability, int regTech) {
2754 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002755 final long token = Binder.clearCallingIdentity();
2756 try {
2757 Phone phone = getPhone(subId);
2758 if (phone == null) return false;
2759 return phone.isImsCapabilityAvailable(capability, regTech);
2760 } finally {
2761 Binder.restoreCallingIdentity(token);
2762 }
2763 }
2764
2765 @Override
2766 public boolean isAdvancedCallingSettingEnabled(int subId) {
2767 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2768 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2769 final long token = Binder.clearCallingIdentity();
2770 try {
2771 return ImsManager.getInstance(mPhone.getContext(),
2772 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2773 } finally {
2774 Binder.restoreCallingIdentity(token);
2775 }
2776 }
2777
2778 @Override
2779 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2781 "setAdvancedCallingSetting");
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2785 ImsManager.getInstance(mPhone.getContext(),
2786 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
2789 }
2790 }
2791
2792 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002793 public boolean isVtSettingEnabled(int subId) {
2794 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002795 final long identity = Binder.clearCallingIdentity();
2796 try {
2797 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2798 return ImsManager.getInstance(mPhone.getContext(),
2799 getSlotIndexOrException(subId)).isVtEnabledByUser();
2800 } finally {
2801 Binder.restoreCallingIdentity(identity);
2802 }
2803 }
2804
2805 @Override
2806 public void setVtSetting(int subId, boolean isEnabled) {
2807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2808 "setVtSetting");
2809 final long identity = Binder.clearCallingIdentity();
2810 try {
2811 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2812 ImsManager.getInstance(mPhone.getContext(),
2813 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
2816 }
2817 }
2818
2819 @Override
2820 public boolean isVoWiFiSettingEnabled(int subId) {
2821 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2825 return ImsManager.getInstance(mPhone.getContext(),
2826 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2827 } finally {
2828 Binder.restoreCallingIdentity(identity);
2829 }
2830 }
2831
2832 @Override
2833 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2835 "setVoWiFiSetting");
2836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2839 ImsManager.getInstance(mPhone.getContext(),
2840 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2841 } finally {
2842 Binder.restoreCallingIdentity(identity);
2843 }
2844 }
2845
2846 @Override
2847 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2848 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2849 final long identity = Binder.clearCallingIdentity();
2850 try {
2851 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2852 return ImsManager.getInstance(mPhone.getContext(),
2853 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2854 } finally {
2855 Binder.restoreCallingIdentity(identity);
2856 }
2857 }
2858
2859 @Override
2860 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2862 "setVoWiFiRoamingSetting");
2863 final long identity = Binder.clearCallingIdentity();
2864 try {
2865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2866 ImsManager.getInstance(mPhone.getContext(),
2867 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2868 } finally {
2869 Binder.restoreCallingIdentity(identity);
2870 }
2871 }
2872
2873 @Override
2874 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2876 "setVoWiFiNonPersistent");
2877 final long identity = Binder.clearCallingIdentity();
2878 try {
2879 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2880 ImsManager.getInstance(mPhone.getContext(),
2881 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2882 } finally {
2883 Binder.restoreCallingIdentity(identity);
2884 }
2885 }
2886
2887 @Override
2888 public int getVoWiFiModeSetting(int subId) {
2889 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2893 return ImsManager.getInstance(mPhone.getContext(),
2894 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2895 } finally {
2896 Binder.restoreCallingIdentity(identity);
2897 }
2898 }
2899
2900 @Override
2901 public void setVoWiFiModeSetting(int subId, int mode) {
2902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2903 "setVoWiFiModeSetting");
2904 final long identity = Binder.clearCallingIdentity();
2905 try {
2906 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2907 ImsManager.getInstance(mPhone.getContext(),
2908 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
2911 }
2912 }
2913
2914 @Override
2915 public int getVoWiFiRoamingModeSetting(int subId) {
2916 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2917 final long identity = Binder.clearCallingIdentity();
2918 try {
2919 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2920 return ImsManager.getInstance(mPhone.getContext(),
2921 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2922 } finally {
2923 Binder.restoreCallingIdentity(identity);
2924 }
2925 }
2926
2927 @Override
2928 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2930 "setVoWiFiRoamingModeSetting");
2931 final long identity = Binder.clearCallingIdentity();
2932 try {
2933 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2934 ImsManager.getInstance(mPhone.getContext(),
2935 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2936 } finally {
2937 Binder.restoreCallingIdentity(identity);
2938 }
2939 }
2940
2941 @Override
2942 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2944 "setRttCapabilityEnabled");
2945 final long identity = Binder.clearCallingIdentity();
2946 try {
2947 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2948 ImsManager.getInstance(mPhone.getContext(),
2949 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
2952 }
2953 }
2954
2955 @Override
2956 public boolean isTtyOverVolteEnabled(int subId) {
2957 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2961 return ImsManager.getInstance(mPhone.getContext(),
2962 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
2965 }
2966 }
2967
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002968 @Override
2969 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2970 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
2971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2974 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2975 .getConfigInterface().addConfigCallback(callback);
2976 } catch (ImsException e) {
2977 throw new IllegalArgumentException(e.getMessage());
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
2981 }
2982
2983 @Override
2984 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2985 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
2986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2989 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2990 .getConfigInterface().removeConfigCallback(callback);
2991 } catch (ImsException e) {
2992 throw new IllegalArgumentException(e.getMessage());
2993 } finally {
2994 Binder.restoreCallingIdentity(identity);
2995 }
2996 }
2997
2998 @Override
2999 public int getImsProvisioningInt(int subId, int key) {
3000 enforceReadPrivilegedPermission("getImsProvisioningInt");
3001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3004 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3005 .getConfigInterface().getConfigInt(key);
3006 } catch (ImsException e) {
3007 throw new IllegalArgumentException(e.getMessage());
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
3011 }
3012
3013 @Override
3014 public String getImsProvisioningString(int subId, int key) {
3015 enforceReadPrivilegedPermission("getImsProvisioningString");
3016 final long identity = Binder.clearCallingIdentity();
3017 try {
3018 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3019 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3020 .getConfigInterface().getConfigString(key);
3021 } catch (ImsException e) {
3022 throw new IllegalArgumentException(e.getMessage());
3023 } finally {
3024 Binder.restoreCallingIdentity(identity);
3025 }
3026 }
3027
3028 @Override
3029 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3031 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003032 final long identity = Binder.clearCallingIdentity();
3033 try {
3034 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3035 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3036 .getConfigInterface().setConfig(key, value);
3037 } catch (ImsException e) {
3038 throw new IllegalArgumentException(e.getMessage());
3039 } finally {
3040 Binder.restoreCallingIdentity(identity);
3041 }
3042 }
3043
3044 @Override
3045 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3047 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3051 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3052 .getConfigInterface().setConfig(key, value);
3053 } catch (ImsException e) {
3054 throw new IllegalArgumentException(e.getMessage());
3055 } finally {
3056 Binder.restoreCallingIdentity(identity);
3057 }
3058 }
3059
Brad Ebinger4c460712018-10-01 10:40:55 -07003060 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3061 int slotId = SubscriptionManager.getSlotIndex(subId);
3062 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3063 throw new IllegalArgumentException("Invalid Subscription Id.");
3064 }
3065 return slotId;
3066 }
3067
Wink Saville36469e72014-06-11 15:17:00 -07003068 /**
3069 * Returns the network type for a subId
3070 */
3071 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003072 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003073 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003074 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003075 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3076 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003077
Malcolm Chend965c8b2018-02-28 15:00:40 -08003078 final long identity = Binder.clearCallingIdentity();
3079 try {
3080 final Phone phone = getPhone(subId);
3081 if (phone != null) {
3082 return phone.getServiceState().getDataNetworkType();
3083 } else {
3084 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3085 }
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003089 }
3090
3091 /**
3092 * Returns the data network type
3093 */
3094 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003095 public int getDataNetworkType(String callingPackage) {
3096 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003097 }
3098
3099 /**
3100 * Returns the data network type for a subId
3101 */
3102 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003103 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003104 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003105 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003106 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3107 }
3108
Malcolm Chend965c8b2018-02-28 15:00:40 -08003109 final long identity = Binder.clearCallingIdentity();
3110 try {
3111 final Phone phone = getPhone(subId);
3112 if (phone != null) {
3113 return phone.getServiceState().getDataNetworkType();
3114 } else {
3115 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3116 }
3117 } finally {
3118 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003120 }
3121
3122 /**
Wink Saville36469e72014-06-11 15:17:00 -07003123 * Returns the Voice network type for a subId
3124 */
3125 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003126 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003128 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003129 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3130 }
3131
Malcolm Chend965c8b2018-02-28 15:00:40 -08003132 final long identity = Binder.clearCallingIdentity();
3133 try {
3134 final Phone phone = getPhone(subId);
3135 if (phone != null) {
3136 return phone.getServiceState().getVoiceNetworkType();
3137 } else {
3138 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3139 }
3140 } finally {
3141 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143 }
3144
3145 /**
3146 * @return true if a ICC card is present
3147 */
3148 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003149 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003150 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3151 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003152 }
3153
3154 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003155 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003156 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003157 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003158 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003159 final long identity = Binder.clearCallingIdentity();
3160 try {
3161 final Phone phone = PhoneFactory.getPhone(slotIndex);
3162 if (phone != null) {
3163 return phone.getIccCard().hasIccCard();
3164 } else {
3165 return false;
3166 }
3167 } finally {
3168 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170 }
3171
3172 /**
3173 * Return if the current radio is LTE on CDMA. This
3174 * is a tri-state return value as for a period of time
3175 * the mode may be unknown.
3176 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003177 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003178 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003179 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003180 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003181 @Override
3182 public int getLteOnCdmaMode(String callingPackage) {
3183 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003184 }
3185
Sanket Padawe356d7632015-06-22 14:03:32 -07003186 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003187 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003189 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003190 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3191 }
3192
Malcolm Chend965c8b2018-02-28 15:00:40 -08003193 final long identity = Binder.clearCallingIdentity();
3194 try {
3195 final Phone phone = getPhone(subId);
3196 if (phone == null) {
3197 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3198 } else {
3199 return phone.getLteOnCdmaMode();
3200 }
3201 } finally {
3202 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003203 }
Wink Saville36469e72014-06-11 15:17:00 -07003204 }
3205
3206 public void setPhone(Phone phone) {
3207 mPhone = phone;
3208 }
3209
3210 /**
3211 * {@hide}
3212 * Returns Default subId, 0 in the case of single standby.
3213 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003214 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003215 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003216 }
3217
Shishir Agrawala9f32182016-04-12 12:00:16 -07003218 private int getSlotForDefaultSubscription() {
3219 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3220 }
3221
Wink Savilleb564aae2014-10-23 10:18:09 -07003222 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003223 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003224 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003225
Pengquan Meng466e2482018-09-21 15:54:48 -07003226 private boolean isActiveSubscription(int subId) {
3227 return mSubscriptionController.isActiveSubId(subId);
3228 }
3229
Ihab Awadf2177b72013-11-25 13:33:23 -08003230 /**
3231 * @see android.telephony.TelephonyManager.WifiCallingChoices
3232 */
3233 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003234 final long identity = Binder.clearCallingIdentity();
3235 try {
3236 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3237 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3238 getWhenToMakeWifiCallsDefaultPreference());
3239 } finally {
3240 Binder.restoreCallingIdentity(identity);
3241 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003242 }
3243
3244 /**
3245 * @see android.telephony.TelephonyManager.WifiCallingChoices
3246 */
3247 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003248 final long identity = Binder.clearCallingIdentity();
3249 try {
3250 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3251 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3252 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3253 } finally {
3254 Binder.restoreCallingIdentity(identity);
3255 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003256 }
3257
Sailesh Nepald1e68152013-12-12 19:08:02 -08003258 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003259 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003260 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003261 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003262
Shishir Agrawal566b7612013-10-28 14:41:00 -07003263 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003264 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3265 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3267 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003268 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003269
Malcolm Chend965c8b2018-02-28 15:00:40 -08003270 final long identity = Binder.clearCallingIdentity();
3271 try {
3272 if (TextUtils.equals(ISDR_AID, aid)) {
3273 // Only allows LPA to open logical channel to ISD-R.
3274 ComponentInfo bestComponent =
3275 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3276 if (bestComponent == null
3277 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3278 loge("The calling package is not allowed to access ISD-R.");
3279 throw new SecurityException(
3280 "The calling package is not allowed to access ISD-R.");
3281 }
Derek Tan740e1672017-06-27 14:56:27 -07003282 }
Derek Tan740e1672017-06-27 14:56:27 -07003283
Malcolm Chend965c8b2018-02-28 15:00:40 -08003284 if (DBG) {
3285 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3286 }
3287 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3288 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3289 if (DBG) log("iccOpenLogicalChannel: " + response);
3290 return response;
3291 } finally {
3292 Binder.restoreCallingIdentity(identity);
3293 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003294 }
3295
3296 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003297 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3299 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003300
Malcolm Chend965c8b2018-02-28 15:00:40 -08003301 final long identity = Binder.clearCallingIdentity();
3302 try {
3303 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3304 if (channel < 0) {
3305 return false;
3306 }
3307 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3308 if (DBG) log("iccCloseLogicalChannel: " + success);
3309 return success;
3310 } finally {
3311 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003312 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003313 }
3314
3315 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003316 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003317 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3319 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003320
Malcolm Chend965c8b2018-02-28 15:00:40 -08003321 final long identity = Binder.clearCallingIdentity();
3322 try {
3323 if (DBG) {
3324 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3325 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3326 + p3 + " data=" + data);
3327 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003328
Malcolm Chend965c8b2018-02-28 15:00:40 -08003329 if (channel < 0) {
3330 return "";
3331 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003332
Malcolm Chend965c8b2018-02-28 15:00:40 -08003333 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3334 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3335 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003336
Malcolm Chend965c8b2018-02-28 15:00:40 -08003337 // Append the returned status code to the end of the response payload.
3338 String s = Integer.toHexString(
3339 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3340 if (response.payload != null) {
3341 s = IccUtils.bytesToHexString(response.payload) + s;
3342 }
3343 return s;
3344 } finally {
3345 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003346 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003347 }
Jake Hambye994d462014-02-03 13:10:13 -08003348
Evan Charltonc66da362014-05-16 14:06:40 -07003349 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003350 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3351 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3353 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003354 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003355
Malcolm Chend965c8b2018-02-28 15:00:40 -08003356 final long identity = Binder.clearCallingIdentity();
3357 try {
3358 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3359 && TextUtils.equals(ISDR_AID, data)) {
3360 // Only allows LPA to select ISD-R.
3361 ComponentInfo bestComponent =
3362 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3363 if (bestComponent == null
3364 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3365 loge("The calling package is not allowed to select ISD-R.");
3366 throw new SecurityException(
3367 "The calling package is not allowed to select ISD-R.");
3368 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003369 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003370
Malcolm Chend965c8b2018-02-28 15:00:40 -08003371 if (DBG) {
3372 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3373 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3374 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003375
Malcolm Chend965c8b2018-02-28 15:00:40 -08003376 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3377 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3378 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003379
Malcolm Chend965c8b2018-02-28 15:00:40 -08003380 // Append the returned status code to the end of the response payload.
3381 String s = Integer.toHexString(
3382 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3383 if (response.payload != null) {
3384 s = IccUtils.bytesToHexString(response.payload) + s;
3385 }
3386 return s;
3387 } finally {
3388 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003389 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003390 }
3391
3392 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003393 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003394 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3396 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003397
Malcolm Chend965c8b2018-02-28 15:00:40 -08003398 final long identity = Binder.clearCallingIdentity();
3399 try {
3400 if (DBG) {
3401 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3402 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3403 }
3404
3405 IccIoResult response =
3406 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3407 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3408 subId);
3409
3410 if (DBG) {
3411 log("Exchange SIM_IO [R]" + response);
3412 }
3413
3414 byte[] result = null;
3415 int length = 2;
3416 if (response.payload != null) {
3417 length = 2 + response.payload.length;
3418 result = new byte[length];
3419 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3420 } else {
3421 result = new byte[length];
3422 }
3423
3424 result[length - 1] = (byte) response.sw2;
3425 result[length - 2] = (byte) response.sw1;
3426 return result;
3427 } finally {
3428 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003429 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003430 }
3431
Nathan Haroldb3014052017-01-25 15:57:32 -08003432 /**
3433 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3434 * on a particular subscription
3435 */
sqianb6e41952018-03-12 14:54:01 -07003436 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3438 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3439 return null;
3440 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003441
3442 final long identity = Binder.clearCallingIdentity();
3443 try {
3444 if (appType != TelephonyManager.APPTYPE_USIM
3445 && appType != TelephonyManager.APPTYPE_SIM) {
3446 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3447 return null;
3448 }
3449 Object response = sendRequest(
3450 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3451 if (response instanceof String[]) {
3452 return (String[]) response;
3453 }
3454 // Response is an Exception of some kind,
3455 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003456 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003457 } finally {
3458 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003459 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003460 }
3461
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003462 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003463 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3465 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003466
Malcolm Chend965c8b2018-02-28 15:00:40 -08003467 final long identity = Binder.clearCallingIdentity();
3468 try {
3469 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3470 if (response.payload == null) {
3471 return "";
3472 }
Evan Charltonc66da362014-05-16 14:06:40 -07003473
Malcolm Chend965c8b2018-02-28 15:00:40 -08003474 // Append the returned status code to the end of the response payload.
3475 String s = Integer.toHexString(
3476 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3477 s = IccUtils.bytesToHexString(response.payload) + s;
3478 return s;
3479 } finally {
3480 Binder.restoreCallingIdentity(identity);
3481 }
Evan Charltonc66da362014-05-16 14:06:40 -07003482 }
3483
Jake Hambye994d462014-02-03 13:10:13 -08003484 /**
3485 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3486 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3487 *
3488 * @param itemID the ID of the item to read
3489 * @return the NV item as a String, or null on error.
3490 */
3491 @Override
3492 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003493 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3495 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003496
3497 final long identity = Binder.clearCallingIdentity();
3498 try {
3499 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003500 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003501 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3502 return value;
3503 } finally {
3504 Binder.restoreCallingIdentity(identity);
3505 }
Jake Hambye994d462014-02-03 13:10:13 -08003506 }
3507
3508 /**
3509 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3510 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3511 *
3512 * @param itemID the ID of the item to read
3513 * @param itemValue the value to write, as a String
3514 * @return true on success; false on any failure
3515 */
3516 @Override
3517 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003518 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3520 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003521
3522 final long identity = Binder.clearCallingIdentity();
3523 try {
3524 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3525 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003526 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003527 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3528 return success;
3529 } finally {
3530 Binder.restoreCallingIdentity(identity);
3531 }
Jake Hambye994d462014-02-03 13:10:13 -08003532 }
3533
3534 /**
3535 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3536 * Used for device configuration by some CDMA operators.
3537 *
3538 * @param preferredRoamingList byte array containing the new PRL
3539 * @return true on success; false on any failure
3540 */
3541 @Override
3542 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3544 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003545
3546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3549 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3550 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3551 return success;
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
3554 }
Jake Hambye994d462014-02-03 13:10:13 -08003555 }
3556
3557 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003558 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003559 * Used for device configuration by some CDMA operators.
3560 *
chen xu1cc0abe2018-10-26 17:39:23 -07003561 * @param slotIndex - device slot.
3562 *
Jake Hambye994d462014-02-03 13:10:13 -08003563 * @return true on success; false on any failure
3564 */
3565 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003566 public boolean resetModemConfig(int slotIndex) {
3567 Phone phone = PhoneFactory.getPhone(slotIndex);
3568 if (phone != null) {
3569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3570 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003571
chen xu1cc0abe2018-10-26 17:39:23 -07003572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3575 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3576 return success;
3577 } finally {
3578 Binder.restoreCallingIdentity(identity);
3579 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003580 }
chen xu1cc0abe2018-10-26 17:39:23 -07003581 return false;
3582 }
3583
3584 /**
3585 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3586 *
3587 * @param slotIndex - device slot.
3588 *
3589 * @return true on success; false on any failure
3590 */
3591 @Override
3592 public boolean rebootModem(int slotIndex) {
3593 Phone phone = PhoneFactory.getPhone(slotIndex);
3594 if (phone != null) {
3595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3596 mApp, phone.getSubId(), "rebootModem");
3597
3598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3601 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3602 return success;
3603 } finally {
3604 Binder.restoreCallingIdentity(identity);
3605 }
3606 }
3607 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003608 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003609
Svet Ganovb320e182015-04-16 12:30:10 -07003610 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003612 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003613 return new String[0];
3614 }
3615
Malcolm Chend965c8b2018-02-28 15:00:40 -08003616 final long identity = Binder.clearCallingIdentity();
3617 try {
3618 return mPhone.getPcscfAddress(apnType);
3619 } finally {
3620 Binder.restoreCallingIdentity(identity);
3621 }
Wink Saville36469e72014-06-11 15:17:00 -07003622 }
3623
Brad Ebinger51f743a2017-01-23 13:50:20 -08003624 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003625 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3626 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003627 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003628 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003629 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003630
3631 final long identity = Binder.clearCallingIdentity();
3632 try {
3633 PhoneFactory.getImsResolver().enableIms(slotId);
3634 } finally {
3635 Binder.restoreCallingIdentity(identity);
3636 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003637 }
3638
3639 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003640 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3641 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003642 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003643 public void disableIms(int slotId) {
3644 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003645
3646 final long identity = Binder.clearCallingIdentity();
3647 try {
3648 PhoneFactory.getImsResolver().disableIms(slotId);
3649 } finally {
3650 Binder.restoreCallingIdentity(identity);
3651 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003652 }
3653
3654 /**
3655 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3656 * feature or {@link null} if the service is not available. If the feature is available, the
3657 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3658 */
3659 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003660 IImsServiceFeatureCallback callback) {
3661 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003662
3663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3666 } finally {
3667 Binder.restoreCallingIdentity(identity);
3668 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003669 }
3670
3671 /**
3672 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3673 * feature during emergency calling or {@link null} if the service is not available. If the
3674 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3675 * listener for feature updates.
3676 */
3677 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3678 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003679
3680 final long identity = Binder.clearCallingIdentity();
3681 try {
3682 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3683 } finally {
3684 Binder.restoreCallingIdentity(identity);
3685 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003686 }
3687
Brad Ebinger5f64b052017-12-14 14:26:15 -08003688 /**
3689 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3690 * specified.
3691 */
3692 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3693 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003694
3695 final long identity = Binder.clearCallingIdentity();
3696 try {
3697 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3698 } finally {
3699 Binder.restoreCallingIdentity(identity);
3700 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003701 }
3702
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003703 /**
3704 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3705 * specified.
3706 */
3707 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3708 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003709
3710 final long identity = Binder.clearCallingIdentity();
3711 try {
3712 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3713 } finally {
3714 Binder.restoreCallingIdentity(identity);
3715 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003716 }
3717
Brad Ebinger884c07b2018-02-15 16:17:40 -08003718 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003719 * Sets the ImsService Package Name that Telephony will bind to.
3720 *
3721 * @param slotId the slot ID that the ImsService should bind for.
3722 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3723 * ImsService is the device default ImsService.
3724 * @param packageName The package name of the application that contains the ImsService to bind
3725 * to.
3726 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3727 * @hide
3728 */
3729 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003730 int[] subIds = SubscriptionManager.getSubId(slotId);
3731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3732 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3733 "setImsService");
3734
Malcolm Chend965c8b2018-02-28 15:00:40 -08003735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3738 isCarrierImsService, packageName);
3739 } finally {
3740 Binder.restoreCallingIdentity(identity);
3741 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003742 }
3743
3744 /**
3745 * Return the ImsService configuration.
3746 *
3747 * @param slotId The slot that the ImsService is associated with.
3748 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3749 * the device default.
3750 * @return the package name of the ImsService configuration.
3751 */
3752 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003753 int[] subIds = SubscriptionManager.getSubId(slotId);
3754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3755 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3756 "getImsService");
3757
Malcolm Chend965c8b2018-02-28 15:00:40 -08003758 final long identity = Binder.clearCallingIdentity();
3759 try {
3760 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3761 isCarrierImsService);
3762 } finally {
3763 Binder.restoreCallingIdentity(identity);
3764 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003765 }
3766
Wink Saville36469e72014-06-11 15:17:00 -07003767 public void setImsRegistrationState(boolean registered) {
3768 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003769
3770 final long identity = Binder.clearCallingIdentity();
3771 try {
3772 mPhone.setImsRegistrationState(registered);
3773 } finally {
3774 Binder.restoreCallingIdentity(identity);
3775 }
Wink Saville36469e72014-06-11 15:17:00 -07003776 }
3777
3778 /**
Stuart Scott54788802015-03-30 13:18:01 -07003779 * Set the network selection mode to automatic.
3780 *
3781 */
3782 @Override
3783 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3785 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003786
Pengquan Meng466e2482018-09-21 15:54:48 -07003787 if (!isActiveSubscription(subId)) {
3788 return;
3789 }
3790
Malcolm Chend965c8b2018-02-28 15:00:40 -08003791 final long identity = Binder.clearCallingIdentity();
3792 try {
3793 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3794 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3795 } finally {
3796 Binder.restoreCallingIdentity(identity);
3797 }
Stuart Scott54788802015-03-30 13:18:01 -07003798 }
3799
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003800 /**
3801 * Ask the radio to connect to the input network and change selection mode to manual.
3802 *
3803 * @param subId the id of the subscription.
3804 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3805 * the operator to attach to.
3806 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3807 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3808 * normal network selection next time.
3809 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003810 */
3811 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003812 public boolean setNetworkSelectionModeManual(
3813 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3815 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003816
3817 if (!isActiveSubscription(subId)) {
3818 return false;
3819 }
3820
Malcolm Chend965c8b2018-02-28 15:00:40 -08003821 final long identity = Binder.clearCallingIdentity();
3822 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003823 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003824 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003825 if (DBG) {
3826 log("setNetworkSelectionModeManual: subId: " + subId
3827 + " operator: " + operatorInfo);
3828 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003829 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3830 } finally {
3831 Binder.restoreCallingIdentity(identity);
3832 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003833 }
3834
3835 /**
3836 * Scans for available networks.
3837 */
3838 @Override
3839 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3841 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003842
Pengquan Meng0c05b502018-09-06 09:59:22 -07003843 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003844 try {
3845 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003846 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003847 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003848 } finally {
3849 Binder.restoreCallingIdentity(identity);
3850 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003851 }
3852
3853 /**
yinxub1bed742017-04-17 11:45:04 -07003854 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003855 *
yinxub1bed742017-04-17 11:45:04 -07003856 * @param subId id of the subscription
3857 * @param request contains the radio access networks with bands/channels to scan
3858 * @param messenger callback messenger for scan results or errors
3859 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003860 * @return the id of the requested scan which can be used to stop the scan.
3861 */
3862 @Override
3863 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3864 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3866 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003867
3868 final long identity = Binder.clearCallingIdentity();
3869 try {
3870 return mNetworkScanRequestTracker.startNetworkScan(
3871 request, messenger, binder, getPhone(subId));
3872 } finally {
3873 Binder.restoreCallingIdentity(identity);
3874 }
yinxu504e1392017-04-12 16:03:22 -07003875 }
3876
3877 /**
3878 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003879 *
3880 * @param subId id of the subscription
3881 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003882 */
3883 @Override
3884 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3886 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003887
3888 final long identity = Binder.clearCallingIdentity();
3889 try {
3890 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3891 } finally {
3892 Binder.restoreCallingIdentity(identity);
3893 }
yinxu504e1392017-04-12 16:03:22 -07003894 }
3895
3896 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003897 * Get the calculated preferred network type.
3898 * Used for debugging incorrect network type.
3899 *
3900 * @return the preferred network type, defined in RILConstants.java.
3901 */
3902 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003903 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003904 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003905 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003906 return RILConstants.PREFERRED_NETWORK_MODE;
3907 }
3908
Malcolm Chend965c8b2018-02-28 15:00:40 -08003909 final long identity = Binder.clearCallingIdentity();
3910 try {
3911 // FIXME: need to get SubId from somewhere.
3912 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3913 } finally {
3914 Binder.restoreCallingIdentity(identity);
3915 }
Junda Liu84d15a22014-07-02 11:21:04 -07003916 }
3917
3918 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003919 * Get the preferred network type.
3920 * Used for device configuration by some CDMA operators.
3921 *
3922 * @return the preferred network type, defined in RILConstants.java.
3923 */
3924 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003925 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3927 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003928
3929 final long identity = Binder.clearCallingIdentity();
3930 try {
3931 if (DBG) log("getPreferredNetworkType");
3932 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3933 int networkType = (result != null ? result[0] : -1);
3934 if (DBG) log("getPreferredNetworkType: " + networkType);
3935 return networkType;
3936 } finally {
3937 Binder.restoreCallingIdentity(identity);
3938 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003939 }
3940
3941 /**
3942 * Set the preferred network type.
3943 * Used for device configuration by some CDMA operators.
3944 *
3945 * @param networkType the preferred network type, defined in RILConstants.java.
3946 * @return true on success; false on any failure.
3947 */
3948 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003949 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3951 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003952
3953 final long identity = Binder.clearCallingIdentity();
3954 try {
3955 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3956 Boolean success = (Boolean) sendRequest(
3957 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3958 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3959 if (success) {
3960 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3961 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3962 }
3963 return success;
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003966 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003967 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003968
3969 /**
Junda Liu475951f2014-11-07 16:45:03 -08003970 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07003971 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003972 * tethering.
3973 *
3974 * @return 0: Not required. 1: required. 2: Not set.
3975 * @hide
3976 */
3977 @Override
3978 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003979 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003980
3981 final long identity = Binder.clearCallingIdentity();
3982 try {
3983 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3984 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07003985 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Malcolm Chend965c8b2018-02-28 15:00:40 -08003986 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3987 dunRequired = 1;
3988 }
3989 return dunRequired;
3990 } finally {
3991 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003992 }
Junda Liu475951f2014-11-07 16:45:03 -08003993 }
3994
3995 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003996 * Set mobile data enabled
3997 * Used by the user through settings etc to turn on/off mobile data
3998 *
3999 * @param enable {@code true} turn turn data on, else {@code false}
4000 */
4001 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004002 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4004 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004005
4006 final long identity = Binder.clearCallingIdentity();
4007 try {
4008 int phoneId = mSubscriptionController.getPhoneId(subId);
4009 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4010 Phone phone = PhoneFactory.getPhone(phoneId);
4011 if (phone != null) {
4012 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
4013 phone.setUserDataEnabled(enable);
4014 } else {
4015 loge("setUserDataEnabled: no phone for subId=" + subId);
4016 }
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004019 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004020 }
4021
4022 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004023 * Get the user enabled state of Mobile Data.
4024 *
4025 * TODO: remove and use isUserDataEnabled.
4026 * This can't be removed now because some vendor codes
4027 * calls through ITelephony directly while they should
4028 * use TelephonyManager.
4029 *
4030 * @return true on enabled
4031 */
4032 @Override
4033 public boolean getDataEnabled(int subId) {
4034 return isUserDataEnabled(subId);
4035 }
4036
4037 /**
4038 * Get whether mobile data is enabled per user setting.
4039 *
4040 * There are other factors deciding whether mobile data is actually enabled, but they are
4041 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004042 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004043 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004044 *
4045 * @return {@code true} if data is enabled else {@code false}
4046 */
4047 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004048 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004049 try {
4050 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4051 null);
4052 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4054 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004055 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004056
4057 final long identity = Binder.clearCallingIdentity();
4058 try {
4059 int phoneId = mSubscriptionController.getPhoneId(subId);
4060 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4061 Phone phone = PhoneFactory.getPhone(phoneId);
4062 if (phone != null) {
4063 boolean retVal = phone.isUserDataEnabled();
4064 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4065 return retVal;
4066 } else {
4067 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4068 return false;
4069 }
4070 } finally {
4071 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004072 }
4073 }
4074
4075 /**
4076 * Get whether mobile data is enabled.
4077 *
4078 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4079 * whether mobile data is actually enabled.
4080 *
4081 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4082 *
4083 * @return {@code true} if data is enabled else {@code false}
4084 */
4085 @Override
4086 public boolean isDataEnabled(int subId) {
4087 try {
4088 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4089 null);
4090 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4092 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004093 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004094
4095 final long identity = Binder.clearCallingIdentity();
4096 try {
4097 int phoneId = mSubscriptionController.getPhoneId(subId);
4098 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4099 Phone phone = PhoneFactory.getPhone(phoneId);
4100 if (phone != null) {
4101 boolean retVal = phone.isDataEnabled();
4102 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4103 return retVal;
4104 } else {
4105 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4106 return false;
4107 }
4108 } finally {
4109 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004110 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004111 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004112
4113 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004114 public int getCarrierPrivilegeStatus(int subId) {
4115 final Phone phone = getPhone(subId);
4116 if (phone == null) {
4117 loge("getCarrierPrivilegeStatus: Invalid subId");
4118 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4119 }
4120 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004121 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004122 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004123 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4124 }
4125 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004126 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004127 }
Junda Liu29340342014-07-10 15:23:27 -07004128
4129 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004130 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4131 final Phone phone = getPhone(subId);
4132 if (phone == null) {
4133 loge("getCarrierPrivilegeStatus: Invalid subId");
4134 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4135 }
4136 UiccProfile profile =
4137 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4138 if (profile == null) {
4139 loge("getCarrierPrivilegeStatus: No UICC");
4140 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4141 }
4142 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4143 }
4144
4145 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004146 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004147 if (TextUtils.isEmpty(pkgName))
4148 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08004149 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004150 if (card == null) {
4151 loge("checkCarrierPrivilegesForPackage: No UICC");
4152 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4153 }
Zach Johnson50ecba32015-05-19 00:24:21 -07004154 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
4155 }
4156
4157 @Override
4158 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004159 if (TextUtils.isEmpty(pkgName))
4160 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004161 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4162 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4163 UiccCard card = UiccController.getInstance().getUiccCard(i);
4164 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004165 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004166 continue;
4167 }
4168
4169 result = card.getCarrierPrivilegeStatus(
4170 mPhone.getContext().getPackageManager(), pkgName);
4171 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4172 break;
4173 }
4174 }
4175
4176 return result;
Junda Liu29340342014-07-10 15:23:27 -07004177 }
Derek Tan89e89d42014-07-08 17:00:10 -07004178
4179 @Override
Junda Liue64de782015-04-16 17:19:16 -07004180 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4181 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4182 loge("phoneId " + phoneId + " is not valid.");
4183 return null;
4184 }
4185 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004186 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004187 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004188 return null ;
4189 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004190 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004191 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004192 }
4193
Amith Yamasani6e118872016-02-19 12:53:51 -08004194 @Override
4195 public List<String> getPackagesWithCarrierPrivileges() {
4196 PackageManager pm = mPhone.getContext().getPackageManager();
4197 List<String> privilegedPackages = new ArrayList<>();
4198 List<PackageInfo> packages = null;
4199 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4200 UiccCard card = UiccController.getInstance().getUiccCard(i);
4201 if (card == null) {
4202 // No UICC in that slot.
4203 continue;
4204 }
4205 if (card.hasCarrierPrivilegeRules()) {
4206 if (packages == null) {
4207 // Only check packages in user 0 for now
4208 packages = pm.getInstalledPackagesAsUser(
4209 PackageManager.MATCH_DISABLED_COMPONENTS
4210 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4211 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4212 }
4213 for (int p = packages.size() - 1; p >= 0; p--) {
4214 PackageInfo pkgInfo = packages.get(p);
4215 if (pkgInfo != null && pkgInfo.packageName != null
4216 && card.getCarrierPrivilegeStatus(pkgInfo)
4217 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4218 privilegedPackages.add(pkgInfo.packageName);
4219 }
4220 }
4221 }
4222 }
4223 return privilegedPackages;
4224 }
4225
Wink Savilleb564aae2014-10-23 10:18:09 -07004226 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004227 final Phone phone = getPhone(subId);
4228 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004229 if (card == null) {
4230 loge("getIccId: No UICC");
4231 return null;
4232 }
4233 String iccId = card.getIccId();
4234 if (TextUtils.isEmpty(iccId)) {
4235 loge("getIccId: ICC ID is null or empty.");
4236 return null;
4237 }
4238 return iccId;
4239 }
4240
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004241 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004242 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4243 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004244 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4245 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004246
Malcolm Chend965c8b2018-02-28 15:00:40 -08004247 final long identity = Binder.clearCallingIdentity();
4248 try {
4249 final String iccId = getIccId(subId);
4250 final Phone phone = getPhone(subId);
4251 if (phone == null) {
4252 return false;
4253 }
4254 final String subscriberId = phone.getSubscriberId();
4255
4256 if (DBG_MERGE) {
4257 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4258 + subscriberId + " to " + number);
4259 }
4260
4261 if (TextUtils.isEmpty(iccId)) {
4262 return false;
4263 }
4264
4265 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4266
4267 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4268 if (alphaTag == null) {
4269 editor.remove(alphaTagPrefKey);
4270 } else {
4271 editor.putString(alphaTagPrefKey, alphaTag);
4272 }
4273
4274 // Record both the line number and IMSI for this ICCID, since we need to
4275 // track all merged IMSIs based on line number
4276 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4277 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4278 if (number == null) {
4279 editor.remove(numberPrefKey);
4280 editor.remove(subscriberPrefKey);
4281 } else {
4282 editor.putString(numberPrefKey, number);
4283 editor.putString(subscriberPrefKey, subscriberId);
4284 }
4285
4286 editor.commit();
4287 return true;
4288 } finally {
4289 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004290 }
Derek Tan7226c842014-07-02 17:42:23 -07004291 }
4292
4293 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004294 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004295 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004297 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004298 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004299 return null;
4300 }
Derek Tan97ebb422014-09-05 16:55:38 -07004301
Malcolm Chend965c8b2018-02-28 15:00:40 -08004302 final long identity = Binder.clearCallingIdentity();
4303 try {
4304 String iccId = getIccId(subId);
4305 if (iccId != null) {
4306 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4307 if (DBG_MERGE) {
4308 log("getLine1NumberForDisplay returning "
4309 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4310 }
4311 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004312 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004313 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4314 return null;
4315 } finally {
4316 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004317 }
Derek Tan7226c842014-07-02 17:42:23 -07004318 }
4319
4320 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004321 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004323 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004324 return null;
4325 }
Derek Tan97ebb422014-09-05 16:55:38 -07004326
Malcolm Chend965c8b2018-02-28 15:00:40 -08004327 final long identity = Binder.clearCallingIdentity();
4328 try {
4329 String iccId = getIccId(subId);
4330 if (iccId != null) {
4331 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4332 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4333 }
4334 return null;
4335 } finally {
4336 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004337 }
Derek Tan7226c842014-07-02 17:42:23 -07004338 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004339
4340 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004341 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004342 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4343 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004344 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004345 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4346 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004347 return null;
4348 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004349
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004350 final long identity = Binder.clearCallingIdentity();
4351 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004352 final Context context = mPhone.getContext();
4353 final TelephonyManager tele = TelephonyManager.from(context);
4354 final SubscriptionManager sub = SubscriptionManager.from(context);
4355
4356 // Figure out what subscribers are currently active
4357 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4358 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4359 // the process, where TelephonyManager was instantiated.
4360 // Otherwise AppOps check will fail.
4361
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004362 final int[] subIds = sub.getActiveSubscriptionIdList();
4363 for (int subId : subIds) {
4364 activeSubscriberIds.add(tele.getSubscriberId(subId));
4365 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004366
4367 // First pass, find a number override for an active subscriber
4368 String mergeNumber = null;
4369 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4370 for (String key : prefs.keySet()) {
4371 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4372 final String subscriberId = (String) prefs.get(key);
4373 if (activeSubscriberIds.contains(subscriberId)) {
4374 final String iccId = key.substring(
4375 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4376 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4377 mergeNumber = (String) prefs.get(numberKey);
4378 if (DBG_MERGE) {
4379 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4380 + " for active subscriber " + subscriberId);
4381 }
4382 if (!TextUtils.isEmpty(mergeNumber)) {
4383 break;
4384 }
4385 }
4386 }
4387 }
4388
4389 // Shortcut when no active merged subscribers
4390 if (TextUtils.isEmpty(mergeNumber)) {
4391 return null;
4392 }
4393
4394 // Second pass, find all subscribers under that line override
4395 final ArraySet<String> result = new ArraySet<>();
4396 for (String key : prefs.keySet()) {
4397 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4398 final String number = (String) prefs.get(key);
4399 if (mergeNumber.equals(number)) {
4400 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4401 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4402 final String subscriberId = (String) prefs.get(subscriberKey);
4403 if (!TextUtils.isEmpty(subscriberId)) {
4404 result.add(subscriberId);
4405 }
4406 }
4407 }
4408 }
4409
4410 final String[] resultArray = result.toArray(new String[result.size()]);
4411 Arrays.sort(resultArray);
4412 if (DBG_MERGE) {
4413 Slog.d(LOG_TAG,
4414 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4415 }
4416 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004417 } finally {
4418 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004419 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004420 }
4421
4422 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004423 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004424 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4425 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004426
4427 final long identity = Binder.clearCallingIdentity();
4428 try {
4429 final Phone phone = getPhone(subId);
4430 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4431 } finally {
4432 Binder.restoreCallingIdentity(identity);
4433 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004434 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004435
4436 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004437 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004438 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4439 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004440 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004441
4442 final long identity = Binder.clearCallingIdentity();
4443 try {
4444 final Phone phone = getPhone(subId);
4445 if (phone == null) {
4446 return false;
4447 }
4448 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4449 cdmaNonRoamingList);
4450 } finally {
4451 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004452 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004453 }
4454
4455 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004456 @Deprecated
4457 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4458 enforceModifyPermission();
4459
4460 int returnValue = 0;
4461 try {
vagdevie435a3e2018-08-15 16:01:53 -07004462 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004463 if(result.exception == null) {
4464 if (result.result != null) {
4465 byte[] responseData = (byte[])(result.result);
4466 if(responseData.length > oemResp.length) {
4467 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4468 responseData.length + "bytes. Buffer Size is " +
4469 oemResp.length + "bytes.");
4470 }
4471 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4472 returnValue = responseData.length;
4473 }
4474 } else {
4475 CommandException ex = (CommandException) result.exception;
4476 returnValue = ex.getCommandError().ordinal();
4477 if(returnValue > 0) returnValue *= -1;
4478 }
4479 } catch (RuntimeException e) {
4480 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4481 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4482 if(returnValue > 0) returnValue *= -1;
4483 }
4484
4485 return returnValue;
4486 }
4487
4488 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004489 public void setRadioCapability(RadioAccessFamily[] rafs) {
4490 try {
4491 ProxyController.getInstance().setRadioCapability(rafs);
4492 } catch (RuntimeException e) {
4493 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4494 }
4495 }
4496
4497 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004498 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004499 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004500 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004501 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004502 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004503 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004504 final long identity = Binder.clearCallingIdentity();
4505 try {
chen xufeeed752018-10-26 14:17:57 -07004506 TelephonyPermissions
4507 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4508 mApp, phone.getSubId(), "getRadioAccessFamily");
4509 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004510 } finally {
4511 Binder.restoreCallingIdentity(identity);
4512 }
chen xufeeed752018-10-26 14:17:57 -07004513 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004514 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004515
4516 @Override
4517 public void enableVideoCalling(boolean enable) {
4518 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004519
4520 final long identity = Binder.clearCallingIdentity();
4521 try {
4522 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4523 } finally {
4524 Binder.restoreCallingIdentity(identity);
4525 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004526 }
4527
4528 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004529 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4531 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4532 return false;
4533 }
Svet Ganovb320e182015-04-16 12:30:10 -07004534
Malcolm Chend965c8b2018-02-28 15:00:40 -08004535 final long identity = Binder.clearCallingIdentity();
4536 try {
4537 // Check the user preference and the system-level IMS setting. Even if the user has
4538 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4539 // In the long run, we may instead need to check if there exists a connection service
4540 // which can support video calling.
4541 ImsManager imsManager =
4542 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4543 return imsManager.isVtEnabledByPlatform()
4544 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4545 && imsManager.isVtEnabledByUser();
4546 } finally {
4547 Binder.restoreCallingIdentity(identity);
4548 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004549 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004550
Andrew Leea1239f22015-03-02 17:44:07 -08004551 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004552 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4553 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4554 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4555 return false;
4556 }
4557
4558 final long identity = Binder.clearCallingIdentity();
4559 try {
4560 CarrierConfigManager configManager =
4561 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4562 return configManager.getConfigForSubId(mPhone.getSubId())
4563 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4564 } finally {
4565 Binder.restoreCallingIdentity(identity);
4566 }
Andrew Leea1239f22015-03-02 17:44:07 -08004567 }
4568
4569 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004570 public boolean isWorldPhone(int subId, String callingPackage) {
4571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4572 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4573 return false;
4574 }
4575
4576 final long identity = Binder.clearCallingIdentity();
4577 try {
4578 CarrierConfigManager configManager =
4579 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4580 return configManager.getConfigForSubId(mPhone.getSubId())
4581 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4582 } finally {
4583 Binder.restoreCallingIdentity(identity);
4584 }
Andrew Leea1239f22015-03-02 17:44:07 -08004585 }
4586
Andrew Lee9431b832015-03-09 18:46:45 -07004587 @Override
4588 public boolean isTtyModeSupported() {
4589 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004590 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004591 }
4592
4593 @Override
4594 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004595 final long identity = Binder.clearCallingIdentity();
4596 try {
4597 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4598 } finally {
4599 Binder.restoreCallingIdentity(identity);
4600 }
Andrew Lee9431b832015-03-09 18:46:45 -07004601 }
4602
Hall Liuf6668912018-10-31 17:05:23 -07004603 /**
4604 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4605 * support for the feature and device firmware support.
4606 *
4607 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4608 */
4609 @Override
4610 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004611 final long identity = Binder.clearCallingIdentity();
4612 try {
4613 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4614 mPhone.getSubId()).getBoolean(
4615 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4616 boolean isDeviceSupported =
4617 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4618 return isCarrierSupported && isDeviceSupported;
4619 } finally {
4620 Binder.restoreCallingIdentity(identity);
4621 }
Hall Liu98187582018-01-22 19:15:32 -08004622 }
4623
Hall Liuf6668912018-10-31 17:05:23 -07004624 /**
4625 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4626 * both also support RTT.
4627 */
4628 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004629 final long identity = Binder.clearCallingIdentity();
4630 try {
Hall Liuf6668912018-10-31 17:05:23 -07004631 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004632 mPhone.getContext().getContentResolver(),
4633 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4634 } finally {
4635 Binder.restoreCallingIdentity(identity);
4636 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004637 }
4638
Sanket Padawe7310cc72015-01-14 09:53:20 -08004639 /**
4640 * Returns the unique device ID of phone, for example, the IMEI for
4641 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4642 *
4643 * <p>Requires Permission:
4644 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4645 */
4646 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004647 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004648 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004649 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004650 return null;
4651 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004652 int subId = phone.getSubId();
4653 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4654 mApp, subId, callingPackage, "getDeviceId")) {
4655 return null;
4656 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004657
4658 final long identity = Binder.clearCallingIdentity();
4659 try {
4660 return phone.getDeviceId();
4661 } finally {
4662 Binder.restoreCallingIdentity(identity);
4663 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004664 }
4665
Ping Sunc67b7c22016-03-02 19:16:45 +08004666 /**
4667 * {@hide}
4668 * Returns the IMS Registration Status on a particular subid
4669 *
4670 * @param subId
4671 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004672 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004673 Phone phone = getPhone(subId);
4674 if (phone != null) {
4675 return phone.isImsRegistered();
4676 } else {
4677 return false;
4678 }
4679 }
4680
Santos Cordon7a1885b2015-02-03 11:15:19 -08004681 @Override
4682 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004683 final long identity = Binder.clearCallingIdentity();
4684 try {
4685 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4686 } finally {
4687 Binder.restoreCallingIdentity(identity);
4688 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004689 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004690
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004691 /**
4692 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004693 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004694 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004695 final long identity = Binder.clearCallingIdentity();
4696 try {
4697 Phone phone = getPhone(subId);
4698 if (phone != null) {
4699 return phone.isWifiCallingEnabled();
4700 } else {
4701 return false;
4702 }
4703 } finally {
4704 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004705 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004706 }
4707
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004708 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004709 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004710 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004711 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004712 final long identity = Binder.clearCallingIdentity();
4713 try {
4714 Phone phone = getPhone(subId);
4715 if (phone != null) {
4716 return phone.isVideoEnabled();
4717 } else {
4718 return false;
4719 }
4720 } finally {
4721 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004722 }
4723 }
4724
4725 /**
4726 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4727 * defined in {@link ImsRegistrationImplBase}.
4728 */
4729 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004730 final long identity = Binder.clearCallingIdentity();
4731 try {
4732 Phone phone = getPhone(subId);
4733 if (phone != null) {
4734 return phone.getImsRegistrationTech();
4735 } else {
4736 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4737 }
4738 } finally {
4739 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004740 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004741 }
4742
Stuart Scott8eef64f2015-04-08 15:13:54 -07004743 @Override
4744 public void factoryReset(int subId) {
4745 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004746 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4747 return;
4748 }
4749
Svet Ganovcc087f82015-05-12 20:35:54 -07004750 final long identity = Binder.clearCallingIdentity();
4751 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004752 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4753 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004754 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004755 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004756 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4757 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004758 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004759 }
4760 } finally {
4761 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004762 }
4763 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004764
4765 @Override
4766 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004767 final long identity = Binder.clearCallingIdentity();
4768 try {
4769 // We query all subscriptions instead of just the active ones, because
4770 // this might be called early on in the provisioning flow when the
4771 // subscriptions potentially aren't active yet.
4772 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4773 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004774 return null;
4775 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004776
Malcolm Chend965c8b2018-02-28 15:00:40 -08004777 // This function may be called very early, say, from the setup wizard, at
4778 // which point we won't have a default subscription set. If that's the case
4779 // we just choose the first, which will be valid in "most cases".
4780 final int defaultSubId = getDefaultSubscription();
4781 SubscriptionInfo info = null;
4782 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4783 info = slist.get(0);
4784 } else {
4785 for (SubscriptionInfo item : slist) {
4786 if (item.getSubscriptionId() == defaultSubId) {
4787 info = item;
4788 break;
4789 }
4790 }
4791
4792 if (info == null) {
4793 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004794 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004795 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004796
Malcolm Chend965c8b2018-02-28 15:00:40 -08004797 // Try and fetch the locale from the carrier properties or from the SIM language
4798 // preferences (EF-PL and EF-LI)...
4799 final int mcc = info.getMcc();
4800 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4801 String simLanguage = null;
4802 if (defaultPhone != null) {
4803 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4804 if (localeFromDefaultSim != null) {
4805 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4806 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4807 return localeFromDefaultSim.toLanguageTag();
4808 } else {
4809 simLanguage = localeFromDefaultSim.getLanguage();
4810 }
4811 }
4812 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004813
Malcolm Chend965c8b2018-02-28 15:00:40 -08004814 // The SIM language preferences only store a language (e.g. fr = French), not an
4815 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4816 // the SIM and carrier preferences does not include a country we add the country
4817 // determined from the SIM MCC to provide an exact locale.
4818 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4819 simLanguage);
4820 if (mccLocale != null) {
4821 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4822 return mccLocale.toLanguageTag();
4823 }
4824
4825 if (DBG) log("No locale found - returning null");
4826 return null;
4827 } finally {
4828 Binder.restoreCallingIdentity(identity);
4829 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004830 }
4831
4832 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004833 return mSubscriptionController.getAllSubInfoList(
4834 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004835 }
4836
Malcolm Chend965c8b2018-02-28 15:00:40 -08004837 /**
4838 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4839 */
4840 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4841 return mSubscriptionController.getActiveSubscriptionInfoList(
4842 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004843 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004844
Chenjie Yu1ba97252018-01-11 18:16:20 -08004845 private final ModemActivityInfo mLastModemActivityInfo =
4846 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4847
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004848 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004849 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4850 * representing the state of the modem.
4851 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004852 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4853 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004854 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004855 */
4856 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004857 public void requestModemActivityInfo(ResultReceiver result) {
4858 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004859 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004860
4861 final long identity = Binder.clearCallingIdentity();
4862 try {
4863 ModemActivityInfo ret = null;
4864 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004865 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4866 CMD_GET_MODEM_ACTIVITY_INFO,
4867 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004868 if (isModemActivityInfoValid(info)) {
4869 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4870 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4871 mergedTxTimeMs[i] =
4872 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4873 }
4874 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4875 mLastModemActivityInfo.setSleepTimeMillis(
4876 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4877 mLastModemActivityInfo.setIdleTimeMillis(
4878 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4879 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4880 mLastModemActivityInfo.setRxTimeMillis(
4881 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4882 mLastModemActivityInfo.setEnergyUsed(
4883 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004884 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004885 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4886 mLastModemActivityInfo.getSleepTimeMillis(),
4887 mLastModemActivityInfo.getIdleTimeMillis(),
4888 mLastModemActivityInfo.getTxTimeMillis(),
4889 mLastModemActivityInfo.getRxTimeMillis(),
4890 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004891 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004892 Bundle bundle = new Bundle();
4893 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4894 result.send(0, bundle);
4895 } finally {
4896 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004897 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004898 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004899
Siddharth Rayf5d29552018-06-17 15:02:38 -07004900 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4901 // less than total activity duration.
4902 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4903 if (info == null) {
4904 return false;
4905 }
4906 int activityDurationMs =
4907 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4908 int totalTxTimeMs = 0;
4909 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4910 totalTxTimeMs += info.getTxTimeMillis()[i];
4911 }
4912 return (info.isValid()
4913 && (info.getSleepTimeMillis() <= activityDurationMs)
4914 && (info.getIdleTimeMillis() <= activityDurationMs)
4915 && (info.getRxTimeMillis() <= activityDurationMs)
4916 && (totalTxTimeMs <= activityDurationMs));
4917 }
4918
Jack Yu85bd38a2015-11-09 11:34:32 -08004919 /**
4920 * {@hide}
4921 * Returns the service state information on specified subscription.
4922 */
4923 @Override
4924 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004926 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004927 return null;
4928 }
4929
Malcolm Chend965c8b2018-02-28 15:00:40 -08004930 final long identity = Binder.clearCallingIdentity();
4931 try {
4932 final Phone phone = getPhone(subId);
4933 if (phone == null) {
4934 return null;
4935 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004936
Malcolm Chend965c8b2018-02-28 15:00:40 -08004937 return phone.getServiceState();
4938 } finally {
4939 Binder.restoreCallingIdentity(identity);
4940 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004941 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004942
4943 /**
4944 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4945 *
4946 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4947 * voicemail ringtone.
4948 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4949 * PhoneAccount.
4950 */
4951 @Override
4952 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004953 final long identity = Binder.clearCallingIdentity();
4954 try {
4955 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4956 if (phone == null) {
4957 phone = mPhone;
4958 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004959
Malcolm Chend965c8b2018-02-28 15:00:40 -08004960 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4961 } finally {
4962 Binder.restoreCallingIdentity(identity);
4963 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004964 }
4965
4966 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004967 * Sets the per-account voicemail ringtone.
4968 *
4969 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4970 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4971 *
4972 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4973 * voicemail ringtone.
4974 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4975 * PhoneAccount.
4976 */
4977 @Override
4978 public void setVoicemailRingtoneUri(String callingPackage,
4979 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4980 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4981 if (!TextUtils.equals(callingPackage,
4982 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4984 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4985 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004986 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004987
4988 final long identity = Binder.clearCallingIdentity();
4989 try {
4990 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4991 if (phone == null) {
4992 phone = mPhone;
4993 }
4994 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4995 } finally {
4996 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004997 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004998 }
4999
5000 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005001 * Returns whether vibration is set for voicemail notification in Phone settings.
5002 *
5003 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5004 * voicemail vibration setting.
5005 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5006 */
5007 @Override
5008 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005009 final long identity = Binder.clearCallingIdentity();
5010 try {
5011 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5012 if (phone == null) {
5013 phone = mPhone;
5014 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005015
Malcolm Chend965c8b2018-02-28 15:00:40 -08005016 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5017 } finally {
5018 Binder.restoreCallingIdentity(identity);
5019 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005020 }
5021
Youhan Wange64578a2016-05-02 15:32:42 -07005022 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005023 * Sets the per-account voicemail vibration.
5024 *
5025 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5026 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5027 *
5028 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5029 * voicemail vibration setting.
5030 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5031 * specific PhoneAccount.
5032 */
5033 @Override
5034 public void setVoicemailVibrationEnabled(String callingPackage,
5035 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
5036 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5037 if (!TextUtils.equals(callingPackage,
5038 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5040 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5041 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005042 }
5043
Malcolm Chend965c8b2018-02-28 15:00:40 -08005044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5047 if (phone == null) {
5048 phone = mPhone;
5049 }
5050 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5051 } finally {
5052 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005053 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005054 }
5055
5056 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005057 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5058 *
5059 * @throws SecurityException if the caller does not have the required permission
5060 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005061 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005062 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005063 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005064 }
5065
5066 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005067 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5068 * permission.
5069 *
5070 * @throws SecurityException if the caller does not have the required permission
5071 */
5072 private void enforceSendSmsPermission() {
5073 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5074 }
5075
5076 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005077 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005078 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005079 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005080 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005081 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005082 final long identity = Binder.clearCallingIdentity();
5083 try {
5084 ComponentName componentName =
5085 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
5086 if (componentName == null) {
5087 throw new SecurityException(
5088 "Caller not current active visual voicemail package[null]");
5089 }
5090 String vvmPackage = componentName.getPackageName();
5091 if (!callingPackage.equals(vvmPackage)) {
5092 throw new SecurityException("Caller not current active visual voicemail package["
5093 + vvmPackage + "]");
5094 }
5095 } finally {
5096 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005097 }
5098 }
5099
5100 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005101 * Return the application ID for the app type.
5102 *
5103 * @param subId the subscription ID that this request applies to.
5104 * @param appType the uicc app type.
5105 * @return Application ID for specificied app type, or null if no uicc.
5106 */
5107 @Override
5108 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005109 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005110 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005111
5112 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005113 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005114 if (phone == null) {
5115 return null;
5116 }
5117 String aid = null;
5118 try {
5119 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5120 .getApplicationByType(appType).getAid();
5121 } catch (Exception e) {
5122 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5123 }
5124 return aid;
5125 } finally {
5126 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005127 }
Youhan Wange64578a2016-05-02 15:32:42 -07005128 }
5129
Youhan Wang4001d252016-05-11 10:29:41 -07005130 /**
5131 * Return the Electronic Serial Number.
5132 *
5133 * @param subId the subscription ID that this request applies to.
5134 * @return ESN or null if error.
5135 */
5136 @Override
5137 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005138 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005139 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005140
5141 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005142 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005143 if (phone == null) {
5144 return null;
5145 }
5146 String esn = null;
5147 try {
5148 esn = phone.getEsn();
5149 } catch (Exception e) {
5150 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5151 }
5152 return esn;
5153 } finally {
5154 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005155 }
Youhan Wang4001d252016-05-11 10:29:41 -07005156 }
5157
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005158 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005159 * Return the Preferred Roaming List Version.
5160 *
5161 * @param subId the subscription ID that this request applies to.
5162 * @return PRLVersion or null if error.
5163 */
5164 @Override
5165 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005166 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005167 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005168
5169 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005170 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005171 if (phone == null) {
5172 return null;
5173 }
5174 String cdmaPrlVersion = null;
5175 try {
5176 cdmaPrlVersion = phone.getCdmaPrlVersion();
5177 } catch (Exception e) {
5178 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5179 }
5180 return cdmaPrlVersion;
5181 } finally {
5182 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005183 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005184 }
5185
5186 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005187 * Get snapshot of Telephony histograms
5188 * @return List of Telephony histograms
5189 * @hide
5190 */
5191 @Override
5192 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005193 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5194 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005195
5196 final long identity = Binder.clearCallingIdentity();
5197 try {
5198 return RIL.getTelephonyRILTimingHistograms();
5199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005202 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005203
5204 /**
5205 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005206 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005207 * Require system privileges. In the future we may add this to carrier APIs.
5208 *
5209 * @return The number of carriers set successfully, should match length of carriers
5210 */
5211 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005212 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005213 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005214 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005215
Meng Wang9b7c4e92017-02-17 11:41:27 -08005216 if (carriers == null) {
5217 throw new NullPointerException("carriers cannot be null");
5218 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005219
Malcolm Chend965c8b2018-02-28 15:00:40 -08005220 final long identity = Binder.clearCallingIdentity();
5221 try {
5222 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005223 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5224 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005225 return retVal[0];
5226 } finally {
5227 Binder.restoreCallingIdentity(identity);
5228 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005229 }
5230
5231 /**
5232 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005233 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005234 * Require system privileges. In the future we may add this to carrier APIs.
5235 *
5236 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5237 * means all carriers are allowed.
5238 */
5239 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005240 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005241 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005242 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005243
5244 final long identity = Binder.clearCallingIdentity();
5245 try {
5246 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005247 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5248 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005252 }
5253
fionaxu59545b42016-05-25 15:53:37 -07005254 /**
5255 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5256 * @param subId the subscription ID that this action applies to.
5257 * @param enabled control enable or disable metered apns.
5258 * {@hide}
5259 */
5260 @Override
5261 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5262 enforceModifyPermission();
5263 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005264
5265 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005266 if (phone == null) {
5267 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5268 return;
5269 }
5270 try {
5271 phone.carrierActionSetMeteredApnsEnabled(enabled);
5272 } catch (Exception e) {
5273 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005274 } finally {
5275 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005276 }
5277 }
5278
5279 /**
5280 * Action set from carrier signalling broadcast receivers to enable/disable radio
5281 * @param subId the subscription ID that this action applies to.
5282 * @param enabled control enable or disable radio.
5283 * {@hide}
5284 */
5285 @Override
5286 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5287 enforceModifyPermission();
5288 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005289
5290 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005291 if (phone == null) {
5292 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5293 return;
5294 }
5295 try {
5296 phone.carrierActionSetRadioEnabled(enabled);
5297 } catch (Exception e) {
5298 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005299 } finally {
5300 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005301 }
5302 }
5303
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005304 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005305 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5306 * network status based on which carrier apps could apply actions accordingly,
5307 * enable/disable default url handler for example.
5308 *
5309 * @param subId the subscription ID that this action applies to.
5310 * @param report control start/stop reporting the default network status.
5311 * {@hide}
5312 */
5313 @Override
5314 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5315 enforceModifyPermission();
5316 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005317
5318 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005319 if (phone == null) {
5320 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5321 return;
5322 }
5323 try {
5324 phone.carrierActionReportDefaultNetworkStatus(report);
5325 } catch (Exception e) {
5326 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005327 } finally {
5328 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005329 }
5330 }
5331
5332 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005333 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5334 * bug report is being generated.
5335 */
5336 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005337 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005338 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5339 != PackageManager.PERMISSION_GRANTED) {
5340 writer.println("Permission Denial: can't dump Phone from pid="
5341 + Binder.getCallingPid()
5342 + ", uid=" + Binder.getCallingUid()
5343 + "without permission "
5344 + android.Manifest.permission.DUMP);
5345 return;
5346 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005347 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005348 }
Jack Yueb89b242016-06-22 13:27:47 -07005349
Brad Ebingerdac2f002018-04-03 15:17:52 -07005350 @Override
5351 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5352 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5353 throws RemoteException {
5354 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5355 }
5356
Jack Yueb89b242016-06-22 13:27:47 -07005357 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005358 * Get aggregated video call data usage since boot.
5359 *
5360 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5361 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005362 * {@hide}
5363 */
5364 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005365 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005366 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5367 null);
5368
Malcolm Chend965c8b2018-02-28 15:00:40 -08005369 final long identity = Binder.clearCallingIdentity();
5370 try {
5371 // NetworkStatsService keeps tracking the active network interface and identity. It
5372 // records the delta with the corresponding network identity.
5373 // We just return the total video call data usage snapshot since boot.
5374 Phone phone = getPhone(subId);
5375 if (phone != null) {
5376 return phone.getVtDataUsage(perUidStats);
5377 }
5378 return null;
5379 } finally {
5380 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005381 }
Jack Yueb89b242016-06-22 13:27:47 -07005382 }
Jack Yu75ab2952016-07-08 14:29:33 -07005383
5384 /**
5385 * Policy control of data connection. Usually used when data limit is passed.
5386 * @param enabled True if enabling the data, otherwise disabling.
5387 * @param subId Subscription index
5388 * {@hide}
5389 */
5390 @Override
5391 public void setPolicyDataEnabled(boolean enabled, int subId) {
5392 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005393
5394 final long identity = Binder.clearCallingIdentity();
5395 try {
5396 Phone phone = getPhone(subId);
5397 if (phone != null) {
5398 phone.setPolicyDataEnabled(enabled);
5399 }
5400 } finally {
5401 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005402 }
5403 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005404
5405 /**
5406 * Get Client request stats
5407 * @return List of Client Request Stats
5408 * @hide
5409 */
5410 @Override
5411 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005412 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005413 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005414 return null;
5415 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005416 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005417
Malcolm Chend965c8b2018-02-28 15:00:40 -08005418 final long identity = Binder.clearCallingIdentity();
5419 try {
5420 if (phone != null) {
5421 return phone.getClientRequestStats();
5422 }
5423
5424 return null;
5425 } finally {
5426 Binder.restoreCallingIdentity(identity);
5427 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005428 }
5429
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005430 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005431 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005432 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005433 }
Jack Yueb4124c2017-02-16 15:32:43 -08005434
5435 /**
Grace Chen70990072017-03-24 17:21:30 -07005436 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005437 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005438 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005439 * @param state State of SIM (power down, power up, pass through)
5440 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5441 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5442 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005443 *
5444 **/
5445 @Override
Grace Chen70990072017-03-24 17:21:30 -07005446 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005447 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005448 Phone phone = PhoneFactory.getPhone(slotIndex);
5449
vagdevie435a3e2018-08-15 16:01:53 -07005450 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5451
Malcolm Chend965c8b2018-02-28 15:00:40 -08005452 final long identity = Binder.clearCallingIdentity();
5453 try {
5454 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005455 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005456 }
5457 } finally {
5458 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005459 }
5460 }
Shuo Qiandd210312017-04-12 22:11:33 +00005461
Tyler Gunn65d45c22017-06-05 11:22:26 -07005462 private boolean isUssdApiAllowed(int subId) {
5463 CarrierConfigManager configManager =
5464 (CarrierConfigManager) mPhone.getContext().getSystemService(
5465 Context.CARRIER_CONFIG_SERVICE);
5466 if (configManager == null) {
5467 return false;
5468 }
5469 PersistableBundle pb = configManager.getConfigForSubId(subId);
5470 if (pb == null) {
5471 return false;
5472 }
5473 return pb.getBoolean(
5474 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5475 }
5476
Shuo Qiandd210312017-04-12 22:11:33 +00005477 /**
5478 * Check if phone is in emergency callback mode
5479 * @return true if phone is in emergency callback mode
5480 * @param subId sub id
5481 */
goneil9c5f4872017-12-05 14:07:56 -08005482 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005483 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005484 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005485 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005486
5487 final long identity = Binder.clearCallingIdentity();
5488 try {
5489 if (phone != null) {
5490 return phone.isInEcm();
5491 } else {
5492 return false;
5493 }
5494 } finally {
5495 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005496 }
5497 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005498
5499 /**
5500 * Get the current signal strength information for the given subscription.
5501 * Because this information is not updated when the device is in a low power state
5502 * it should not be relied-upon to be current.
5503 * @param subId Subscription index
5504 * @return the most recent cached signal strength info from the modem
5505 */
5506 @Override
5507 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005508 final long identity = Binder.clearCallingIdentity();
5509 try {
5510 Phone p = getPhone(subId);
5511 if (p == null) {
5512 return null;
5513 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005514
Malcolm Chend965c8b2018-02-28 15:00:40 -08005515 return p.getSignalStrength();
5516 } finally {
5517 Binder.restoreCallingIdentity(identity);
5518 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005519 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005520
Pengquan Meng9140aec2018-08-22 14:49:57 -07005521 /**
chen xu907e5a22018-10-11 13:21:04 -07005522 * Get the current modem radio state for the given slot.
5523 * @param slotIndex slot index.
5524 * @param callingPackage the name of the package making the call.
5525 * @return the current radio power state from the modem
5526 */
5527 @Override
5528 public int getRadioPowerState(int slotIndex, String callingPackage) {
5529 Phone phone = PhoneFactory.getPhone(slotIndex);
5530 if (phone != null) {
5531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5532 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5533 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5534 }
5535
5536 final long identity = Binder.clearCallingIdentity();
5537 try {
5538 return phone.getRadioPowerState();
5539 } finally {
5540 Binder.restoreCallingIdentity(identity);
5541 }
5542 }
5543 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5544 }
5545
5546 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005547 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5548 *
5549 * <p>Requires one of the following permissions:
5550 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5551 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5552 * privileges.
5553 *
5554 * @param subId subscription id
5555 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5556 * {@code false}.
5557 */
5558 @Override
5559 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005560 boolean isEnabled = false;
5561 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005562 try {
5563 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005564 null /* message */);
5565 Phone phone = getPhone(subId);
5566 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005567 } catch (Exception e) {
5568 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5569 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005570 } finally {
5571 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005572 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005573 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005574 }
5575
5576
5577 /**
5578 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5579 *
5580 * <p> Requires permission:
5581 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5582 * privileges.
5583 *
5584 * @param subId subscription id
5585 * @param isEnabled {@code true} means enable, {@code false} means disable.
5586 */
5587 @Override
5588 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005589 final long identity = Binder.clearCallingIdentity();
5590 try {
5591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5592 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005593
Pengquan Meng0c05b502018-09-06 09:59:22 -07005594 Phone phone = getPhone(subId);
5595 if (phone != null) {
5596 phone.setDataRoamingEnabled(isEnabled);
5597 }
5598 } finally {
5599 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005600 }
5601 }
5602
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005603 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005604 public boolean isManualNetworkSelectionAllowed(int subId) {
5605 boolean isAllowed = true;
5606 final long identity = Binder.clearCallingIdentity();
5607 try {
5608 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5609 mApp, subId, "isManualNetworkSelectionAllowed");
5610 Phone phone = getPhone(subId);
5611 if (phone != null) {
5612 isAllowed = phone.isCspPlmnEnabled();
5613 }
5614 } finally {
5615 Binder.restoreCallingIdentity(identity);
5616 }
5617 return isAllowed;
5618 }
5619
5620 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005621 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005622 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005623
Malcolm Chend965c8b2018-02-28 15:00:40 -08005624 final long identity = Binder.clearCallingIdentity();
5625 try {
5626 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5627 if (slots == null) {
5628 Rlog.i(LOG_TAG, "slots is null.");
5629 return null;
5630 }
5631
5632 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5633 for (int i = 0; i < slots.length; i++) {
5634 UiccSlot slot = slots[i];
5635 if (slot == null) {
5636 continue;
5637 }
5638
5639 String cardId;
5640 UiccCard card = slot.getUiccCard();
5641 if (card != null) {
5642 cardId = card.getCardId();
5643 } else {
5644 cardId = slot.getIccId();
5645 }
5646
5647 int cardState = 0;
5648 switch (slot.getCardState()) {
5649 case CARDSTATE_ABSENT:
5650 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5651 break;
5652 case CARDSTATE_PRESENT:
5653 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5654 break;
5655 case CARDSTATE_ERROR:
5656 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5657 break;
5658 case CARDSTATE_RESTRICTED:
5659 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5660 break;
5661 default:
5662 break;
5663
5664 }
5665
5666 infos[i] = new UiccSlotInfo(
5667 slot.isActive(),
5668 slot.isEuicc(),
5669 cardId,
5670 cardState,
5671 slot.getPhoneId(),
5672 slot.isExtendedApduSupported());
5673 }
5674 return infos;
5675 } finally {
5676 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005677 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005678 }
5679
5680 @Override
5681 public boolean switchSlots(int[] physicalSlots) {
5682 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005683
5684 final long identity = Binder.clearCallingIdentity();
5685 try {
5686 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5687 } finally {
5688 Binder.restoreCallingIdentity(identity);
5689 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005690 }
Jack Yu4c988042018-02-27 15:30:01 -08005691
5692 @Override
5693 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5694 enforceModifyPermission();
5695 final Phone phone = getPhone(subId);
5696 if (phone == null) {
5697 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5698 return;
5699 }
5700
Malcolm Chend965c8b2018-02-28 15:00:40 -08005701 final long identity = Binder.clearCallingIdentity();
5702 try {
5703 phone.setRadioIndicationUpdateMode(filters, mode);
5704 } finally {
5705 Binder.restoreCallingIdentity(identity);
5706 }
Jack Yu4c988042018-02-27 15:30:01 -08005707 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005708
5709 /**
goneil47ffb6e2018-04-06 15:40:58 -07005710 * A test API to reload the UICC profile.
5711 *
5712 * <p>Requires that the calling app has permission
5713 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5714 * @hide
5715 */
5716 @Override
5717 public void refreshUiccProfile(int subId) {
5718 enforceModifyPermission();
5719
5720 final long identity = Binder.clearCallingIdentity();
5721 try {
5722 Phone phone = getPhone(subId);
5723 if (phone == null) {
5724 return;
5725 }
5726 UiccCard uiccCard = phone.getUiccCard();
5727 if (uiccCard == null) {
5728 return;
5729 }
5730 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5731 if (uiccProfile == null) {
5732 return;
5733 }
5734 uiccProfile.refresh();
5735 } finally {
5736 Binder.restoreCallingIdentity(identity);
5737 }
5738 }
5739
5740 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005741 * Returns false if the mobile data is disabled by default, otherwise return true.
5742 */
5743 private boolean getDefaultDataEnabled() {
5744 return "true".equalsIgnoreCase(
5745 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5746 }
5747
5748 /**
5749 * Returns true if the data roaming is enabled by default, i.e the system property
5750 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5751 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5752 */
5753 private boolean getDefaultDataRoamingEnabled(int subId) {
5754 final CarrierConfigManager configMgr = (CarrierConfigManager)
5755 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5756 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5757 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5758 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5759 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5760 return isDataRoamingEnabled;
5761 }
5762
5763 /**
5764 * Returns the default network type for the given {@code subId}, if the default network type is
5765 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5766 */
5767 private int getDefaultNetworkType(int subId) {
5768 return Integer.parseInt(
5769 TelephonyManager.getTelephonyProperty(
5770 mSubscriptionController.getPhoneId(subId),
5771 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5772 String.valueOf(Phone.PREFERRED_NT_MODE)));
5773 }
fionaxua13278b2018-03-21 00:08:13 -07005774
5775 @Override
5776 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5777 gid1, String gid2, String plmn, String spn) {
5778 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005779
5780 final long identity = Binder.clearCallingIdentity();
5781 try {
5782 final Phone phone = getPhone(subId);
5783 if (phone == null) {
5784 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5785 return;
5786 }
5787 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5788 } finally {
5789 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005790 }
fionaxua13278b2018-03-21 00:08:13 -07005791 }
5792
5793 @Override
5794 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005795 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005796
5797 final long identity = Binder.clearCallingIdentity();
5798 try {
5799 final Phone phone = getPhone(subId);
5800 if (phone == null) {
5801 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5802 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5803 }
5804 return phone.getCarrierIdListVersion();
5805 } finally {
5806 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005807 }
fionaxua13278b2018-03-21 00:08:13 -07005808 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005809
5810 @Override
5811 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5812 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5813 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5814 return -1;
5815 }
5816
5817 final long identity = Binder.clearCallingIdentity();
5818 try {
5819 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5820 } finally {
5821 Binder.restoreCallingIdentity(identity);
5822 }
5823 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005824
5825 @Override
5826 public int getCdmaRoamingMode(int subId) {
5827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5828 mApp, subId, "getCdmaRoamingMode");
5829
5830 final long identity = Binder.clearCallingIdentity();
5831 try {
5832 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5833 } finally {
5834 Binder.restoreCallingIdentity(identity);
5835 }
5836 }
5837
5838 @Override
5839 public boolean setCdmaRoamingMode(int subId, int mode) {
5840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5841 mApp, subId, "setCdmaRoamingMode");
5842
5843 final long identity = Binder.clearCallingIdentity();
5844 try {
5845 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5846 } finally {
5847 Binder.restoreCallingIdentity(identity);
5848 }
5849 }
5850
5851 @Override
5852 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5854 mApp, subId, "setCdmaSubscriptionMode");
5855
5856 final long identity = Binder.clearCallingIdentity();
5857 try {
5858 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5859 } finally {
5860 Binder.restoreCallingIdentity(identity);
5861 }
5862 }
chen xu7ee67862018-10-30 22:27:10 -07005863
sqian2fff4a32018-11-05 14:18:37 -08005864 private void ensureUserRunning(int userId) {
5865 if (!mUserManager.isUserRunning(userId)) {
5866 throw new IllegalStateException("User " + userId + " does not exist or not running");
5867 }
5868 }
5869
5870 /**
5871 * Returns a list of SMS apps on a given user.
5872 *
5873 * Only the shell user (UID 2000 or 0) can call it.
5874 * Target user must be running.
5875 */
5876 @Override
5877 public String[] getSmsApps(int userId) {
5878 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5879 ensureUserRunning(userId);
5880
5881 final Collection<SmsApplicationData> apps =
5882 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5883
5884 String[] ret = new String[apps.size()];
5885 int i = 0;
5886 for (SmsApplicationData app : apps) {
5887 ret[i++] = app.mPackageName;
5888 }
5889 return ret;
5890 }
5891
5892 /**
5893 * Returns the default SMS app package name on a given user.
5894 *
5895 * Only the shell user (UID 2000 or 0) can call it.
5896 * Target user must be running.
5897 */
5898 @Override
5899 public String getDefaultSmsApp(int userId) {
5900 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5901 ensureUserRunning(userId);
5902
5903 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5904 /* updateIfNeeded= */ true, userId);
5905 return cn == null ? null : cn.getPackageName();
5906 }
5907
5908 /**
5909 * Set a package as the default SMS app on a given user.
5910 *
5911 * Only the shell user (UID 2000 or 0) can call it.
5912 * Target user must be running.
5913 */
5914 @Override
5915 public void setDefaultSmsApp(int userId, String packageName) {
5916 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5917 ensureUserRunning(userId);
5918
5919 boolean found = false;
5920 for (String pkg : getSmsApps(userId)) {
5921 if (TextUtils.equals(packageName, pkg)) {
5922 found = true;
5923 break;
5924 }
5925 }
5926 if (!found) {
5927 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5928 }
5929
5930 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5931 }
5932
chen xu7ee67862018-10-30 22:27:10 -07005933 @Override
sqian04b86072018-11-07 14:02:21 -08005934 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5935 String callingPackage) {
5936 // TODO connect with internal content
5937 return null;
5938 }
5939
5940 @Override
5941 public boolean isCurrentEmergencyNumber(String number) {
5942 // TODO connect with internal content
5943 return false;
5944 }
5945
5946 @Override
chen xu7ee67862018-10-30 22:27:10 -07005947 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5948 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5949 Phone phone = getPhone(subId);
5950 if (phone == null) {
5951 return null;
5952 }
5953 final long identity = Binder.clearCallingIdentity();
5954 try {
5955 UiccProfile profile = UiccController.getInstance()
5956 .getUiccProfileForPhone(phone.getPhoneId());
5957 if (profile != null) {
5958 return profile.getCertsFromCarrierPrivilegeAccessRules();
5959 }
5960 } finally {
5961 Binder.restoreCallingIdentity(identity);
5962 }
5963 return null;
5964 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005965}