blob: 6418305a5a988c5b2d7bf4f7fa5980f279ab42fc [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 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602 * Returns the unread count of voicemails
2603 */
2604 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002605 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002606 }
2607
2608 /**
2609 * Returns the unread count of voicemails for a subId
2610 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002611 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002612 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 final Phone phone = getPhone(subId);
2616 if (phone != null) {
2617 return phone.getVoiceMessageCount();
2618 } else {
2619 return 0;
2620 }
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002623 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002624 }
2625
2626 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002627 * returns true, if the device is in a state where both voice and data
2628 * are supported simultaneously. This can change based on location or network condition.
2629 */
2630 @Override
2631 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002632 final long identity = Binder.clearCallingIdentity();
2633 try {
2634 final Phone phone = getPhone(subId);
2635 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
2638 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002639 }
2640
2641 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002642 * Send the dialer code if called from the current default dialer or the caller has
2643 * carrier privilege.
2644 * @param inputCode The dialer code to send
2645 */
2646 @Override
2647 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2648 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2649 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2650 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002651 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2652 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002653 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002654
2655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 mPhone.sendDialerSpecialCode(inputCode);
2658 } finally {
2659 Binder.restoreCallingIdentity(identity);
2660 }
fionaxu235cc5e2017-03-06 22:25:57 -08002661 }
2662
2663 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002664 * Returns the data network type.
2665 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 *
2667 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2668 */
2669 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002670 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002671 final long identity = Binder.clearCallingIdentity();
2672 try {
2673 final Phone phone = getPhone(getDefaultSubscription());
2674 if (phone != null) {
2675 return phone.getServiceState().getDataNetworkType();
2676 } else {
2677 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2678 }
2679 } finally {
2680 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002681 }
Wink Saville36469e72014-06-11 15:17:00 -07002682 }
2683
Pengquan Meng0c05b502018-09-06 09:59:22 -07002684 @Override
2685 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002686 if (!isActiveSubscription(subId)) {
2687 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2688 }
2689
Pengquan Meng0c05b502018-09-06 09:59:22 -07002690 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2691 }
2692
Brad Ebinger4c460712018-10-01 10:40:55 -07002693 @Override
2694 public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2695 String callingPackage) throws RemoteException {
2696 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2697 "addImsRegistrationCallback")) {
2698 return;
2699 }
2700 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2701 final long token = Binder.clearCallingIdentity();
2702 try {
2703 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2704 .addRegistrationCallbackForSubscription(c, subId);
2705 } finally {
2706 Binder.restoreCallingIdentity(token);
2707 }
2708 }
2709
2710 @Override
2711 public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2712 String callingPackage) {
2713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2714 "removeImsRegistrationCallback")) {
2715 return;
2716 }
2717 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2718 Binder.withCleanCallingIdentity(() ->
2719 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2720 .removeRegistrationCallbackForSubscription(c, subId));
2721 }
2722
2723 @Override
2724 public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2725 String callingPackage) throws RemoteException {
2726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2727 "addMmTelCapabilityCallback")) {
2728 return;
2729 }
2730 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2731 final long token = Binder.clearCallingIdentity();
2732 try {
2733 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2734 .addCapabilitiesCallbackForSubscription(c, subId);
2735 } finally {
2736 Binder.restoreCallingIdentity(token);
2737 }
2738 }
2739
2740 @Override
2741 public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2742 String callingPackage) {
2743 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2744 "removeMmTelCapabilityCallback")) {
2745 return;
2746 }
2747 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2748 Binder.withCleanCallingIdentity(() ->
2749 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2750 .removeCapabilitiesCallbackForSubscription(c, subId));
2751 }
2752
2753 @Override
2754 public boolean isCapable(int subId, int capability, int regTech, String callingPackage) {
2755 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2756 "isCapable")) {
2757 return false;
2758 }
2759 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2760 final long token = Binder.clearCallingIdentity();
2761 try {
2762 return ImsManager.getInstance(mPhone.getContext(),
2763 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2764 } catch (ImsException e) {
2765 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2766 return false;
2767 } finally {
2768 Binder.restoreCallingIdentity(token);
2769 }
2770 }
2771
2772 @Override
2773 public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) {
2774 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2775 "isAvailable")) {
2776 return false;
2777 }
2778 final long token = Binder.clearCallingIdentity();
2779 try {
2780 Phone phone = getPhone(subId);
2781 if (phone == null) return false;
2782 return phone.isImsCapabilityAvailable(capability, regTech);
2783 } finally {
2784 Binder.restoreCallingIdentity(token);
2785 }
2786 }
2787
2788 @Override
2789 public boolean isAdvancedCallingSettingEnabled(int subId) {
2790 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2791 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2792 final long token = Binder.clearCallingIdentity();
2793 try {
2794 return ImsManager.getInstance(mPhone.getContext(),
2795 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2796 } finally {
2797 Binder.restoreCallingIdentity(token);
2798 }
2799 }
2800
2801 @Override
2802 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2804 "setAdvancedCallingSetting");
2805 final long identity = Binder.clearCallingIdentity();
2806 try {
2807 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2808 ImsManager.getInstance(mPhone.getContext(),
2809 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
2812 }
2813 }
2814
2815 @Override
2816 public boolean isVtSettingEnabled(int subId, String callingPackage) {
2817 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2818 "isVtSettingEnabled")) {
2819 return false;
2820 }
2821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2824 return ImsManager.getInstance(mPhone.getContext(),
2825 getSlotIndexOrException(subId)).isVtEnabledByUser();
2826 } finally {
2827 Binder.restoreCallingIdentity(identity);
2828 }
2829 }
2830
2831 @Override
2832 public void setVtSetting(int subId, boolean isEnabled) {
2833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2834 "setVtSetting");
2835 final long identity = Binder.clearCallingIdentity();
2836 try {
2837 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2838 ImsManager.getInstance(mPhone.getContext(),
2839 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2840 } finally {
2841 Binder.restoreCallingIdentity(identity);
2842 }
2843 }
2844
2845 @Override
2846 public boolean isVoWiFiSettingEnabled(int subId) {
2847 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2851 return ImsManager.getInstance(mPhone.getContext(),
2852 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2853 } finally {
2854 Binder.restoreCallingIdentity(identity);
2855 }
2856 }
2857
2858 @Override
2859 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2861 "setVoWiFiSetting");
2862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2865 ImsManager.getInstance(mPhone.getContext(),
2866 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
2869 }
2870 }
2871
2872 @Override
2873 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2874 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2875 final long identity = Binder.clearCallingIdentity();
2876 try {
2877 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2878 return ImsManager.getInstance(mPhone.getContext(),
2879 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
2882 }
2883 }
2884
2885 @Override
2886 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2888 "setVoWiFiRoamingSetting");
2889 final long identity = Binder.clearCallingIdentity();
2890 try {
2891 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2892 ImsManager.getInstance(mPhone.getContext(),
2893 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2894 } finally {
2895 Binder.restoreCallingIdentity(identity);
2896 }
2897 }
2898
2899 @Override
2900 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2902 "setVoWiFiNonPersistent");
2903 final long identity = Binder.clearCallingIdentity();
2904 try {
2905 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2906 ImsManager.getInstance(mPhone.getContext(),
2907 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2908 } finally {
2909 Binder.restoreCallingIdentity(identity);
2910 }
2911 }
2912
2913 @Override
2914 public int getVoWiFiModeSetting(int subId) {
2915 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2916 final long identity = Binder.clearCallingIdentity();
2917 try {
2918 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2919 return ImsManager.getInstance(mPhone.getContext(),
2920 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
2923 }
2924 }
2925
2926 @Override
2927 public void setVoWiFiModeSetting(int subId, int mode) {
2928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2929 "setVoWiFiModeSetting");
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2933 ImsManager.getInstance(mPhone.getContext(),
2934 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
2937 }
2938 }
2939
2940 @Override
2941 public int getVoWiFiRoamingModeSetting(int subId) {
2942 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2943 final long identity = Binder.clearCallingIdentity();
2944 try {
2945 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2946 return ImsManager.getInstance(mPhone.getContext(),
2947 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2948 } finally {
2949 Binder.restoreCallingIdentity(identity);
2950 }
2951 }
2952
2953 @Override
2954 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2956 "setVoWiFiRoamingModeSetting");
2957 final long identity = Binder.clearCallingIdentity();
2958 try {
2959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2960 ImsManager.getInstance(mPhone.getContext(),
2961 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
2964 }
2965 }
2966
2967 @Override
2968 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2970 "setRttCapabilityEnabled");
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(),
2975 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
2978 }
2979 }
2980
2981 @Override
2982 public boolean isTtyOverVolteEnabled(int subId) {
2983 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2987 return ImsManager.getInstance(mPhone.getContext(),
2988 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
2992 }
2993
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002994 @Override
2995 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2996 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
2997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3000 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3001 .getConfigInterface().addConfigCallback(callback);
3002 } catch (ImsException e) {
3003 throw new IllegalArgumentException(e.getMessage());
3004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
3007 }
3008
3009 @Override
3010 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3011 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3015 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3016 .getConfigInterface().removeConfigCallback(callback);
3017 } catch (ImsException e) {
3018 throw new IllegalArgumentException(e.getMessage());
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
3022 }
3023
3024 @Override
3025 public int getImsProvisioningInt(int subId, int key) {
3026 enforceReadPrivilegedPermission("getImsProvisioningInt");
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3030 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3031 .getConfigInterface().getConfigInt(key);
3032 } catch (ImsException e) {
3033 throw new IllegalArgumentException(e.getMessage());
3034 } finally {
3035 Binder.restoreCallingIdentity(identity);
3036 }
3037 }
3038
3039 @Override
3040 public String getImsProvisioningString(int subId, int key) {
3041 enforceReadPrivilegedPermission("getImsProvisioningString");
3042 final long identity = Binder.clearCallingIdentity();
3043 try {
3044 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3045 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3046 .getConfigInterface().getConfigString(key);
3047 } catch (ImsException e) {
3048 throw new IllegalArgumentException(e.getMessage());
3049 } finally {
3050 Binder.restoreCallingIdentity(identity);
3051 }
3052 }
3053
3054 @Override
3055 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3057 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003058 final long identity = Binder.clearCallingIdentity();
3059 try {
3060 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3061 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3062 .getConfigInterface().setConfig(key, value);
3063 } catch (ImsException e) {
3064 throw new IllegalArgumentException(e.getMessage());
3065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
3068 }
3069
3070 @Override
3071 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3073 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3077 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3078 .getConfigInterface().setConfig(key, value);
3079 } catch (ImsException e) {
3080 throw new IllegalArgumentException(e.getMessage());
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
3083 }
3084 }
3085
Brad Ebinger4c460712018-10-01 10:40:55 -07003086 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3087 int slotId = SubscriptionManager.getSlotIndex(subId);
3088 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3089 throw new IllegalArgumentException("Invalid Subscription Id.");
3090 }
3091 return slotId;
3092 }
3093
Wink Saville36469e72014-06-11 15:17:00 -07003094 /**
3095 * Returns the network type for a subId
3096 */
3097 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003098 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003100 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003101 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3102 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003103
Malcolm Chend965c8b2018-02-28 15:00:40 -08003104 final long identity = Binder.clearCallingIdentity();
3105 try {
3106 final Phone phone = getPhone(subId);
3107 if (phone != null) {
3108 return phone.getServiceState().getDataNetworkType();
3109 } else {
3110 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3111 }
3112 } finally {
3113 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003115 }
3116
3117 /**
3118 * Returns the data network type
3119 */
3120 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003121 public int getDataNetworkType(String callingPackage) {
3122 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003123 }
3124
3125 /**
3126 * Returns the data network type for a subId
3127 */
3128 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003129 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003131 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003132 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3133 }
3134
Malcolm Chend965c8b2018-02-28 15:00:40 -08003135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 final Phone phone = getPhone(subId);
3138 if (phone != null) {
3139 return phone.getServiceState().getDataNetworkType();
3140 } else {
3141 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3142 }
3143 } finally {
3144 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003145 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003146 }
3147
3148 /**
Wink Saville36469e72014-06-11 15:17:00 -07003149 * Returns the Voice network type for a subId
3150 */
3151 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003152 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003154 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003155 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3156 }
3157
Malcolm Chend965c8b2018-02-28 15:00:40 -08003158 final long identity = Binder.clearCallingIdentity();
3159 try {
3160 final Phone phone = getPhone(subId);
3161 if (phone != null) {
3162 return phone.getServiceState().getVoiceNetworkType();
3163 } else {
3164 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3165 }
3166 } finally {
3167 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003169 }
3170
3171 /**
3172 * @return true if a ICC card is present
3173 */
3174 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003175 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003176 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3177 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003178 }
3179
3180 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003181 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003182 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003183 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003184 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 final Phone phone = PhoneFactory.getPhone(slotIndex);
3188 if (phone != null) {
3189 return phone.getIccCard().hasIccCard();
3190 } else {
3191 return false;
3192 }
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 }
3197
3198 /**
3199 * Return if the current radio is LTE on CDMA. This
3200 * is a tri-state return value as for a period of time
3201 * the mode may be unknown.
3202 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003203 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003205 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003206 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003207 @Override
3208 public int getLteOnCdmaMode(String callingPackage) {
3209 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003210 }
3211
Sanket Padawe356d7632015-06-22 14:03:32 -07003212 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003213 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003215 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003216 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3217 }
3218
Malcolm Chend965c8b2018-02-28 15:00:40 -08003219 final long identity = Binder.clearCallingIdentity();
3220 try {
3221 final Phone phone = getPhone(subId);
3222 if (phone == null) {
3223 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3224 } else {
3225 return phone.getLteOnCdmaMode();
3226 }
3227 } finally {
3228 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003229 }
Wink Saville36469e72014-06-11 15:17:00 -07003230 }
3231
3232 public void setPhone(Phone phone) {
3233 mPhone = phone;
3234 }
3235
3236 /**
3237 * {@hide}
3238 * Returns Default subId, 0 in the case of single standby.
3239 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003240 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003241 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003242 }
3243
Shishir Agrawala9f32182016-04-12 12:00:16 -07003244 private int getSlotForDefaultSubscription() {
3245 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3246 }
3247
Wink Savilleb564aae2014-10-23 10:18:09 -07003248 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003249 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003250 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003251
Pengquan Meng466e2482018-09-21 15:54:48 -07003252 private boolean isActiveSubscription(int subId) {
3253 return mSubscriptionController.isActiveSubId(subId);
3254 }
3255
Ihab Awadf2177b72013-11-25 13:33:23 -08003256 /**
3257 * @see android.telephony.TelephonyManager.WifiCallingChoices
3258 */
3259 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003260 final long identity = Binder.clearCallingIdentity();
3261 try {
3262 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3263 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3264 getWhenToMakeWifiCallsDefaultPreference());
3265 } finally {
3266 Binder.restoreCallingIdentity(identity);
3267 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003268 }
3269
3270 /**
3271 * @see android.telephony.TelephonyManager.WifiCallingChoices
3272 */
3273 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003274 final long identity = Binder.clearCallingIdentity();
3275 try {
3276 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3277 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3278 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3279 } finally {
3280 Binder.restoreCallingIdentity(identity);
3281 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003282 }
3283
Sailesh Nepald1e68152013-12-12 19:08:02 -08003284 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003285 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003286 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003287 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003288
Shishir Agrawal566b7612013-10-28 14:41:00 -07003289 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003290 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3291 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3293 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003294 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003295
Malcolm Chend965c8b2018-02-28 15:00:40 -08003296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 if (TextUtils.equals(ISDR_AID, aid)) {
3299 // Only allows LPA to open logical channel to ISD-R.
3300 ComponentInfo bestComponent =
3301 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3302 if (bestComponent == null
3303 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3304 loge("The calling package is not allowed to access ISD-R.");
3305 throw new SecurityException(
3306 "The calling package is not allowed to access ISD-R.");
3307 }
Derek Tan740e1672017-06-27 14:56:27 -07003308 }
Derek Tan740e1672017-06-27 14:56:27 -07003309
Malcolm Chend965c8b2018-02-28 15:00:40 -08003310 if (DBG) {
3311 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3312 }
3313 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3314 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3315 if (DBG) log("iccOpenLogicalChannel: " + response);
3316 return response;
3317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003320 }
3321
3322 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003323 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3325 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003326
Malcolm Chend965c8b2018-02-28 15:00:40 -08003327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3330 if (channel < 0) {
3331 return false;
3332 }
3333 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3334 if (DBG) log("iccCloseLogicalChannel: " + success);
3335 return success;
3336 } finally {
3337 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003338 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003339 }
3340
3341 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003342 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003343 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3345 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003346
Malcolm Chend965c8b2018-02-28 15:00:40 -08003347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 if (DBG) {
3350 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3351 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3352 + p3 + " data=" + data);
3353 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003354
Malcolm Chend965c8b2018-02-28 15:00:40 -08003355 if (channel < 0) {
3356 return "";
3357 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003358
Malcolm Chend965c8b2018-02-28 15:00:40 -08003359 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3360 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3361 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003362
Malcolm Chend965c8b2018-02-28 15:00:40 -08003363 // Append the returned status code to the end of the response payload.
3364 String s = Integer.toHexString(
3365 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3366 if (response.payload != null) {
3367 s = IccUtils.bytesToHexString(response.payload) + s;
3368 }
3369 return s;
3370 } finally {
3371 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003372 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003373 }
Jake Hambye994d462014-02-03 13:10:13 -08003374
Evan Charltonc66da362014-05-16 14:06:40 -07003375 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003376 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3377 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3379 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003380 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003381
Malcolm Chend965c8b2018-02-28 15:00:40 -08003382 final long identity = Binder.clearCallingIdentity();
3383 try {
3384 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3385 && TextUtils.equals(ISDR_AID, data)) {
3386 // Only allows LPA to select ISD-R.
3387 ComponentInfo bestComponent =
3388 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3389 if (bestComponent == null
3390 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3391 loge("The calling package is not allowed to select ISD-R.");
3392 throw new SecurityException(
3393 "The calling package is not allowed to select ISD-R.");
3394 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003395 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003396
Malcolm Chend965c8b2018-02-28 15:00:40 -08003397 if (DBG) {
3398 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3399 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3400 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003401
Malcolm Chend965c8b2018-02-28 15:00:40 -08003402 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3403 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3404 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003405
Malcolm Chend965c8b2018-02-28 15:00:40 -08003406 // Append the returned status code to the end of the response payload.
3407 String s = Integer.toHexString(
3408 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3409 if (response.payload != null) {
3410 s = IccUtils.bytesToHexString(response.payload) + s;
3411 }
3412 return s;
3413 } finally {
3414 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003415 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003416 }
3417
3418 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003419 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003420 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3422 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003423
Malcolm Chend965c8b2018-02-28 15:00:40 -08003424 final long identity = Binder.clearCallingIdentity();
3425 try {
3426 if (DBG) {
3427 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3428 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3429 }
3430
3431 IccIoResult response =
3432 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3433 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3434 subId);
3435
3436 if (DBG) {
3437 log("Exchange SIM_IO [R]" + response);
3438 }
3439
3440 byte[] result = null;
3441 int length = 2;
3442 if (response.payload != null) {
3443 length = 2 + response.payload.length;
3444 result = new byte[length];
3445 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3446 } else {
3447 result = new byte[length];
3448 }
3449
3450 result[length - 1] = (byte) response.sw2;
3451 result[length - 2] = (byte) response.sw1;
3452 return result;
3453 } finally {
3454 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003455 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003456 }
3457
Nathan Haroldb3014052017-01-25 15:57:32 -08003458 /**
3459 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3460 * on a particular subscription
3461 */
sqianb6e41952018-03-12 14:54:01 -07003462 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3464 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3465 return null;
3466 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003467
3468 final long identity = Binder.clearCallingIdentity();
3469 try {
3470 if (appType != TelephonyManager.APPTYPE_USIM
3471 && appType != TelephonyManager.APPTYPE_SIM) {
3472 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3473 return null;
3474 }
3475 Object response = sendRequest(
3476 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3477 if (response instanceof String[]) {
3478 return (String[]) response;
3479 }
3480 // Response is an Exception of some kind,
3481 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003482 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003483 } finally {
3484 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003485 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003486 }
3487
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003488 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003489 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3491 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003492
Malcolm Chend965c8b2018-02-28 15:00:40 -08003493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3496 if (response.payload == null) {
3497 return "";
3498 }
Evan Charltonc66da362014-05-16 14:06:40 -07003499
Malcolm Chend965c8b2018-02-28 15:00:40 -08003500 // Append the returned status code to the end of the response payload.
3501 String s = Integer.toHexString(
3502 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3503 s = IccUtils.bytesToHexString(response.payload) + s;
3504 return s;
3505 } finally {
3506 Binder.restoreCallingIdentity(identity);
3507 }
Evan Charltonc66da362014-05-16 14:06:40 -07003508 }
3509
Jake Hambye994d462014-02-03 13:10:13 -08003510 /**
3511 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3512 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3513 *
3514 * @param itemID the ID of the item to read
3515 * @return the NV item as a String, or null on error.
3516 */
3517 @Override
3518 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003519 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3521 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003522
3523 final long identity = Binder.clearCallingIdentity();
3524 try {
3525 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003526 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003527 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3528 return value;
3529 } finally {
3530 Binder.restoreCallingIdentity(identity);
3531 }
Jake Hambye994d462014-02-03 13:10:13 -08003532 }
3533
3534 /**
3535 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3536 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3537 *
3538 * @param itemID the ID of the item to read
3539 * @param itemValue the value to write, as a String
3540 * @return true on success; false on any failure
3541 */
3542 @Override
3543 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003544 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3546 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003547
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3551 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003552 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003553 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3554 return success;
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
Jake Hambye994d462014-02-03 13:10:13 -08003558 }
3559
3560 /**
3561 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3562 * Used for device configuration by some CDMA operators.
3563 *
3564 * @param preferredRoamingList byte array containing the new PRL
3565 * @return true on success; false on any failure
3566 */
3567 @Override
3568 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3570 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003571
3572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3575 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3576 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3577 return success;
3578 } finally {
3579 Binder.restoreCallingIdentity(identity);
3580 }
Jake Hambye994d462014-02-03 13:10:13 -08003581 }
3582
3583 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003584 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003585 * Used for device configuration by some CDMA operators.
3586 *
chen xu1cc0abe2018-10-26 17:39:23 -07003587 * @param slotIndex - device slot.
3588 *
Jake Hambye994d462014-02-03 13:10:13 -08003589 * @return true on success; false on any failure
3590 */
3591 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003592 public boolean resetModemConfig(int slotIndex) {
3593 Phone phone = PhoneFactory.getPhone(slotIndex);
3594 if (phone != null) {
3595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3596 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003597
chen xu1cc0abe2018-10-26 17:39:23 -07003598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3601 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3602 return success;
3603 } finally {
3604 Binder.restoreCallingIdentity(identity);
3605 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003606 }
chen xu1cc0abe2018-10-26 17:39:23 -07003607 return false;
3608 }
3609
3610 /**
3611 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3612 *
3613 * @param slotIndex - device slot.
3614 *
3615 * @return true on success; false on any failure
3616 */
3617 @Override
3618 public boolean rebootModem(int slotIndex) {
3619 Phone phone = PhoneFactory.getPhone(slotIndex);
3620 if (phone != null) {
3621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3622 mApp, phone.getSubId(), "rebootModem");
3623
3624 final long identity = Binder.clearCallingIdentity();
3625 try {
3626 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3627 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3628 return success;
3629 } finally {
3630 Binder.restoreCallingIdentity(identity);
3631 }
3632 }
3633 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003634 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003635
Svet Ganovb320e182015-04-16 12:30:10 -07003636 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003637 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003638 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003639 return new String[0];
3640 }
3641
Malcolm Chend965c8b2018-02-28 15:00:40 -08003642 final long identity = Binder.clearCallingIdentity();
3643 try {
3644 return mPhone.getPcscfAddress(apnType);
3645 } finally {
3646 Binder.restoreCallingIdentity(identity);
3647 }
Wink Saville36469e72014-06-11 15:17:00 -07003648 }
3649
Brad Ebinger51f743a2017-01-23 13:50:20 -08003650 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003651 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3652 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003653 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003654 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003655 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003656
3657 final long identity = Binder.clearCallingIdentity();
3658 try {
3659 PhoneFactory.getImsResolver().enableIms(slotId);
3660 } finally {
3661 Binder.restoreCallingIdentity(identity);
3662 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003663 }
3664
3665 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003666 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3667 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003668 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003669 public void disableIms(int slotId) {
3670 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003671
3672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 PhoneFactory.getImsResolver().disableIms(slotId);
3675 } finally {
3676 Binder.restoreCallingIdentity(identity);
3677 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003678 }
3679
3680 /**
3681 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3682 * feature or {@link null} if the service is not available. If the feature is available, the
3683 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3684 */
3685 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003686 IImsServiceFeatureCallback callback) {
3687 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003688
3689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3692 } finally {
3693 Binder.restoreCallingIdentity(identity);
3694 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003695 }
3696
3697 /**
3698 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3699 * feature during emergency calling or {@link null} if the service is not available. If the
3700 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3701 * listener for feature updates.
3702 */
3703 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3704 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003705
3706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3709 } finally {
3710 Binder.restoreCallingIdentity(identity);
3711 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003712 }
3713
Brad Ebinger5f64b052017-12-14 14:26:15 -08003714 /**
3715 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3716 * specified.
3717 */
3718 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3719 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003720
3721 final long identity = Binder.clearCallingIdentity();
3722 try {
3723 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3724 } finally {
3725 Binder.restoreCallingIdentity(identity);
3726 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003727 }
3728
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003729 /**
3730 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3731 * specified.
3732 */
3733 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3734 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003735
3736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3739 } finally {
3740 Binder.restoreCallingIdentity(identity);
3741 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003742 }
3743
Brad Ebinger884c07b2018-02-15 16:17:40 -08003744 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003745 * Sets the ImsService Package Name that Telephony will bind to.
3746 *
3747 * @param slotId the slot ID that the ImsService should bind for.
3748 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3749 * ImsService is the device default ImsService.
3750 * @param packageName The package name of the application that contains the ImsService to bind
3751 * to.
3752 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3753 * @hide
3754 */
3755 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003756 int[] subIds = SubscriptionManager.getSubId(slotId);
3757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3758 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3759 "setImsService");
3760
Malcolm Chend965c8b2018-02-28 15:00:40 -08003761 final long identity = Binder.clearCallingIdentity();
3762 try {
3763 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3764 isCarrierImsService, packageName);
3765 } finally {
3766 Binder.restoreCallingIdentity(identity);
3767 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003768 }
3769
3770 /**
3771 * Return the ImsService configuration.
3772 *
3773 * @param slotId The slot that the ImsService is associated with.
3774 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3775 * the device default.
3776 * @return the package name of the ImsService configuration.
3777 */
3778 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003779 int[] subIds = SubscriptionManager.getSubId(slotId);
3780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3781 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3782 "getImsService");
3783
Malcolm Chend965c8b2018-02-28 15:00:40 -08003784 final long identity = Binder.clearCallingIdentity();
3785 try {
3786 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3787 isCarrierImsService);
3788 } finally {
3789 Binder.restoreCallingIdentity(identity);
3790 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003791 }
3792
Wink Saville36469e72014-06-11 15:17:00 -07003793 public void setImsRegistrationState(boolean registered) {
3794 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003795
3796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 mPhone.setImsRegistrationState(registered);
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
3801 }
Wink Saville36469e72014-06-11 15:17:00 -07003802 }
3803
3804 /**
Stuart Scott54788802015-03-30 13:18:01 -07003805 * Set the network selection mode to automatic.
3806 *
3807 */
3808 @Override
3809 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3811 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003812
Pengquan Meng466e2482018-09-21 15:54:48 -07003813 if (!isActiveSubscription(subId)) {
3814 return;
3815 }
3816
Malcolm Chend965c8b2018-02-28 15:00:40 -08003817 final long identity = Binder.clearCallingIdentity();
3818 try {
3819 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3820 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3821 } finally {
3822 Binder.restoreCallingIdentity(identity);
3823 }
Stuart Scott54788802015-03-30 13:18:01 -07003824 }
3825
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003826 /**
3827 * Ask the radio to connect to the input network and change selection mode to manual.
3828 *
3829 * @param subId the id of the subscription.
3830 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3831 * the operator to attach to.
3832 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3833 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3834 * normal network selection next time.
3835 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003836 */
3837 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003838 public boolean setNetworkSelectionModeManual(
3839 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3841 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003842
3843 if (!isActiveSubscription(subId)) {
3844 return false;
3845 }
3846
Malcolm Chend965c8b2018-02-28 15:00:40 -08003847 final long identity = Binder.clearCallingIdentity();
3848 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003849 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003850 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003851 if (DBG) {
3852 log("setNetworkSelectionModeManual: subId: " + subId
3853 + " operator: " + operatorInfo);
3854 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003855 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3856 } finally {
3857 Binder.restoreCallingIdentity(identity);
3858 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003859 }
3860
3861 /**
3862 * Scans for available networks.
3863 */
3864 @Override
3865 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3867 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003868
Pengquan Meng0c05b502018-09-06 09:59:22 -07003869 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003870 try {
3871 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003872 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003873 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003874 } finally {
3875 Binder.restoreCallingIdentity(identity);
3876 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003877 }
3878
3879 /**
yinxub1bed742017-04-17 11:45:04 -07003880 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003881 *
yinxub1bed742017-04-17 11:45:04 -07003882 * @param subId id of the subscription
3883 * @param request contains the radio access networks with bands/channels to scan
3884 * @param messenger callback messenger for scan results or errors
3885 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003886 * @return the id of the requested scan which can be used to stop the scan.
3887 */
3888 @Override
3889 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3890 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3892 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003893
3894 final long identity = Binder.clearCallingIdentity();
3895 try {
3896 return mNetworkScanRequestTracker.startNetworkScan(
3897 request, messenger, binder, getPhone(subId));
3898 } finally {
3899 Binder.restoreCallingIdentity(identity);
3900 }
yinxu504e1392017-04-12 16:03:22 -07003901 }
3902
3903 /**
3904 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003905 *
3906 * @param subId id of the subscription
3907 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003908 */
3909 @Override
3910 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3912 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003913
3914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3917 } finally {
3918 Binder.restoreCallingIdentity(identity);
3919 }
yinxu504e1392017-04-12 16:03:22 -07003920 }
3921
3922 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003923 * Get the calculated preferred network type.
3924 * Used for debugging incorrect network type.
3925 *
3926 * @return the preferred network type, defined in RILConstants.java.
3927 */
3928 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003929 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003931 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003932 return RILConstants.PREFERRED_NETWORK_MODE;
3933 }
3934
Malcolm Chend965c8b2018-02-28 15:00:40 -08003935 final long identity = Binder.clearCallingIdentity();
3936 try {
3937 // FIXME: need to get SubId from somewhere.
3938 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3939 } finally {
3940 Binder.restoreCallingIdentity(identity);
3941 }
Junda Liu84d15a22014-07-02 11:21:04 -07003942 }
3943
3944 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003945 * Get the preferred network type.
3946 * Used for device configuration by some CDMA operators.
3947 *
3948 * @return the preferred network type, defined in RILConstants.java.
3949 */
3950 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003951 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3953 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003954
3955 final long identity = Binder.clearCallingIdentity();
3956 try {
3957 if (DBG) log("getPreferredNetworkType");
3958 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3959 int networkType = (result != null ? result[0] : -1);
3960 if (DBG) log("getPreferredNetworkType: " + networkType);
3961 return networkType;
3962 } finally {
3963 Binder.restoreCallingIdentity(identity);
3964 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003965 }
3966
3967 /**
3968 * Set the preferred network type.
3969 * Used for device configuration by some CDMA operators.
3970 *
3971 * @param networkType the preferred network type, defined in RILConstants.java.
3972 * @return true on success; false on any failure.
3973 */
3974 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003975 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3977 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003978
3979 final long identity = Binder.clearCallingIdentity();
3980 try {
3981 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3982 Boolean success = (Boolean) sendRequest(
3983 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3984 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3985 if (success) {
3986 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3987 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3988 }
3989 return success;
3990 } finally {
3991 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003992 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003993 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003994
3995 /**
Junda Liu475951f2014-11-07 16:45:03 -08003996 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07003997 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003998 * tethering.
3999 *
4000 * @return 0: Not required. 1: required. 2: Not set.
4001 * @hide
4002 */
4003 @Override
4004 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004005 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004006
4007 final long identity = Binder.clearCallingIdentity();
4008 try {
4009 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
4010 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004011 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Malcolm Chend965c8b2018-02-28 15:00:40 -08004012 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
4013 dunRequired = 1;
4014 }
4015 return dunRequired;
4016 } finally {
4017 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004018 }
Junda Liu475951f2014-11-07 16:45:03 -08004019 }
4020
4021 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004022 * Set mobile data enabled
4023 * Used by the user through settings etc to turn on/off mobile data
4024 *
4025 * @param enable {@code true} turn turn data on, else {@code false}
4026 */
4027 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004028 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4030 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004031
4032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 int phoneId = mSubscriptionController.getPhoneId(subId);
4035 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4036 Phone phone = PhoneFactory.getPhone(phoneId);
4037 if (phone != null) {
4038 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
4039 phone.setUserDataEnabled(enable);
4040 } else {
4041 loge("setUserDataEnabled: no phone for subId=" + subId);
4042 }
4043 } finally {
4044 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004045 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004046 }
4047
4048 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004049 * Get the user enabled state of Mobile Data.
4050 *
4051 * TODO: remove and use isUserDataEnabled.
4052 * This can't be removed now because some vendor codes
4053 * calls through ITelephony directly while they should
4054 * use TelephonyManager.
4055 *
4056 * @return true on enabled
4057 */
4058 @Override
4059 public boolean getDataEnabled(int subId) {
4060 return isUserDataEnabled(subId);
4061 }
4062
4063 /**
4064 * Get whether mobile data is enabled per user setting.
4065 *
4066 * There are other factors deciding whether mobile data is actually enabled, but they are
4067 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004068 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004069 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004070 *
4071 * @return {@code true} if data is enabled else {@code false}
4072 */
4073 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004074 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004075 try {
4076 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4077 null);
4078 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4080 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004081 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004082
4083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 int phoneId = mSubscriptionController.getPhoneId(subId);
4086 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4087 Phone phone = PhoneFactory.getPhone(phoneId);
4088 if (phone != null) {
4089 boolean retVal = phone.isUserDataEnabled();
4090 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4091 return retVal;
4092 } else {
4093 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4094 return false;
4095 }
4096 } finally {
4097 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004098 }
4099 }
4100
4101 /**
4102 * Get whether mobile data is enabled.
4103 *
4104 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4105 * whether mobile data is actually enabled.
4106 *
4107 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4108 *
4109 * @return {@code true} if data is enabled else {@code false}
4110 */
4111 @Override
4112 public boolean isDataEnabled(int subId) {
4113 try {
4114 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4115 null);
4116 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4118 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004119 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004120
4121 final long identity = Binder.clearCallingIdentity();
4122 try {
4123 int phoneId = mSubscriptionController.getPhoneId(subId);
4124 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4125 Phone phone = PhoneFactory.getPhone(phoneId);
4126 if (phone != null) {
4127 boolean retVal = phone.isDataEnabled();
4128 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4129 return retVal;
4130 } else {
4131 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4132 return false;
4133 }
4134 } finally {
4135 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004136 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004137 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004138
4139 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004140 public int getCarrierPrivilegeStatus(int subId) {
4141 final Phone phone = getPhone(subId);
4142 if (phone == null) {
4143 loge("getCarrierPrivilegeStatus: Invalid subId");
4144 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4145 }
4146 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004147 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004148 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004149 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4150 }
4151 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004152 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004153 }
Junda Liu29340342014-07-10 15:23:27 -07004154
4155 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004156 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4157 final Phone phone = getPhone(subId);
4158 if (phone == null) {
4159 loge("getCarrierPrivilegeStatus: Invalid subId");
4160 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4161 }
4162 UiccProfile profile =
4163 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4164 if (profile == null) {
4165 loge("getCarrierPrivilegeStatus: No UICC");
4166 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4167 }
4168 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4169 }
4170
4171 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004172 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004173 if (TextUtils.isEmpty(pkgName))
4174 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08004175 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004176 if (card == null) {
4177 loge("checkCarrierPrivilegesForPackage: No UICC");
4178 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4179 }
Zach Johnson50ecba32015-05-19 00:24:21 -07004180 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
4181 }
4182
4183 @Override
4184 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004185 if (TextUtils.isEmpty(pkgName))
4186 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004187 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4188 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4189 UiccCard card = UiccController.getInstance().getUiccCard(i);
4190 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004191 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004192 continue;
4193 }
4194
4195 result = card.getCarrierPrivilegeStatus(
4196 mPhone.getContext().getPackageManager(), pkgName);
4197 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4198 break;
4199 }
4200 }
4201
4202 return result;
Junda Liu29340342014-07-10 15:23:27 -07004203 }
Derek Tan89e89d42014-07-08 17:00:10 -07004204
4205 @Override
Junda Liue64de782015-04-16 17:19:16 -07004206 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4207 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4208 loge("phoneId " + phoneId + " is not valid.");
4209 return null;
4210 }
4211 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004212 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004213 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004214 return null ;
4215 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004216 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004217 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004218 }
4219
Amith Yamasani6e118872016-02-19 12:53:51 -08004220 @Override
4221 public List<String> getPackagesWithCarrierPrivileges() {
4222 PackageManager pm = mPhone.getContext().getPackageManager();
4223 List<String> privilegedPackages = new ArrayList<>();
4224 List<PackageInfo> packages = null;
4225 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4226 UiccCard card = UiccController.getInstance().getUiccCard(i);
4227 if (card == null) {
4228 // No UICC in that slot.
4229 continue;
4230 }
4231 if (card.hasCarrierPrivilegeRules()) {
4232 if (packages == null) {
4233 // Only check packages in user 0 for now
4234 packages = pm.getInstalledPackagesAsUser(
4235 PackageManager.MATCH_DISABLED_COMPONENTS
4236 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4237 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4238 }
4239 for (int p = packages.size() - 1; p >= 0; p--) {
4240 PackageInfo pkgInfo = packages.get(p);
4241 if (pkgInfo != null && pkgInfo.packageName != null
4242 && card.getCarrierPrivilegeStatus(pkgInfo)
4243 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4244 privilegedPackages.add(pkgInfo.packageName);
4245 }
4246 }
4247 }
4248 }
4249 return privilegedPackages;
4250 }
4251
Wink Savilleb564aae2014-10-23 10:18:09 -07004252 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004253 final Phone phone = getPhone(subId);
4254 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004255 if (card == null) {
4256 loge("getIccId: No UICC");
4257 return null;
4258 }
4259 String iccId = card.getIccId();
4260 if (TextUtils.isEmpty(iccId)) {
4261 loge("getIccId: ICC ID is null or empty.");
4262 return null;
4263 }
4264 return iccId;
4265 }
4266
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004267 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004268 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4269 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004270 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4271 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004272
Malcolm Chend965c8b2018-02-28 15:00:40 -08004273 final long identity = Binder.clearCallingIdentity();
4274 try {
4275 final String iccId = getIccId(subId);
4276 final Phone phone = getPhone(subId);
4277 if (phone == null) {
4278 return false;
4279 }
4280 final String subscriberId = phone.getSubscriberId();
4281
4282 if (DBG_MERGE) {
4283 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4284 + subscriberId + " to " + number);
4285 }
4286
4287 if (TextUtils.isEmpty(iccId)) {
4288 return false;
4289 }
4290
4291 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4292
4293 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4294 if (alphaTag == null) {
4295 editor.remove(alphaTagPrefKey);
4296 } else {
4297 editor.putString(alphaTagPrefKey, alphaTag);
4298 }
4299
4300 // Record both the line number and IMSI for this ICCID, since we need to
4301 // track all merged IMSIs based on line number
4302 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4303 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4304 if (number == null) {
4305 editor.remove(numberPrefKey);
4306 editor.remove(subscriberPrefKey);
4307 } else {
4308 editor.putString(numberPrefKey, number);
4309 editor.putString(subscriberPrefKey, subscriberId);
4310 }
4311
4312 editor.commit();
4313 return true;
4314 } finally {
4315 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004316 }
Derek Tan7226c842014-07-02 17:42:23 -07004317 }
4318
4319 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004320 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004321 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004323 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004324 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004325 return null;
4326 }
Derek Tan97ebb422014-09-05 16:55:38 -07004327
Malcolm Chend965c8b2018-02-28 15:00:40 -08004328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 String iccId = getIccId(subId);
4331 if (iccId != null) {
4332 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4333 if (DBG_MERGE) {
4334 log("getLine1NumberForDisplay returning "
4335 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4336 }
4337 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004338 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004339 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4340 return null;
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004343 }
Derek Tan7226c842014-07-02 17:42:23 -07004344 }
4345
4346 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004347 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004348 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004349 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004350 return null;
4351 }
Derek Tan97ebb422014-09-05 16:55:38 -07004352
Malcolm Chend965c8b2018-02-28 15:00:40 -08004353 final long identity = Binder.clearCallingIdentity();
4354 try {
4355 String iccId = getIccId(subId);
4356 if (iccId != null) {
4357 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4358 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4359 }
4360 return null;
4361 } finally {
4362 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004363 }
Derek Tan7226c842014-07-02 17:42:23 -07004364 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004365
4366 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004367 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004368 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4369 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004371 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4372 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004373 return null;
4374 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004375
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004376 final long identity = Binder.clearCallingIdentity();
4377 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004378 final Context context = mPhone.getContext();
4379 final TelephonyManager tele = TelephonyManager.from(context);
4380 final SubscriptionManager sub = SubscriptionManager.from(context);
4381
4382 // Figure out what subscribers are currently active
4383 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4384 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4385 // the process, where TelephonyManager was instantiated.
4386 // Otherwise AppOps check will fail.
4387
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004388 final int[] subIds = sub.getActiveSubscriptionIdList();
4389 for (int subId : subIds) {
4390 activeSubscriberIds.add(tele.getSubscriberId(subId));
4391 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004392
4393 // First pass, find a number override for an active subscriber
4394 String mergeNumber = null;
4395 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4396 for (String key : prefs.keySet()) {
4397 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4398 final String subscriberId = (String) prefs.get(key);
4399 if (activeSubscriberIds.contains(subscriberId)) {
4400 final String iccId = key.substring(
4401 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4402 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4403 mergeNumber = (String) prefs.get(numberKey);
4404 if (DBG_MERGE) {
4405 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4406 + " for active subscriber " + subscriberId);
4407 }
4408 if (!TextUtils.isEmpty(mergeNumber)) {
4409 break;
4410 }
4411 }
4412 }
4413 }
4414
4415 // Shortcut when no active merged subscribers
4416 if (TextUtils.isEmpty(mergeNumber)) {
4417 return null;
4418 }
4419
4420 // Second pass, find all subscribers under that line override
4421 final ArraySet<String> result = new ArraySet<>();
4422 for (String key : prefs.keySet()) {
4423 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4424 final String number = (String) prefs.get(key);
4425 if (mergeNumber.equals(number)) {
4426 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4427 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4428 final String subscriberId = (String) prefs.get(subscriberKey);
4429 if (!TextUtils.isEmpty(subscriberId)) {
4430 result.add(subscriberId);
4431 }
4432 }
4433 }
4434 }
4435
4436 final String[] resultArray = result.toArray(new String[result.size()]);
4437 Arrays.sort(resultArray);
4438 if (DBG_MERGE) {
4439 Slog.d(LOG_TAG,
4440 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4441 }
4442 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004443 } finally {
4444 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004445 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004446 }
4447
4448 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004449 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004450 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4451 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004452
4453 final long identity = Binder.clearCallingIdentity();
4454 try {
4455 final Phone phone = getPhone(subId);
4456 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4457 } finally {
4458 Binder.restoreCallingIdentity(identity);
4459 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004460 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004461
4462 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004463 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004464 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4465 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004466 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004467
4468 final long identity = Binder.clearCallingIdentity();
4469 try {
4470 final Phone phone = getPhone(subId);
4471 if (phone == null) {
4472 return false;
4473 }
4474 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4475 cdmaNonRoamingList);
4476 } finally {
4477 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004478 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004479 }
4480
4481 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004482 @Deprecated
4483 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4484 enforceModifyPermission();
4485
4486 int returnValue = 0;
4487 try {
vagdevie435a3e2018-08-15 16:01:53 -07004488 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004489 if(result.exception == null) {
4490 if (result.result != null) {
4491 byte[] responseData = (byte[])(result.result);
4492 if(responseData.length > oemResp.length) {
4493 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4494 responseData.length + "bytes. Buffer Size is " +
4495 oemResp.length + "bytes.");
4496 }
4497 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4498 returnValue = responseData.length;
4499 }
4500 } else {
4501 CommandException ex = (CommandException) result.exception;
4502 returnValue = ex.getCommandError().ordinal();
4503 if(returnValue > 0) returnValue *= -1;
4504 }
4505 } catch (RuntimeException e) {
4506 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4507 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4508 if(returnValue > 0) returnValue *= -1;
4509 }
4510
4511 return returnValue;
4512 }
4513
4514 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004515 public void setRadioCapability(RadioAccessFamily[] rafs) {
4516 try {
4517 ProxyController.getInstance().setRadioCapability(rafs);
4518 } catch (RuntimeException e) {
4519 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4520 }
4521 }
4522
4523 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004524 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004525 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004526 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004527 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004528 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004529 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004530 final long identity = Binder.clearCallingIdentity();
4531 try {
chen xufeeed752018-10-26 14:17:57 -07004532 TelephonyPermissions
4533 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4534 mApp, phone.getSubId(), "getRadioAccessFamily");
4535 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004536 } finally {
4537 Binder.restoreCallingIdentity(identity);
4538 }
chen xufeeed752018-10-26 14:17:57 -07004539 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004540 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004541
4542 @Override
4543 public void enableVideoCalling(boolean enable) {
4544 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004545
4546 final long identity = Binder.clearCallingIdentity();
4547 try {
4548 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4549 } finally {
4550 Binder.restoreCallingIdentity(identity);
4551 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004552 }
4553
4554 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004555 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4557 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4558 return false;
4559 }
Svet Ganovb320e182015-04-16 12:30:10 -07004560
Malcolm Chend965c8b2018-02-28 15:00:40 -08004561 final long identity = Binder.clearCallingIdentity();
4562 try {
4563 // Check the user preference and the system-level IMS setting. Even if the user has
4564 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4565 // In the long run, we may instead need to check if there exists a connection service
4566 // which can support video calling.
4567 ImsManager imsManager =
4568 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4569 return imsManager.isVtEnabledByPlatform()
4570 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4571 && imsManager.isVtEnabledByUser();
4572 } finally {
4573 Binder.restoreCallingIdentity(identity);
4574 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004575 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004576
Andrew Leea1239f22015-03-02 17:44:07 -08004577 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004578 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4579 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4580 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4581 return false;
4582 }
4583
4584 final long identity = Binder.clearCallingIdentity();
4585 try {
4586 CarrierConfigManager configManager =
4587 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4588 return configManager.getConfigForSubId(mPhone.getSubId())
4589 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4590 } finally {
4591 Binder.restoreCallingIdentity(identity);
4592 }
Andrew Leea1239f22015-03-02 17:44:07 -08004593 }
4594
4595 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004596 public boolean isWorldPhone(int subId, String callingPackage) {
4597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4598 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4599 return false;
4600 }
4601
4602 final long identity = Binder.clearCallingIdentity();
4603 try {
4604 CarrierConfigManager configManager =
4605 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4606 return configManager.getConfigForSubId(mPhone.getSubId())
4607 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4608 } finally {
4609 Binder.restoreCallingIdentity(identity);
4610 }
Andrew Leea1239f22015-03-02 17:44:07 -08004611 }
4612
Andrew Lee9431b832015-03-09 18:46:45 -07004613 @Override
4614 public boolean isTtyModeSupported() {
4615 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004616 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004617 }
4618
4619 @Override
4620 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004621 final long identity = Binder.clearCallingIdentity();
4622 try {
4623 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4624 } finally {
4625 Binder.restoreCallingIdentity(identity);
4626 }
Andrew Lee9431b832015-03-09 18:46:45 -07004627 }
4628
Hall Liuf6668912018-10-31 17:05:23 -07004629 /**
4630 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4631 * support for the feature and device firmware support.
4632 *
4633 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4634 */
4635 @Override
4636 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004637 final long identity = Binder.clearCallingIdentity();
4638 try {
4639 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4640 mPhone.getSubId()).getBoolean(
4641 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4642 boolean isDeviceSupported =
4643 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4644 return isCarrierSupported && isDeviceSupported;
4645 } finally {
4646 Binder.restoreCallingIdentity(identity);
4647 }
Hall Liu98187582018-01-22 19:15:32 -08004648 }
4649
Hall Liuf6668912018-10-31 17:05:23 -07004650 /**
4651 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4652 * both also support RTT.
4653 */
4654 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004655 final long identity = Binder.clearCallingIdentity();
4656 try {
Hall Liuf6668912018-10-31 17:05:23 -07004657 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004658 mPhone.getContext().getContentResolver(),
4659 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4660 } finally {
4661 Binder.restoreCallingIdentity(identity);
4662 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004663 }
4664
Sanket Padawe7310cc72015-01-14 09:53:20 -08004665 /**
4666 * Returns the unique device ID of phone, for example, the IMEI for
4667 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4668 *
4669 * <p>Requires Permission:
4670 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4671 */
4672 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004673 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004674 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004675 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004676 return null;
4677 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004678 int subId = phone.getSubId();
4679 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4680 mApp, subId, callingPackage, "getDeviceId")) {
4681 return null;
4682 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004683
4684 final long identity = Binder.clearCallingIdentity();
4685 try {
4686 return phone.getDeviceId();
4687 } finally {
4688 Binder.restoreCallingIdentity(identity);
4689 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004690 }
4691
Ping Sunc67b7c22016-03-02 19:16:45 +08004692 /**
4693 * {@hide}
4694 * Returns the IMS Registration Status on a particular subid
4695 *
4696 * @param subId
4697 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004698 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004699 Phone phone = getPhone(subId);
4700 if (phone != null) {
4701 return phone.isImsRegistered();
4702 } else {
4703 return false;
4704 }
4705 }
4706
Santos Cordon7a1885b2015-02-03 11:15:19 -08004707 @Override
4708 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004709 final long identity = Binder.clearCallingIdentity();
4710 try {
4711 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4712 } finally {
4713 Binder.restoreCallingIdentity(identity);
4714 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004715 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004716
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004717 /**
4718 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004719 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004720 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004721 final long identity = Binder.clearCallingIdentity();
4722 try {
4723 Phone phone = getPhone(subId);
4724 if (phone != null) {
4725 return phone.isWifiCallingEnabled();
4726 } else {
4727 return false;
4728 }
4729 } finally {
4730 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004731 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004732 }
4733
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004734 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004735 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004736 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004737 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004738 final long identity = Binder.clearCallingIdentity();
4739 try {
4740 Phone phone = getPhone(subId);
4741 if (phone != null) {
4742 return phone.isVideoEnabled();
4743 } else {
4744 return false;
4745 }
4746 } finally {
4747 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004748 }
4749 }
4750
4751 /**
4752 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4753 * defined in {@link ImsRegistrationImplBase}.
4754 */
4755 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004756 final long identity = Binder.clearCallingIdentity();
4757 try {
4758 Phone phone = getPhone(subId);
4759 if (phone != null) {
4760 return phone.getImsRegistrationTech();
4761 } else {
4762 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4763 }
4764 } finally {
4765 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004766 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004767 }
4768
Stuart Scott8eef64f2015-04-08 15:13:54 -07004769 @Override
4770 public void factoryReset(int subId) {
4771 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004772 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4773 return;
4774 }
4775
Svet Ganovcc087f82015-05-12 20:35:54 -07004776 final long identity = Binder.clearCallingIdentity();
4777 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004778 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4779 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004780 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004781 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004782 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4783 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004784 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004785 }
4786 } finally {
4787 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004788 }
4789 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004790
4791 @Override
4792 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004793 final long identity = Binder.clearCallingIdentity();
4794 try {
4795 // We query all subscriptions instead of just the active ones, because
4796 // this might be called early on in the provisioning flow when the
4797 // subscriptions potentially aren't active yet.
4798 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4799 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004800 return null;
4801 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004802
Malcolm Chend965c8b2018-02-28 15:00:40 -08004803 // This function may be called very early, say, from the setup wizard, at
4804 // which point we won't have a default subscription set. If that's the case
4805 // we just choose the first, which will be valid in "most cases".
4806 final int defaultSubId = getDefaultSubscription();
4807 SubscriptionInfo info = null;
4808 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4809 info = slist.get(0);
4810 } else {
4811 for (SubscriptionInfo item : slist) {
4812 if (item.getSubscriptionId() == defaultSubId) {
4813 info = item;
4814 break;
4815 }
4816 }
4817
4818 if (info == null) {
4819 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004820 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004821 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004822
Malcolm Chend965c8b2018-02-28 15:00:40 -08004823 // Try and fetch the locale from the carrier properties or from the SIM language
4824 // preferences (EF-PL and EF-LI)...
4825 final int mcc = info.getMcc();
4826 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4827 String simLanguage = null;
4828 if (defaultPhone != null) {
4829 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4830 if (localeFromDefaultSim != null) {
4831 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4832 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4833 return localeFromDefaultSim.toLanguageTag();
4834 } else {
4835 simLanguage = localeFromDefaultSim.getLanguage();
4836 }
4837 }
4838 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004839
Malcolm Chend965c8b2018-02-28 15:00:40 -08004840 // The SIM language preferences only store a language (e.g. fr = French), not an
4841 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4842 // the SIM and carrier preferences does not include a country we add the country
4843 // determined from the SIM MCC to provide an exact locale.
4844 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4845 simLanguage);
4846 if (mccLocale != null) {
4847 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4848 return mccLocale.toLanguageTag();
4849 }
4850
4851 if (DBG) log("No locale found - returning null");
4852 return null;
4853 } finally {
4854 Binder.restoreCallingIdentity(identity);
4855 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004856 }
4857
4858 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004859 return mSubscriptionController.getAllSubInfoList(
4860 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004861 }
4862
Malcolm Chend965c8b2018-02-28 15:00:40 -08004863 /**
4864 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4865 */
4866 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4867 return mSubscriptionController.getActiveSubscriptionInfoList(
4868 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004869 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004870
Chenjie Yu1ba97252018-01-11 18:16:20 -08004871 private final ModemActivityInfo mLastModemActivityInfo =
4872 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4873
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004874 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004875 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4876 * representing the state of the modem.
4877 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004878 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4879 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004880 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004881 */
4882 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004883 public void requestModemActivityInfo(ResultReceiver result) {
4884 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004885 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004886
4887 final long identity = Binder.clearCallingIdentity();
4888 try {
4889 ModemActivityInfo ret = null;
4890 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004891 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4892 CMD_GET_MODEM_ACTIVITY_INFO,
4893 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004894 if (isModemActivityInfoValid(info)) {
4895 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4896 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4897 mergedTxTimeMs[i] =
4898 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4899 }
4900 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4901 mLastModemActivityInfo.setSleepTimeMillis(
4902 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4903 mLastModemActivityInfo.setIdleTimeMillis(
4904 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4905 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4906 mLastModemActivityInfo.setRxTimeMillis(
4907 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4908 mLastModemActivityInfo.setEnergyUsed(
4909 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004910 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004911 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4912 mLastModemActivityInfo.getSleepTimeMillis(),
4913 mLastModemActivityInfo.getIdleTimeMillis(),
4914 mLastModemActivityInfo.getTxTimeMillis(),
4915 mLastModemActivityInfo.getRxTimeMillis(),
4916 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004917 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004918 Bundle bundle = new Bundle();
4919 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4920 result.send(0, bundle);
4921 } finally {
4922 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004923 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004924 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004925
Siddharth Rayf5d29552018-06-17 15:02:38 -07004926 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4927 // less than total activity duration.
4928 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4929 if (info == null) {
4930 return false;
4931 }
4932 int activityDurationMs =
4933 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4934 int totalTxTimeMs = 0;
4935 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4936 totalTxTimeMs += info.getTxTimeMillis()[i];
4937 }
4938 return (info.isValid()
4939 && (info.getSleepTimeMillis() <= activityDurationMs)
4940 && (info.getIdleTimeMillis() <= activityDurationMs)
4941 && (info.getRxTimeMillis() <= activityDurationMs)
4942 && (totalTxTimeMs <= activityDurationMs));
4943 }
4944
Jack Yu85bd38a2015-11-09 11:34:32 -08004945 /**
4946 * {@hide}
4947 * Returns the service state information on specified subscription.
4948 */
4949 @Override
4950 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004951 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004952 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004953 return null;
4954 }
4955
Malcolm Chend965c8b2018-02-28 15:00:40 -08004956 final long identity = Binder.clearCallingIdentity();
4957 try {
4958 final Phone phone = getPhone(subId);
4959 if (phone == null) {
4960 return null;
4961 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004962
Malcolm Chend965c8b2018-02-28 15:00:40 -08004963 return phone.getServiceState();
4964 } finally {
4965 Binder.restoreCallingIdentity(identity);
4966 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004967 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004968
4969 /**
4970 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4971 *
4972 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4973 * voicemail ringtone.
4974 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4975 * PhoneAccount.
4976 */
4977 @Override
4978 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004979 final long identity = Binder.clearCallingIdentity();
4980 try {
4981 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4982 if (phone == null) {
4983 phone = mPhone;
4984 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004985
Malcolm Chend965c8b2018-02-28 15:00:40 -08004986 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4987 } finally {
4988 Binder.restoreCallingIdentity(identity);
4989 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004990 }
4991
4992 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004993 * Sets the per-account voicemail ringtone.
4994 *
4995 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4996 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4997 *
4998 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4999 * voicemail ringtone.
5000 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5001 * PhoneAccount.
5002 */
5003 @Override
5004 public void setVoicemailRingtoneUri(String callingPackage,
5005 PhoneAccountHandle phoneAccountHandle, Uri uri) {
5006 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5007 if (!TextUtils.equals(callingPackage,
5008 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5010 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5011 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005012 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005013
5014 final long identity = Binder.clearCallingIdentity();
5015 try {
5016 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5017 if (phone == null) {
5018 phone = mPhone;
5019 }
5020 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5021 } finally {
5022 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005023 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005024 }
5025
5026 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005027 * Returns whether vibration is set for voicemail notification in Phone settings.
5028 *
5029 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5030 * voicemail vibration setting.
5031 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5032 */
5033 @Override
5034 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005035 final long identity = Binder.clearCallingIdentity();
5036 try {
5037 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5038 if (phone == null) {
5039 phone = mPhone;
5040 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005041
Malcolm Chend965c8b2018-02-28 15:00:40 -08005042 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5043 } finally {
5044 Binder.restoreCallingIdentity(identity);
5045 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005046 }
5047
Youhan Wange64578a2016-05-02 15:32:42 -07005048 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005049 * Sets the per-account voicemail vibration.
5050 *
5051 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5052 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5053 *
5054 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5055 * voicemail vibration setting.
5056 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5057 * specific PhoneAccount.
5058 */
5059 @Override
5060 public void setVoicemailVibrationEnabled(String callingPackage,
5061 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
5062 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5063 if (!TextUtils.equals(callingPackage,
5064 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5066 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5067 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005068 }
5069
Malcolm Chend965c8b2018-02-28 15:00:40 -08005070 final long identity = Binder.clearCallingIdentity();
5071 try {
5072 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5073 if (phone == null) {
5074 phone = mPhone;
5075 }
5076 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5077 } finally {
5078 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005079 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005080 }
5081
5082 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005083 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5084 *
5085 * @throws SecurityException if the caller does not have the required permission
5086 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005087 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005088 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005089 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005090 }
5091
5092 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005093 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5094 * permission.
5095 *
5096 * @throws SecurityException if the caller does not have the required permission
5097 */
5098 private void enforceSendSmsPermission() {
5099 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5100 }
5101
5102 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005103 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005104 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005105 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005106 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005107 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005108 final long identity = Binder.clearCallingIdentity();
5109 try {
5110 ComponentName componentName =
5111 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
5112 if (componentName == null) {
5113 throw new SecurityException(
5114 "Caller not current active visual voicemail package[null]");
5115 }
5116 String vvmPackage = componentName.getPackageName();
5117 if (!callingPackage.equals(vvmPackage)) {
5118 throw new SecurityException("Caller not current active visual voicemail package["
5119 + vvmPackage + "]");
5120 }
5121 } finally {
5122 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005123 }
5124 }
5125
5126 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005127 * Return the application ID for the app type.
5128 *
5129 * @param subId the subscription ID that this request applies to.
5130 * @param appType the uicc app type.
5131 * @return Application ID for specificied app type, or null if no uicc.
5132 */
5133 @Override
5134 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005135 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005136 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005137
5138 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005139 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005140 if (phone == null) {
5141 return null;
5142 }
5143 String aid = null;
5144 try {
5145 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5146 .getApplicationByType(appType).getAid();
5147 } catch (Exception e) {
5148 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5149 }
5150 return aid;
5151 } finally {
5152 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005153 }
Youhan Wange64578a2016-05-02 15:32:42 -07005154 }
5155
Youhan Wang4001d252016-05-11 10:29:41 -07005156 /**
5157 * Return the Electronic Serial Number.
5158 *
5159 * @param subId the subscription ID that this request applies to.
5160 * @return ESN or null if error.
5161 */
5162 @Override
5163 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005164 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005165 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005166
5167 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005168 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005169 if (phone == null) {
5170 return null;
5171 }
5172 String esn = null;
5173 try {
5174 esn = phone.getEsn();
5175 } catch (Exception e) {
5176 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5177 }
5178 return esn;
5179 } finally {
5180 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005181 }
Youhan Wang4001d252016-05-11 10:29:41 -07005182 }
5183
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005184 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005185 * Return the Preferred Roaming List Version.
5186 *
5187 * @param subId the subscription ID that this request applies to.
5188 * @return PRLVersion or null if error.
5189 */
5190 @Override
5191 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005192 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005193 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005194
5195 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005196 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005197 if (phone == null) {
5198 return null;
5199 }
5200 String cdmaPrlVersion = null;
5201 try {
5202 cdmaPrlVersion = phone.getCdmaPrlVersion();
5203 } catch (Exception e) {
5204 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5205 }
5206 return cdmaPrlVersion;
5207 } finally {
5208 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005209 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005210 }
5211
5212 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005213 * Get snapshot of Telephony histograms
5214 * @return List of Telephony histograms
5215 * @hide
5216 */
5217 @Override
5218 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5220 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005221
5222 final long identity = Binder.clearCallingIdentity();
5223 try {
5224 return RIL.getTelephonyRILTimingHistograms();
5225 } finally {
5226 Binder.restoreCallingIdentity(identity);
5227 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005228 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005229
5230 /**
5231 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005232 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005233 * Require system privileges. In the future we may add this to carrier APIs.
5234 *
5235 * @return The number of carriers set successfully, should match length of carriers
5236 */
5237 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005238 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005239 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005240 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005241
Meng Wang9b7c4e92017-02-17 11:41:27 -08005242 if (carriers == null) {
5243 throw new NullPointerException("carriers cannot be null");
5244 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005245
Malcolm Chend965c8b2018-02-28 15:00:40 -08005246 final long identity = Binder.clearCallingIdentity();
5247 try {
5248 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005249 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5250 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005251 return retVal[0];
5252 } finally {
5253 Binder.restoreCallingIdentity(identity);
5254 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005255 }
5256
5257 /**
5258 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005259 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005260 * Require system privileges. In the future we may add this to carrier APIs.
5261 *
5262 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5263 * means all carriers are allowed.
5264 */
5265 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005266 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005267 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005268 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005269
5270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005273 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5274 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005278 }
5279
fionaxu59545b42016-05-25 15:53:37 -07005280 /**
5281 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5282 * @param subId the subscription ID that this action applies to.
5283 * @param enabled control enable or disable metered apns.
5284 * {@hide}
5285 */
5286 @Override
5287 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5288 enforceModifyPermission();
5289 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005290
5291 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005292 if (phone == null) {
5293 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5294 return;
5295 }
5296 try {
5297 phone.carrierActionSetMeteredApnsEnabled(enabled);
5298 } catch (Exception e) {
5299 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005300 } finally {
5301 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005302 }
5303 }
5304
5305 /**
5306 * Action set from carrier signalling broadcast receivers to enable/disable radio
5307 * @param subId the subscription ID that this action applies to.
5308 * @param enabled control enable or disable radio.
5309 * {@hide}
5310 */
5311 @Override
5312 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5313 enforceModifyPermission();
5314 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005315
5316 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005317 if (phone == null) {
5318 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5319 return;
5320 }
5321 try {
5322 phone.carrierActionSetRadioEnabled(enabled);
5323 } catch (Exception e) {
5324 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005325 } finally {
5326 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005327 }
5328 }
5329
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005330 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005331 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5332 * network status based on which carrier apps could apply actions accordingly,
5333 * enable/disable default url handler for example.
5334 *
5335 * @param subId the subscription ID that this action applies to.
5336 * @param report control start/stop reporting the default network status.
5337 * {@hide}
5338 */
5339 @Override
5340 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5341 enforceModifyPermission();
5342 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005343
5344 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005345 if (phone == null) {
5346 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5347 return;
5348 }
5349 try {
5350 phone.carrierActionReportDefaultNetworkStatus(report);
5351 } catch (Exception e) {
5352 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005353 } finally {
5354 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005355 }
5356 }
5357
5358 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005359 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5360 * bug report is being generated.
5361 */
5362 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005363 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005364 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5365 != PackageManager.PERMISSION_GRANTED) {
5366 writer.println("Permission Denial: can't dump Phone from pid="
5367 + Binder.getCallingPid()
5368 + ", uid=" + Binder.getCallingUid()
5369 + "without permission "
5370 + android.Manifest.permission.DUMP);
5371 return;
5372 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005373 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005374 }
Jack Yueb89b242016-06-22 13:27:47 -07005375
Brad Ebingerdac2f002018-04-03 15:17:52 -07005376 @Override
5377 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5378 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5379 throws RemoteException {
5380 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5381 }
5382
Jack Yueb89b242016-06-22 13:27:47 -07005383 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005384 * Get aggregated video call data usage since boot.
5385 *
5386 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5387 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005388 * {@hide}
5389 */
5390 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005391 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005392 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5393 null);
5394
Malcolm Chend965c8b2018-02-28 15:00:40 -08005395 final long identity = Binder.clearCallingIdentity();
5396 try {
5397 // NetworkStatsService keeps tracking the active network interface and identity. It
5398 // records the delta with the corresponding network identity.
5399 // We just return the total video call data usage snapshot since boot.
5400 Phone phone = getPhone(subId);
5401 if (phone != null) {
5402 return phone.getVtDataUsage(perUidStats);
5403 }
5404 return null;
5405 } finally {
5406 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005407 }
Jack Yueb89b242016-06-22 13:27:47 -07005408 }
Jack Yu75ab2952016-07-08 14:29:33 -07005409
5410 /**
5411 * Policy control of data connection. Usually used when data limit is passed.
5412 * @param enabled True if enabling the data, otherwise disabling.
5413 * @param subId Subscription index
5414 * {@hide}
5415 */
5416 @Override
5417 public void setPolicyDataEnabled(boolean enabled, int subId) {
5418 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005419
5420 final long identity = Binder.clearCallingIdentity();
5421 try {
5422 Phone phone = getPhone(subId);
5423 if (phone != null) {
5424 phone.setPolicyDataEnabled(enabled);
5425 }
5426 } finally {
5427 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005428 }
5429 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005430
5431 /**
5432 * Get Client request stats
5433 * @return List of Client Request Stats
5434 * @hide
5435 */
5436 @Override
5437 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005439 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005440 return null;
5441 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005442 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005443
Malcolm Chend965c8b2018-02-28 15:00:40 -08005444 final long identity = Binder.clearCallingIdentity();
5445 try {
5446 if (phone != null) {
5447 return phone.getClientRequestStats();
5448 }
5449
5450 return null;
5451 } finally {
5452 Binder.restoreCallingIdentity(identity);
5453 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005454 }
5455
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005456 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005457 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005458 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005459 }
Jack Yueb4124c2017-02-16 15:32:43 -08005460
5461 /**
Grace Chen70990072017-03-24 17:21:30 -07005462 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005463 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005464 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005465 * @param state State of SIM (power down, power up, pass through)
5466 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5467 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5468 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005469 *
5470 **/
5471 @Override
Grace Chen70990072017-03-24 17:21:30 -07005472 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005473 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005474 Phone phone = PhoneFactory.getPhone(slotIndex);
5475
vagdevie435a3e2018-08-15 16:01:53 -07005476 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5477
Malcolm Chend965c8b2018-02-28 15:00:40 -08005478 final long identity = Binder.clearCallingIdentity();
5479 try {
5480 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005481 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005482 }
5483 } finally {
5484 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005485 }
5486 }
Shuo Qiandd210312017-04-12 22:11:33 +00005487
Tyler Gunn65d45c22017-06-05 11:22:26 -07005488 private boolean isUssdApiAllowed(int subId) {
5489 CarrierConfigManager configManager =
5490 (CarrierConfigManager) mPhone.getContext().getSystemService(
5491 Context.CARRIER_CONFIG_SERVICE);
5492 if (configManager == null) {
5493 return false;
5494 }
5495 PersistableBundle pb = configManager.getConfigForSubId(subId);
5496 if (pb == null) {
5497 return false;
5498 }
5499 return pb.getBoolean(
5500 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5501 }
5502
Shuo Qiandd210312017-04-12 22:11:33 +00005503 /**
5504 * Check if phone is in emergency callback mode
5505 * @return true if phone is in emergency callback mode
5506 * @param subId sub id
5507 */
goneil9c5f4872017-12-05 14:07:56 -08005508 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005509 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005510 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005511 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005512
5513 final long identity = Binder.clearCallingIdentity();
5514 try {
5515 if (phone != null) {
5516 return phone.isInEcm();
5517 } else {
5518 return false;
5519 }
5520 } finally {
5521 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005522 }
5523 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005524
5525 /**
5526 * Get the current signal strength information for the given subscription.
5527 * Because this information is not updated when the device is in a low power state
5528 * it should not be relied-upon to be current.
5529 * @param subId Subscription index
5530 * @return the most recent cached signal strength info from the modem
5531 */
5532 @Override
5533 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005534 final long identity = Binder.clearCallingIdentity();
5535 try {
5536 Phone p = getPhone(subId);
5537 if (p == null) {
5538 return null;
5539 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005540
Malcolm Chend965c8b2018-02-28 15:00:40 -08005541 return p.getSignalStrength();
5542 } finally {
5543 Binder.restoreCallingIdentity(identity);
5544 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005545 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005546
Pengquan Meng9140aec2018-08-22 14:49:57 -07005547 /**
chen xu907e5a22018-10-11 13:21:04 -07005548 * Get the current modem radio state for the given slot.
5549 * @param slotIndex slot index.
5550 * @param callingPackage the name of the package making the call.
5551 * @return the current radio power state from the modem
5552 */
5553 @Override
5554 public int getRadioPowerState(int slotIndex, String callingPackage) {
5555 Phone phone = PhoneFactory.getPhone(slotIndex);
5556 if (phone != null) {
5557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5558 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5559 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5560 }
5561
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
5564 return phone.getRadioPowerState();
5565 } finally {
5566 Binder.restoreCallingIdentity(identity);
5567 }
5568 }
5569 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5570 }
5571
5572 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005573 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5574 *
5575 * <p>Requires one of the following permissions:
5576 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5577 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5578 * privileges.
5579 *
5580 * @param subId subscription id
5581 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5582 * {@code false}.
5583 */
5584 @Override
5585 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005586 boolean isEnabled = false;
5587 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005588 try {
5589 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005590 null /* message */);
5591 Phone phone = getPhone(subId);
5592 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005593 } catch (Exception e) {
5594 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5595 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005596 } finally {
5597 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005598 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005599 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005600 }
5601
5602
5603 /**
5604 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5605 *
5606 * <p> Requires permission:
5607 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5608 * privileges.
5609 *
5610 * @param subId subscription id
5611 * @param isEnabled {@code true} means enable, {@code false} means disable.
5612 */
5613 @Override
5614 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005615 final long identity = Binder.clearCallingIdentity();
5616 try {
5617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5618 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005619
Pengquan Meng0c05b502018-09-06 09:59:22 -07005620 Phone phone = getPhone(subId);
5621 if (phone != null) {
5622 phone.setDataRoamingEnabled(isEnabled);
5623 }
5624 } finally {
5625 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005626 }
5627 }
5628
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005629 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005630 public boolean isManualNetworkSelectionAllowed(int subId) {
5631 boolean isAllowed = true;
5632 final long identity = Binder.clearCallingIdentity();
5633 try {
5634 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5635 mApp, subId, "isManualNetworkSelectionAllowed");
5636 Phone phone = getPhone(subId);
5637 if (phone != null) {
5638 isAllowed = phone.isCspPlmnEnabled();
5639 }
5640 } finally {
5641 Binder.restoreCallingIdentity(identity);
5642 }
5643 return isAllowed;
5644 }
5645
5646 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005647 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005648 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005649
Malcolm Chend965c8b2018-02-28 15:00:40 -08005650 final long identity = Binder.clearCallingIdentity();
5651 try {
5652 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5653 if (slots == null) {
5654 Rlog.i(LOG_TAG, "slots is null.");
5655 return null;
5656 }
5657
5658 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5659 for (int i = 0; i < slots.length; i++) {
5660 UiccSlot slot = slots[i];
5661 if (slot == null) {
5662 continue;
5663 }
5664
5665 String cardId;
5666 UiccCard card = slot.getUiccCard();
5667 if (card != null) {
5668 cardId = card.getCardId();
5669 } else {
5670 cardId = slot.getIccId();
5671 }
5672
5673 int cardState = 0;
5674 switch (slot.getCardState()) {
5675 case CARDSTATE_ABSENT:
5676 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5677 break;
5678 case CARDSTATE_PRESENT:
5679 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5680 break;
5681 case CARDSTATE_ERROR:
5682 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5683 break;
5684 case CARDSTATE_RESTRICTED:
5685 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5686 break;
5687 default:
5688 break;
5689
5690 }
5691
5692 infos[i] = new UiccSlotInfo(
5693 slot.isActive(),
5694 slot.isEuicc(),
5695 cardId,
5696 cardState,
5697 slot.getPhoneId(),
5698 slot.isExtendedApduSupported());
5699 }
5700 return infos;
5701 } finally {
5702 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005703 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005704 }
5705
5706 @Override
5707 public boolean switchSlots(int[] physicalSlots) {
5708 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005709
5710 final long identity = Binder.clearCallingIdentity();
5711 try {
5712 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5713 } finally {
5714 Binder.restoreCallingIdentity(identity);
5715 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005716 }
Jack Yu4c988042018-02-27 15:30:01 -08005717
5718 @Override
5719 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5720 enforceModifyPermission();
5721 final Phone phone = getPhone(subId);
5722 if (phone == null) {
5723 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5724 return;
5725 }
5726
Malcolm Chend965c8b2018-02-28 15:00:40 -08005727 final long identity = Binder.clearCallingIdentity();
5728 try {
5729 phone.setRadioIndicationUpdateMode(filters, mode);
5730 } finally {
5731 Binder.restoreCallingIdentity(identity);
5732 }
Jack Yu4c988042018-02-27 15:30:01 -08005733 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005734
5735 /**
goneil47ffb6e2018-04-06 15:40:58 -07005736 * A test API to reload the UICC profile.
5737 *
5738 * <p>Requires that the calling app has permission
5739 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5740 * @hide
5741 */
5742 @Override
5743 public void refreshUiccProfile(int subId) {
5744 enforceModifyPermission();
5745
5746 final long identity = Binder.clearCallingIdentity();
5747 try {
5748 Phone phone = getPhone(subId);
5749 if (phone == null) {
5750 return;
5751 }
5752 UiccCard uiccCard = phone.getUiccCard();
5753 if (uiccCard == null) {
5754 return;
5755 }
5756 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5757 if (uiccProfile == null) {
5758 return;
5759 }
5760 uiccProfile.refresh();
5761 } finally {
5762 Binder.restoreCallingIdentity(identity);
5763 }
5764 }
5765
5766 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005767 * Returns false if the mobile data is disabled by default, otherwise return true.
5768 */
5769 private boolean getDefaultDataEnabled() {
5770 return "true".equalsIgnoreCase(
5771 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5772 }
5773
5774 /**
5775 * Returns true if the data roaming is enabled by default, i.e the system property
5776 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5777 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5778 */
5779 private boolean getDefaultDataRoamingEnabled(int subId) {
5780 final CarrierConfigManager configMgr = (CarrierConfigManager)
5781 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5782 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5783 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5784 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5785 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5786 return isDataRoamingEnabled;
5787 }
5788
5789 /**
5790 * Returns the default network type for the given {@code subId}, if the default network type is
5791 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5792 */
5793 private int getDefaultNetworkType(int subId) {
5794 return Integer.parseInt(
5795 TelephonyManager.getTelephonyProperty(
5796 mSubscriptionController.getPhoneId(subId),
5797 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5798 String.valueOf(Phone.PREFERRED_NT_MODE)));
5799 }
fionaxua13278b2018-03-21 00:08:13 -07005800
5801 @Override
5802 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5803 gid1, String gid2, String plmn, String spn) {
5804 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005805
5806 final long identity = Binder.clearCallingIdentity();
5807 try {
5808 final Phone phone = getPhone(subId);
5809 if (phone == null) {
5810 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5811 return;
5812 }
5813 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5814 } finally {
5815 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005816 }
fionaxua13278b2018-03-21 00:08:13 -07005817 }
5818
5819 @Override
5820 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005821 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005822
5823 final long identity = Binder.clearCallingIdentity();
5824 try {
5825 final Phone phone = getPhone(subId);
5826 if (phone == null) {
5827 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5828 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5829 }
5830 return phone.getCarrierIdListVersion();
5831 } finally {
5832 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005833 }
fionaxua13278b2018-03-21 00:08:13 -07005834 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005835
5836 @Override
5837 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5838 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5839 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5840 return -1;
5841 }
5842
5843 final long identity = Binder.clearCallingIdentity();
5844 try {
5845 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5846 } finally {
5847 Binder.restoreCallingIdentity(identity);
5848 }
5849 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005850
5851 @Override
5852 public int getCdmaRoamingMode(int subId) {
5853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5854 mApp, subId, "getCdmaRoamingMode");
5855
5856 final long identity = Binder.clearCallingIdentity();
5857 try {
5858 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5859 } finally {
5860 Binder.restoreCallingIdentity(identity);
5861 }
5862 }
5863
5864 @Override
5865 public boolean setCdmaRoamingMode(int subId, int mode) {
5866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5867 mApp, subId, "setCdmaRoamingMode");
5868
5869 final long identity = Binder.clearCallingIdentity();
5870 try {
5871 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5872 } finally {
5873 Binder.restoreCallingIdentity(identity);
5874 }
5875 }
5876
5877 @Override
5878 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5880 mApp, subId, "setCdmaSubscriptionMode");
5881
5882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5885 } finally {
5886 Binder.restoreCallingIdentity(identity);
5887 }
5888 }
chen xu7ee67862018-10-30 22:27:10 -07005889
sqian2fff4a32018-11-05 14:18:37 -08005890 private void ensureUserRunning(int userId) {
5891 if (!mUserManager.isUserRunning(userId)) {
5892 throw new IllegalStateException("User " + userId + " does not exist or not running");
5893 }
5894 }
5895
5896 /**
5897 * Returns a list of SMS apps on a given user.
5898 *
5899 * Only the shell user (UID 2000 or 0) can call it.
5900 * Target user must be running.
5901 */
5902 @Override
5903 public String[] getSmsApps(int userId) {
5904 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5905 ensureUserRunning(userId);
5906
5907 final Collection<SmsApplicationData> apps =
5908 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5909
5910 String[] ret = new String[apps.size()];
5911 int i = 0;
5912 for (SmsApplicationData app : apps) {
5913 ret[i++] = app.mPackageName;
5914 }
5915 return ret;
5916 }
5917
5918 /**
5919 * Returns the default SMS app package name on a given user.
5920 *
5921 * Only the shell user (UID 2000 or 0) can call it.
5922 * Target user must be running.
5923 */
5924 @Override
5925 public String getDefaultSmsApp(int userId) {
5926 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5927 ensureUserRunning(userId);
5928
5929 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5930 /* updateIfNeeded= */ true, userId);
5931 return cn == null ? null : cn.getPackageName();
5932 }
5933
5934 /**
5935 * Set a package as the default SMS app on a given user.
5936 *
5937 * Only the shell user (UID 2000 or 0) can call it.
5938 * Target user must be running.
5939 */
5940 @Override
5941 public void setDefaultSmsApp(int userId, String packageName) {
5942 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5943 ensureUserRunning(userId);
5944
5945 boolean found = false;
5946 for (String pkg : getSmsApps(userId)) {
5947 if (TextUtils.equals(packageName, pkg)) {
5948 found = true;
5949 break;
5950 }
5951 }
5952 if (!found) {
5953 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5954 }
5955
5956 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5957 }
5958
chen xu7ee67862018-10-30 22:27:10 -07005959 @Override
sqian04b86072018-11-07 14:02:21 -08005960 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5961 String callingPackage) {
5962 // TODO connect with internal content
5963 return null;
5964 }
5965
5966 @Override
5967 public boolean isCurrentEmergencyNumber(String number) {
5968 // TODO connect with internal content
5969 return false;
5970 }
5971
5972 @Override
chen xu7ee67862018-10-30 22:27:10 -07005973 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5974 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5975 Phone phone = getPhone(subId);
5976 if (phone == null) {
5977 return null;
5978 }
5979 final long identity = Binder.clearCallingIdentity();
5980 try {
5981 UiccProfile profile = UiccController.getInstance()
5982 .getUiccProfileForPhone(phone.getPhoneId());
5983 if (profile != null) {
5984 return profile.getCertsFromCarrierPrivilegeAccessRules();
5985 }
5986 } finally {
5987 Binder.restoreCallingIdentity(identity);
5988 }
5989 return null;
5990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005991}